05.06.2016, 00:19
I've usually stayed away from timers but in this case I really need to use one. I assign Player[playerid][MechanicTimer] to the following timer. But if the player goes away from the vehicle, the vehicle hood shuts, the player they're repairing logs off, etc, etc it's suppose to kill the timer. But it doesn't. The timer just keeps infinitely repeating.
What am I doing wrong?
Edit: Here's where I used the timer:
PHP код:
forward RepairTimer(playerid, id, vehicleid);
public RepairTimer(playerid, id, vehicleid)
{
if(!IsPlayerConnectedEx(id))
{
KillTimer(Player[playerid][MechanicTimer]);
return SendClientMessage(playerid, WHITE, "That player has disconnected");
}
if(IsPlayerInAnyVehicle(playerid))
{
KillTimer(Player[playerid][MechanicTimer]);
return SendClientMessage(playerid, WHITE, "You can't repair a vehicle from inside.");
}
switch(GetPVarInt(playerid, "RepairInt"))
{
case 0 .. 28:
{
if(vehicleid != INVALID_VEHICLE_ID)
{
new Float:Pos[3], engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
GetVehiclePos(vehicleid, Pos[0], Pos[1], Pos[2]);
if(bonnet == VEHICLE_PARAMS_ON)
{
if(IsPlayerInRangeOfPoint(playerid, 15.0, Pos[0], Pos[1], Pos[2]))
{
Array[0] = 0;
format(Array, sizeof(Array), "Repairing Vehicle...\n%d seconds left.", 30 - GetPVarInt(playerid, "RepairInt"));
SetPVarInt(playerid, "RepairInt", GetPVarInt(playerid, "RepairInt") + 1);
GameTextForPlayer(playerid, Array, 1000, 4);
}
else
{
KillTimer(Player[playerid][MechanicTimer]);
return SendClientMessage(playerid, WHITE, "You are no longer near that vehicle.");
}
}
else
{
KillTimer(Player[playerid][MechanicTimer]);
return SendClientMessage(playerid, WHITE, "The vehicle's hood must be opened.");
}
}
else
{
KillTimer(Player[playerid][MechanicTimer]);
return SendClientMessage(playerid, WHITE, "You are no longer near that vehicle.");
}
}
default:
{
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
if(bonnet == VEHICLE_PARAMS_ON)
{
Array[0] = 0;
RepairVehicle(vehicleid);
SendClientMessage(playerid, WHITE, "You have repaired the vehicle.");
KillTimer(Player[playerid][MechanicTimer]);
SetPVarInt(playerid, "MechanicTime", gettime() + 60);
format(Array, sizeof(Array), "* %s has repaired the vehicle.", GetName(playerid));
SendNearbyMessage(playerid, Array, SCRIPTPURPLE, 30.0);
}
else
{
KillTimer(Player[playerid][MechanicTimer]);
return SendClientMessage(playerid, WHITE, "The vehicle's hood must be opened.");
}
}
}
return 1;
}
Edit: Here's where I used the timer:
PHP код:
Player[playerid][MechanicTimer] = SetTimerEx("RepairTimer", 1000, TRUE, "iii", playerid, id, vehicleid);