PDA

View Full Version : changecolor timer


rakinz
23/02/2018, 08:16 AM
CMD:rainbow(playerid, params[])
{
if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
{
SendClientMessage(playerid, COLOR_RED, "[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(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new vehicleid;
GetPlayerVehicleID(playerid);
ChangeVehicleColor(vehicleid,-1,-1);
SetTimerEx("RainBow", 2000, true, "i", playerid);
}
return 1;
}


I've tried making a command that changes the car color every 2 seconds.

The command doesn't effect at all, not even changing the color once, can someone help me with that?

RogueDrifter
23/02/2018, 08:18 AM
This new vehicleid;
GetPlayerVehicleID(playerid);
That's not how you specify a value to a variable,
more like this:


new vehicleid = GetPlayerVehicleID(playerid);

rfr
23/02/2018, 08:22 AM
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");
}
}

rakinz
23/02/2018, 08:28 AM
CMD:rainbow(playerid, params[])
{
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(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new vehicleid = GetPlayerVehicleID(playerid);
ChangeVehicleColor(vehicleid,-1,-1);
SetTimerEx("RainBow", 2000, true, "i", playerid);
}
return 1;
}

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.

rfr
23/02/2018, 08:30 AM
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

PepsiCola23
23/02/2018, 08:33 AM
Why do you set the same timer twice if one is already is repeating?remove the one in the function

rakinz
23/02/2018, 08:39 AM
Why do you set the same timer twice if one is already is repeating?remove the one in the function

Tried that as well, also I've tried making them both to false. still doesn't work.

RogueDrifter
23/02/2018, 08:44 AM
I'd say try this:

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:

public OnPlayerDisconnect(playerid, reason)
{
KillTimer(Rainbow_Timer[playerid]);
return 1;
}

and

OnPlayerStateChange with a state check

public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == 1 && oldstate == 2) KillTimer(Rainbow_Timer[playerid]);
return 1;
}

rfr
23/02/2018, 08:48 AM
I'd say try this:

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:

public OnPlayerDisconnect(playerid, reason)
{
KillTimer(Rainbow_Timer[playerid]);
return 1;
}

and

OnPlayerStateChange with a state check

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

RogueDrifter
23/02/2018, 08:49 AM
KillTimer(Rainbow_Timer[playerid]);
should be
KillTimer(Rainbow_Timer(playerid)); since the compiler complains when i use [playerid] for timers
Nope. Try compiling that.

EDIT: how so? hang on lemme try that, never encountered a problem with it before.

Nope you're wrong, it's the other way around.

rfr
23/02/2018, 08:50 AM
Nope. Try compiling that.

I did.

and no matter what, the colour of the turismo turns blue when i try to change the colour. not sure what's wrong. i've tried your command too.

https://cdn.discordapp.com/attachments/414391798245359618/416532123105886218/unknown.png

RogueDrifter
23/02/2018, 08:52 AM
I did.

and no matter what, the colour of the turismo turns blue when i try to change the colour. not sure what's wrong. i've tried your command too.
Maybe reusing color -1 doesn't change it lol wait lemme try something else. Gonna edit this reply.

EDIT: try this lmao BUT use print at the Rainbow callback and lemme know if it's even called.

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)
{
new firstcolor;
new secondcolor;
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
if(firstcolor < 500 && secondcolor < 500) firstcolor++, secondcolor ++,
ChangeVehicleColor(GetPlayerVehicleID(playerid),fi rstcolor, secondcolor);
else firstcolor = 0, secondcolor = 0;
}

return 1;
}

rfr
23/02/2018, 08:55 AM
Maybe reusing color -1 doesn't change it lol wait lemme try something else. Gonna edit this reply.


i even tried random(20), still blue


edit: your code changes the colour to blue then white

https://cdn.discordapp.com/attachments/414391798245359618/416533774071758849/unknown.png

rakinz
23/02/2018, 08:58 AM
I'd say try this:

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:

public OnPlayerDisconnect(playerid, reason)
{
KillTimer(Rainbow_Timer[playerid]);
return 1;
}

and

OnPlayerStateChange with a state check

public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == 1 && oldstate == 2) KillTimer(Rainbow_Timer[playerid]);
return 1;
}


Listen, I've made it like that (btw, the KillTimer(Rainbow_Timer[playerid]); can't be in OnPlayerDisconnect because the RainBow_Timer isn't defined there. so I've used it somewhere else in the script)

Anyways, it's still not working, and just for you to know everytime I use the command it changes the car color to blue, then white and that's all.

RogueDrifter
23/02/2018, 09:08 AM
Oh!! that was stupid of me sorry, i didn't realize that every time the function is called it redeclares the variables, give me a few minutes to make you a proper one.

RogueDrifter
23/02/2018, 09:16 AM
enum PLAYER_RAINBOW_DATA//Put this on top of the script
{
bool:Rainbow_Action,

Rainbow_Timer,

Rainbow_Color1,
Rainbow_Color2
}

new
Player_Rainbow[MAX_PLAYERS][PLAYER_RAINBOW_DATA];//Put this on top of the script


CMD:rainbow(playerid, params[])
{
if(!Player_Rainbow[playerid][Rainbow_Action])
{
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.");
new vehicleid = GetPlayerVehicleID(playerd);

Player_Rainbow[playerid][Rainbow_Action] = true;

ChangeVehicleColor(vehicleid,-1,-1);
Player_Rainbow[playerid][Rainbow_Timer] = SetTimerEx("RainBow", 2000, true, "i", playerid, vehicleid);
}
else return SendClientMessage(playerid, -1, "[ERROR]: You're already in the rainbow status!");
return 1;
}

