[BUG] OnVehicleSirenStateChange caught in infinite loop -
MP2 - 18.04.2015
On my server I made vehicles' lights automatically come on when the siren is enabled through OnVehicleSirenStateChange, however it seems this causes an infinite loop of the siren being toggled on/off.
Here's a video showing what happens (have audio on):
[ame]http://www.youtube.com/watch?v=e248PV9Dts4[/ame]
I tested this is a BLANK script, which is this:
pawn Код:
#include <a_samp>
main() {}
public OnGameModeInit()
{
AddPlayerClass(0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0);
CreateVehicle(596, 3, 3, 3, 0, -1, -1, -1);
return 1;
}
public OnVehicleSirenStateChange(playerid, vehicleid, newstate)
{
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, newstate, alarm, doors, bonnet, boot, objective);
return 1;
}
You spawn, get in the cop car, toggle the siren on, and it's stuck. All it's doing is turning the lights on or off, depending on 'newstate'.
It can be fixed by setting a timer (even if just 1 MS). I guess SetVehicleParamsEx is conflicting internally. Perhaps 'sirenstate' could actually be added to SetVehicleParamsEx to allow scripted control over sirens?
Re: [BUG] OnVehicleSirenStateChange caught in infinite loop -
Mmartin - 18.04.2015
This happens because the "alarm" parameter in SetVehicleParamsEx is bound to the siren (if you toggle an alarm on a cop car, it toggles its siren). What you can do is store the state of car's siren and then compare the old state to the new one and only call the function when there's a change between the values, because right now it goes:
Siren on -> OnVehicleSirenStateChange -> Toggles siren on -> Siren on -> OnVehicleSirenStateChange -> ...
Re: [BUG] OnVehicleSirenStateChange caught in infinite loop -
Kalcor - 18.04.2015
This is a bug. Thanks for reporting.
The siren state was not updated internally before OnVehicleSirenStateChange was called. Which means you'd have problems using SetVehicleParamsEx inside OnVehicleSirenStateChange.
It'll be fixed in the next server version.
Re: [BUG] OnVehicleSirenStateChange caught in infinite loop -
MP2 - 18.04.2015
Quote:
Originally Posted by Kalcor
This is a bug. Thanks for reporting.
The siren state was not updated internally before OnVehicleSirenStateChange was called. Which means you'd have problems using SetVehicleParamsEx inside OnVehicleSirenStateChange.
It'll be fixed in the next server version.
|
No problem, thanks.