Posts: 240
Threads: 5
Joined: Nov 2017
PHP код:
new hasplayerrainbow[MAX_PLAYERS] = false;
CMD:rainbow(playerid, params[])
{
if(hasplayerrainbow[playerid]) return SendClientMessage(playerid, -1, "You already have rainbow");
if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
{
SendClientMessage(playerid, -1, "[ERROR]: You need to be a driver in a vehicle to use that command.");
}
else
{
new vehicleid = GetPlayerVehicleID(playerid);
ChangeVehicleColor(vehicleid,-1,-1);
SetTimerEx("RainBow", 2000, true, "i", playerid);
}
return 1;
}
forward RainBow(playerid);
public RainBow(playerid)
{
if(!hasplayerrainbow[playerid])
{
KillTimer(RainBow(playerid));
}
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
hasplayerrainbow[playerid] = true;
new vehicleid = GetPlayerVehicleID(playerid);
ChangeVehicleColor(vehicleid,-1,-1);
SetTimerEx("RainBow", 2000, true, "i", playerid);
}
return 1;
}
CMD:killrainbow(playerid, params[])
{
if (hasplayerrainbow[playerid])
{
hasplayerrainbow[playerid] = false;
KillTimer(RainBow(playerid));
SendClientMessage(playerid, -1, "rainbow deactivated");
}
else
{
SendClientMessage(playerid, -1, "you don't have rainbow activated");
}
}
Posts: 240
Threads: 5
Joined: Nov 2017
Quote:
Originally Posted by rakinz
Yea, I've tried making it like that too. It still just changes the car color once and that's all.
It's like the timer doesn't effect or exist.
|
i'll look into it
Posts: 728
Threads: 109
Joined: May 2015
Reputation:
0
Why do you set the same timer twice if one is already is repeating?remove the one in the function
Posts: 240
Threads: 5
Joined: Nov 2017
Quote:
Originally Posted by RogueDrifter
I'd say try this:
PHP код:
new Rainbow_Timer[MAX_PLAYERS];
CMD:rainbow(playerid, params[])
{
if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You need to be a driver in a vehicle to use that command.");
ChangeVehicleColor(GetPlayerVehicleID(playerid),-1,-1);
Rainbow_Timer[playerid] = SetTimerEx("RainBow", 2000, true, "i", playerid);
return 1;
}
forward RainBow(playerid);
public RainBow(playerid)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) ChangeVehicleColor(GetPlayerVehicleID(playerid),-1,-1);
return 1;
}
And use:
Код:
KillTimer(Rainbow_Timer[playerid]);
At OnPlayerDisconnect strictly:
PHP код:
public OnPlayerDisconnect(playerid, reason)
{
KillTimer(Rainbow_Timer[playerid]);
return 1;
}
and
OnPlayerStateChange with a state check
PHP код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == 1 && oldstate == 2) KillTimer(Rainbow_Timer[playerid]);
return 1;
}
|
KillTimer(Rainbow_Timer[playerid]);
should be
KillTimer(Rainbow_Timer(playerid)); since the compiler complains when i use [playerid] for timers