Community Forum

Using The Same Script For Multiple Triggers in GE

Forum Overview >> Farming Simulator 2011

CategoryFarming Simulator 2011
Created13.08.2011 19:41


Harry Paul Jones (Unknown) 13.08.2011 19:42
Ive made a script to be called by a script call back attribute in GE , the script is for a manual gate but the only problem ive come across is that when i have two gates using the same script the trigger from one is activating the animation for the original gate , is there a way to make the gate use the script and not own the script if you get me , so im able to use the same script for every gate in the map?

Thanks for any help ,

Stefan Geiger - GIANTS Software 25.08.2011 11:09
Normally this is working correctly (e.g. look at the TipTrigger or SiloTrigger classes of the game).

I suppose you use some global variables instead of class member variables only. Can you post the code of your gate?

Harry Paul Jones (Unknown) 28.08.2011 00:40
I did some more research finding more about the global variables , know this i see how its effecting my script , im still stuck for solution so for a chance of some help ill post my code , thanks.

--(c) Copyright DJ Modding
--Author: H-P-J3000
--Terms: Free For Use With Credit
--Date: 08.27.11

ManualGates = {};
ManualGates.Opening = {};

function ManualGates:onCreate(id)
ManualGates:load(id);
end;

print(" Trelawney: Manual Gate Script Loaded!")

local ManualGates_mt = Class(ManualGates);

ManualGatesOnCreate = ManualGates.onCreate;

function ManualGates:loadMap(name)
end;

function ManualGates:draw()
end;

function ManualGates:mouseEvent(posX, posY, isDown, isUp, button)
end;

function ManualGates:keyEvent(unicode, sym, modifier, isDown)
end;


function ManualGates:load(id)
self.triggerId = id;
addTrigger(id, "triggerCallback", self);
self.deleteListenerId = addDeleteListener(id, "delete", self);
local parent = getParent(id);
local GateIndex = getUserAttribute(id, "GateIndex");
self.GateIndex = Utils.indexToObject(parent, GateIndex);
self.Rotmax = Utils.getNoNil(getUserAttribute(id, "RotMax"), 0)
self.playerInTrigger = false;
self.endTime = 500;
self.startTime = 0;
self.rotation = nil;
end;

function ManualGates:deleteMap()
removeTrigger(self.triggerId);
removeDeleteListener(self.triggerId, self.deleteListenerId);
end;

function ManualGates:update(dt)
if self.playerInTrigger then
if InputBinding.hasEvent(InputBinding.ACTION) then
self.rotation = not self.rotation;
end;
end;

if self.rotation then
self.startTime = self.startTime + dt;
self.startTime = math.min(self.startTime, self.endTime);
else
self.startTime = self.startTime - dt;
self.startTime = math.max(self.startTime, 0);
end;

setRotation(self.GateIndex, 0,(self.Rotmax*(3.14159265/180))*(self.startTime/self.endTime), 0);
end;

function ManualGates:draw()
if self.playerInTrigger then
g_currentMission:addExtraPrintText("Open/Close: "..InputBinding.getKeyNamesOfDigitalAction(InputBinding.ACTION));
end;
end;


function ManualGates:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
if onEnter then
if g_currentMission.player ~= nil then
if otherId == g_currentMission.player.rootNode then
self.playerInTrigger = true;
end;
end;
elseif onLeave then
if g_currentMission.player ~= nil then
if otherId == g_currentMission.player.rootNode then
self.playerInTrigger = false;
end;
end;
end;

end;


addModEventListener(ManualGates);

Harry Scolding (Unknown) 16.08.2014 09:24
where would I put this code


Note: Log in to post. Create a new account here.