Farming Simulator UK Forums

The biggest unofficial UK forums for Farming Simulator.

Search Rules Chat Wiki Gallery Privacy Policy

Ahoy there, guest!

Log in Register


 
  Search  

How to make an onCreate for Triggers
Submitted By: Xentro Date: May 12, 2013, 06:34:46 am Views: 3250
Summary: How to make an onCreate for Triggers.

How to make an onCreate for Triggers.


Skill level needed too even attempt this is a little more then basic.

What will this tut teach me you ask? how to make an tip trigger? an silo? (if you gotten this far and still wonders then you do not have the needed skill level)
no this tut will teach you how to do the most important thing about triggers and that is to call it.

Lets start with the basic script layout that you must have

Code:

triggerBase = {};

local triggerBase_mt = Class(triggerBase, Object);
InitObjectClass(triggerBase, "triggerBase");

function triggerBase.onCreate(id)
    local instance = triggerBase:new(g_server ~= nil, g_client ~= nil);
if instance:load(id) then
g_currentMission:addOnCreateLoadedObject(instance);
instance:register(true);
else
instance:delete();
end;
end;
g_onCreateUtil.addOnCreateFunction("customCallScript", triggerBase.onCreate);

function triggerBase:new(isServer, isClient)
    local self = Object:new(isServer, isClient, triggerBase_mt);
    self.className = "triggerBase";

    return self;
end;

function triggerBase:load(id)
return true;
end;

function triggerBase:delete()
end;

function triggerBase:readStream(streamId, connection)
end;

function triggerBase:writeStream(streamId, connection)
end;

function triggerBase:update(dt)
end;

function triggerBase:updateTick(dt)
end;


I will now start explaining the function that are important to this tut.

Code:
function triggerBase.onCreate(id)
    local instance = triggerBase:new(g_server ~= nil, g_client ~= nil);
if instance:load(id) then
g_currentMission:addOnCreateLoadedObject(instance);
instance:register(true);
else
instance:delete();
end;
end;
g_onCreateUtil.addOnCreateFunction("customCallScript", triggerBase.onCreate);


This part is the most important part in the whole script, why you ask? how far would you get without any gas in your car? that is how important it is.
The part that makes the callback you need for your map is this line
Code:
g_onCreateUtil.addOnCreateFunction("customCallScript", triggerBase.onCreate);

this is the full scriptCallBack that you need to write in the trigger
modOnCreate.customCallScript

"customCallScript" can/must be changed when you make your script as it could conflict if there are other callbacks with the same name, same for triggerBase class.

Thats it for the basic scriptCallback.

Edit: had to dummy it down.

Rating: ***** by 10 members.
Comments
Xentro
MVP
500+
*
Posts: 717



View Profile WWW
August 25, 2013, 06:38:51 am
Yes that is correct nsterken.

nsterken
Veteran
*
Posts: 386


New mobo, CPU and SSD - ready to roll


View Profile
August 23, 2013, 11:10:45 am
Thank u for the tut although I was hoping you would go more in depth with your explanations of the calls and exactly what the script is executing and doing but I suppose we can use the other available documentation to decipher that.

My question then is this:

In the part of the script for the OnCreate, where it says:

"CustomCallScript" is this where we need to write in the name for our own script to be called?  Am I reading this correctly?

Thanks again, wish we had more tutorials on .lua as it is such a versatile and powerful syntax. Wink
Feterlj
Veteran
*
Posts: 426


We have Camels fruit type. www.facebook.com/FET3D


View Profile WWW
June 30, 2013, 06:57:59 am
Once again this made no sense at all.

I do not understand what  save/load function even is.

The terminology here is a bit too technical for a novice to use.

If your going to put up a tutorial perhaps you should at least explain in simple English what your talking about.

I am an electronics technican and I do not walk up to my mom, who is someone with no electronics background and tell her "I just measured a latch signal with my oscilloscope".  

Instead I might say something like, "I just measured the signal that controls this part of the circuit"

Since most people novice to electronics repair have no clue what a latch is in electronics or an oscilloscope for that matter.

Just throwing you an example.
georgebob098
Newbie
*
Posts: 28


View Profile
June 04, 2013, 04:45:33 pm
i have a trigger script for an automatic door but i  have no idea what to do with the script and no idea on how to make the trigger.
someone please help !!!!!
AlbertL
1000+
*
Posts: 1,292


Leave us long haired country boy's alone


View Profile
May 27, 2013, 06:16:39 pm
this made absolutly no sence at all.
exactaly what is this suposed to be a sell trigger for new stuff?
a grain station trigger for silos or sell point what???


Powered By SMF Articles by CreateAForum.com
Back Top of page


Powered by SMF 1.1.21 | SMF © 2013, Simple Machines