Home   Help Search Login Register  

Author Topic: Multiplayer mission with "getin" & "getout" eventhandlers  (Read 1689 times)

0 Members and 1 Guest are viewing this topic.

Offline Andy

  • Members
  • *
I'm creating a multiplayer mission revolving around emergency vehicle responses controlled by 1 player (me).  I want to be able to drive a car and have 1 or 2 cars driving directly behind me where ever I go.  The AI drivers will not follow me the way that I want them to, so I set up 2 scripts.  One script checks if a car that I will drive is moving, if it is, then the other script takes my cars position and direction and loops it to the cars following me.  This actually works, but with numerous vehicle groups like this and too many scripts looping at the same time without exiting, the server lags too much. 

I would like to set up eventhandlers that check if I am the driver of "car1" and if so, have "car2" and "car3" follow.  If I get out of "car1" then the script will end. 

If that can't be done, how do I get my original scripts to stop looping when I get out?

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Multiplayer mission with "getin" & "getout" eventhandlers
« Reply #1 on: 05 Apr 2007, 20:55:41 »
Andy,
A quick check of the Bi Wiki reveals that the getin/out event handlers should fire on all machines. This makes what I posted first (and subsequently deleted) somewhat incorrect.
Assuming that your script is called "trackingscript.sqs" here is what I recommend you do. One instance of the script should be run for both car2 and car3.

1) Add the following to the car1 init:
Code: [Select]
this addEventHandler ["GETIN",{car2 exec "trackingscript.sqs" ; car3 exec "trackingscript.sqs" }] ; this addEventHandler ["GETOUT",{andy_getout = TRUE}]
2) Add the following to the very top of "trackingscript.sqs":
Code: [Select]
_car = _this
if (not local _car) then {exit}
andy_getout = FALSE

3) Recode "trackingscript.sqs" to use the variable _car as the tracking vehicle

4) Add somewhere in the looping part of "trackingscript.sqs":
Code: [Select]
if andy_getout then {exit}

This solution should work no matter which player drives car1, or whether car2 and car3 have car1 as a leader. Of course, if car2 and car3 have another leader it could still screw things up.¦nbsp; One last thing you should add to the script is a line in the looping part that exits if either _car can not move, or its driver is dead:

5)
Code: [Select]
if (not canMove _car or not alive driver _car) then {exit}You might have to add more brackets.... i.e. if ((not canMove _car) or (not alive driver _car)) then {exit}

Make sure you also add a small pause somewhere in the looping part of your script. If you do not the script will most certainly cause lag. Surely the following drivers need only receive an updated position every second or so? i.e. ~0.5

« Last Edit: 05 Apr 2007, 21:23:26 by Mr.Peanut »
urp!