How to make an onCreate for Triggers

Game Version: FS15 and later
GE Version: 6.x and later


Modding Index | Misc. Modding Tutorials


This tutorial will teach you how to make an oncreate trigger

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

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

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

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.


Original Author: Xentro | Date: May 12, 2013

Modding Index | Misc. Modding Tutorials