Run script as soon as a player gets in vehicle

Kenturrac

New Member
Hey guys,
I'm looking for something really simple, but I wonder how to do it since the "get in as driver" is deep down in the Arma 2 code. So, what I wanna do is to run a script on client side as soon as the controlling player jumps into a car as the driver. Does anyone know how and where to do that?

Thx in advance!
 
If you mean created by me as coded and put into the game by me, then no.
If you mean created by the player and controlled by the player, then also no.

The car is created by the server. I know that the vehicle gets handed over to the driver client and in that moment I wanna do a specific check. You are right, I could do a loop on the player, but that sounds really hacky and I was wondering, if I could avoid that.
 
I think you're going on that a bit wrong. You could simply do a endless loop and add something like this inside:

PHP:
if (vehicle player != 0) then {

};

Sleep it every 5 secs i.e. make it check every 5 sec and that's your script done. If that does not work try it with if (!isNul(vehicle player)) or just check arma2 scripting wiki.
 
Sure, but adding an endless loop sounds way to hacky for me. If someone would do that at work, I would question if that is the right job for him. But if that is how you roll with arma script, then I have to do it. Thx man!
 
Last edited:
Is it a vehicle created by you, or all vehicles on the server?

if it is created by you (your own script) then you can use a getin eventhandler on the vehicle
https://community.bistudio.com/wiki/addEventHandler
https://community.bistudio.com/wiki/ArmA_2:_Event_Handlers#GetIn

otherwise you have to run a loop for every player and check if the player gets in a vehicle

He can Add an EH to a vehicle that is spawned via server also :confused:

Somewhere below

Code:
if (_object isKindOf "AllVehicles") then {

in server_monitor.sqf

Add:

Code:
    _object addMPEventHandler ["GetIn",{
    _vehicle = _this select 0; //vehicle wchich triggered the EH
    _pos = _this select 1; //Position in vehicle (driver, gunner etc) not Position on map!
    _unit _this select 2; //player that entered the vehicle
   
    //your awesome script goes here
   
    }];
 
cyrq,

Can i use addEventHandler instead of addMPEventHandler?

addMPEventHandler is not working in a code i'm doing, the multi player event handler is created on cliente side, but it does not work (it is never triggered).

If i use addEventHandler it works.
 
Last edited:
Back
Top