//this is what I use to set the lights on and off (flashing)
forward SetVehicleFlashingLights(playerid, vehicleid);
public SetVehicleFlashingLights(playerid, vehicleid)
{
new
engine,
lights,
alarm,
doors,
bonnet,
boot,
objective;
if(IsPlayerInAnyVehicle(playerid))
{
if(engine != VEHICLE_PARAMS_ON)
{
SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_ON, lights, alarm, doors, bonnet, boot, objective);
}
else
{
SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_OFF, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_ON, alarm, doors, bonnet, boot, objective);
}
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_OFF, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_ON, alarm, doors, bonnet, boot, objective);
}
}
//this turns off the flashing lights, by running itself once, you'll see in the command, what I did.
forward TurnOffFlashingLights(playerid, vehicleid);
public TurnOffFlashingLights(playerid, vehicleid)
{
new
engine,
lights,
alarm,
doors,
bonnet,
boot,
objective;
while(IsPlayerInAnyVehicle(playerid))
{
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_OFF, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_ON, alarm, doors, bonnet, boot, objective);
}
}
new kmiTimer; //for timer, outside (global var)
//this is supposed to start the timer
dcmd_OnLights(playerid, params[])
{
#pragma unused params
new
vehID;
vehID = GetPlayerVehicleID(playerid);
if(IsPlayerInAnyVehicle(playerid))
{
kmiTimer = SetTimerEx("SetVehicleFlashingLights", 30000, true, "d", vehID);
SendClientMessage(playerid, 0xFFFFFFFF, "[ ! ] Vehicle Lights turned on. If nothing happens, there is something wrong with your code.");
}
else
{
SendClientMessage(playerid, 0xFF0000FF, "[ ! ] You aren't in a vehicle!");
}
return true;
}
//this is supposed to turn them off.
dcmd_OffLights(playerid, params[])
{
#pragma unused params
new
vehID;
vehID = GetPlayerVehicleID(playerid);
if(IsPlayerInAnyVehicle(playerid))
{
KillTimer(kmiTimer);
SendClientMessage(playerid, 0xFF0000FF, "[ ! ] Lights killed successfully.");
SetTimerEx("TurnOffFlashingLights", 1, true, "d", vehID);
}
else
{
SendClientMessage(playerid, 0xFF0000FF, "[ ! ] You aren't in a vehicle!");
}
return true;
}
while(IsPlayerInAnyVehicle(playerid))
{
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_OFF, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, VEHICLE_PARAMS_ON, alarm, doors, bonnet, boot, objective);
}
You know that this code will run forever until the player gets out?
pawn Код:
|
I honestly do not feel like writing new code, or even looking at it, so I'll give you what is a better approach than "hanging" your server:
- Make a variable to store the vehicle's lights status - Run a 1 second timer checking the variable. If the lights are one, set them off, and vice-verse. A one second timer would be fine for this situation. The problem with your code is it was re-setting the lights on/off multiple times a second, so you probably couldn't notice the differences. I'm also sure there are other ways for doing this, more efficiently, but like I said, not in the mood. |