Jump to content
Sign in to follow this  
scifer

Accessing unit's variable inside vehicles

Recommended Posts

I'm implementing an excitability system to my script MoodJukebox and this is an excerpt:

player setVariable ["stress", 0];
player addEventHandler
["firedNear",
{
  player setVariable ["stress", (player getVariable "stress") + 1];
  hintSilent format ["%1", player getVariable "stress"];
}
];

So each time the player shoots an increasing number is displayed.

The problem is that it only works while on foot and as soon as I board any vehicle it doesn't work anymore :(

What do I do?

Share this post


Link to post
Share on other sites

maybe because firedNear eventhandler does not register that player is in vehicle, maybe check if player is in vehicle and add eventhandler to vehicle then remove it once player exits vehicle..

if you get where im going...

Edit:

player setVariable ["stress", 0];
player addEventHandler
["firedNear",
{
player setVariable ["stress", (player getVariable "stress") + 1];
hintSilent format ["%1", player getVariable "stress"];
}];

while {true} do {
waitUntil {(vehicle player) != player};

_veh = (vehicle player);
_idx = _veh addEventHandler
["firedNear",
{
	player setVariable ["stress", (player getVariable "stress") + 1];
	hintSilent format ["%1", player getVariable "stress"];
}];

waitUntil {(vehicle player) != _veh};
_veh removeEventHandler ["firedNear", _idx];
};

edit2: ah you got it working.

Edited by Demonized

Share this post


Link to post
Share on other sites
maybe because firedNear eventhandler does not register that player is in vehicle, maybe check if player is in vehicle and add eventhandler to vehicle then remove it once player exits vehicle..

Thanx a lot. It worked :)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×