CMD:stoprainbow(playerid, params[])
{
if(Player_Rainbow[playerid][Rainbow_Action])
{
Player_Rainbow[playerid][Rainbow_Action] = false,
KillTimer(Player_Rainbow[playerid][Rainbow_Timer]),
Player_Rainbow[playerid][Rainbow_Color1] = 0, Player_Rainbow[playerid][Rainbow_Color2] = 0;
}
else return SendClientMessage(playerid, -1, "[ERROR]: You're not in rainbow status!");
return 1;
}

forward RainBow(playerid, vehicleid);
public RainBow(playerid, vehicleid)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
if(Player_Rainbow[playerid][Rainbow_Color1] < 500 && Player_Rainbow[playerid][Rainbow_Color2] < 500)
{
Player_Rainbow[playerid][Rainbow_Color1]++,
Player_Rainbow[playerid][Rainbow_Color2]++;
ChangeVehicleColor(vehicleid,Player_Rainbow[playerid][Rainbow_Color1], Player_Rainbow[playerid][Rainbow_Color2]);
}
else Player_Rainbow[playerid][Rainbow_Color1] = 0, Player_Rainbow[playerid][Rainbow_Color2] = 0;
}

else KillTimer(Player_Rainbow[playerid][Rainbow_Timer]), Player_Rainbow[playerid][Rainbow_Action] = false,
Player_Rainbow[playerid][Rainbow_Color1] = 0, Player_Rainbow[playerid][Rainbow_Color2] = 0;
return 1;
}

public OnPlayerDisconnect(playerid, reason)//Put the codes here under your OnPlayerDisconnect.
{
Player_Rainbow[playerid][Rainbow_Action] = false,
KillTimer(Player_Rainbow[playerid][Rainbow_Timer]),
Player_Rainbow[playerid][Rainbow_Color1] = 0, Player_Rainbow[playerid][Rainbow_Color2] = 0;
return 1;
}

There you go, let me know if u don't understand any part in it.

rakinz
23/02/2018, 09:46 AM
enum PLAYER_RAINBOW_DATA//Put this on top of the script
{
bool:Rainbow_Action,

Rainbow_Timer,

Rainbow_Color1,
Rainbow_Color2
}

new
Player_Rainbow[MAX_PLAYERS][PLAYER_RAINBOW_DATA];//Put this on top of the script


CMD:rainbow(playerid, params[])
{
if(!Player_Rainbow[playerid][Rainbow_Action])
{
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.");
new vehicleid = GetPlayerVehicleID(playerd);

Player_Rainbow[playerid][Rainbow_Action] = true;

ChangeVehicleColor(vehicleid,-1,-1);
Player_Rainbow[playerid][Rainbow_Timer] = SetTimerEx("RainBow", 2000, true, "i", playerid, vehicleid);
}
else return SendClientMessage(playerid, -1, "[ERROR]: You're already in the rainbow status!");
return 1;
}

CMD:stoprainbow(playerid, params[])
{
if(Player_Rainbow[playerid][Rainbow_Action])
{
Player_Rainbow[playerid][Rainbow_Action] = false,
KillTimer(Player_Rainbow[playerid][Rainbow_Timer]),
Player_Rainbow[playerid][Rainbow_Color1] = 0, Player_Rainbow[playerid][Rainbow_Color2] = 0;
}
else return SendClientMessage(playerid, -1, "[ERROR]: You're not in rainbow status!");
return 1;
}

forward RainBow(playerid, vehicleid);
public RainBow(playerid, vehicleid)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
if(Player_Rainbow[playerid][Rainbow_Color1] < 500 && Player_Rainbow[playerid][Rainbow_Color2] < 500)
{
Player_Rainbow[playerid][Rainbow_Color1]++,
Player_Rainbow[playerid][Rainbow_Color2]++;
ChangeVehicleColor(vehicleid,Player_Rainbow[playerid][Rainbow_Color1], Player_Rainbow[playerid][Rainbow_Color2]);
}
else Player_Rainbow[playerid][Rainbow_Color1] = 0, Player_Rainbow[playerid][Rainbow_Color2] = 0;
}

else KillTimer(Player_Rainbow[playerid][Rainbow_Timer]), Player_Rainbow[playerid][Rainbow_Action] = false,
Player_Rainbow[playerid][Rainbow_Color1] = 0, Player_Rainbow[playerid][Rainbow_Color2] = 0;
return 1;
}

public OnPlayerDisconnect(playerid, reason)//Put the codes here under your OnPlayerDisconnect.
{
Player_Rainbow[playerid][Rainbow_Action] = false,
KillTimer(Player_Rainbow[playerid][Rainbow_Timer]),
Player_Rainbow[playerid][Rainbow_Color1] = 0, Player_Rainbow[playerid][Rainbow_Color2] = 0;
return 1;
}

There you go, let me know if u don't understand any part in it.

I don't know if it's something with my script or something but the command still just makes the car to blue, and not more then that.. Anyways, thanks a lot for helping me and your efforts bro!

RogueDrifter
23/02/2018, 09:49 AM
I don't know if it's something with my script or something but the command still just makes the car to blue, and not more then that.. Anyways, thanks a lot for helping me and your efforts bro!
That worked for me, must be your client.

kingmk
23/02/2018, 11:21 AM
KillTimer(Rainbow_Timer[playerid]);
should be
KillTimer(Rainbow_Timer(playerid)); since the compiler complains when i use [playerid] for timers

RogueDrifter it's right, Rainbow_Timer isn't a function, it's a var, so u do Rainbow_Timer[playerid].