Community Forum

Making a Key Event MP capable

Forum Overview >> Farming Simulator 2011

CategoryFarming Simulator 2011
Created22.01.2011 21:26


Harry Paul Jones (Unknown) 22.01.2011 21:30
Hello , im in the process of making converting a script and was wondering how would i make a key event sent the function.for instance i have

function WarningLight:keyEvent(unicode, sym, modifier, isDown)

if isDown and sym == Input.KEY_u then
self.WarningLight = not self.WarningLight;
setVisibility(self.Light, self.WarningLight);
end;
end;

and would like to send that function , can it be done or do i have to make its an inputbinding.


also how would i make the set visibility like above automatic with a delay?
so a flash on then delay then flash off and delay.

thnkyou for any help .

Stefan Geiger - GIANTS Software 24.01.2011 11:10
What do you mean be sending that function? Adding multiplayer capability? This is independent of the usage of the input binding (although I would recommend to use the input binding, to allow the player to adjust the binding in the gui).
You need to add a WarningLightEvent class, which you would send when the warning light should be turned on/off.

Maybe you want to have look at the SetTurnedOnEvent which you can use as a reference.
http://ls-mods.de/scriptDocumentation.php?lua_file=vehicles/specializations/SetTurnedOnEvent
Since you are writing I mod, you need to exchange the InitStaticEventClass(...) call with this call:
InitEventClass(WarningLightEvent, "WarningLightEvent");



I would implement an automatic blinking of the light with a timer and a boolean whether the blinking is enabled.

So the code would look like this:
if self.doBlink then
self.blinkTimer = self.blinkTimer - dt;
if self.blinkTimer <= 0 then
self.blinkTimer = self.blinkTimer + 500; -- toggle light visibility every 500ms
setVisiblity(self.blinkLight, not getVisiblity(self.blinkLight));
end;
end;


To toggle the blinking the code would look like this:
if self:getIsActiveForInput() and InputBinding.hasEvent(InputBinding.TOGGLE_BLINKING) then
self.doBlink = not self.doBlink;
setVisiblity(self.blinkLight, false);
self.blinkTimer = 500;
g_client:sendEvent(ToggleBlinkEvent:new(self.doBlink));
end;

The ToggleBlinkEvent writes/reads a single bool to the network stream and the run function does the same code as inside the if, except for the sendEvent which is replaced by:
if not connection:getIsServer() then
g_server:broadcastEvent(self, false, connection, self.doBlink);
end;

Harry Paul Jones (Unknown) 24.01.2011 22:53



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