SA-MP Forums Archive
changecolor timer - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: changecolor timer (/showthread.php?tid=650202)



changecolor timer - rakinz - 23.02.2018

Код:
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?


Re: changecolor timer - RogueDrifter - 23.02.2018

This
Quote:

new vehicleid;
GetPlayerVehicleID(playerid);

That's not how you specify a value to a variable,
more like this:

PHP код:
new vehicleid GetPlayerVehicleID(playerid); 



Re: changecolor timer - rfr - 23.02.2018

PHP код:
new hasplayerrainbow[MAX_PLAYERS] = false;
CMD:rainbow(playeridparams[])
{
    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"2000true"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"2000true"i"playerid);
    }
    return 
1;
}
CMD:killrainbow(playeridparams[])
{
    if (
hasplayerrainbow[playerid])
    {
        
hasplayerrainbow[playerid] = false;
        
KillTimer(RainBow(playerid));
        
SendClientMessage(playerid, -1"rainbow deactivated");
    }
    else
    {
        
SendClientMessage(playerid, -1"you don't have rainbow activated");
    }




Re: changecolor timer - rakinz - 23.02.2018

Quote:
Originally Posted by rfr
Посмотреть сообщение
Код:
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.


Re: changecolor timer - rfr - 23.02.2018

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


Re: changecolor timer - PepsiCola23 - 23.02.2018

Why do you set the same timer twice if one is already is repeating?remove the one in the function


Re: changecolor timer - rakinz - 23.02.2018

Quote:
Originally Posted by PepsiCola23
Посмотреть сообщение
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.


Re: changecolor timer - RogueDrifter - 23.02.2018

I'd say try this:
PHP код:
new Rainbow_Timer[MAX_PLAYERS];
CMD:rainbow(playeridparams[])
{
    if(
GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playeridCOLOR_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"2000true"i"playerid);
    return 
1;
}
forward RainBow(playerid);
public 
RainBow(playerid)
{
    if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVERChangeVehicleColor(GetPlayerVehicleID(playerid),-1,-1);
    
    return 
1;

And use:
Код:
KillTimer(Rainbow_Timer[playerid]);
At OnPlayerDisconnect strictly:
PHP код:
public OnPlayerDisconnect(playeridreason)
{
    
KillTimer(Rainbow_Timer[playerid]);
    return 
1;

and

OnPlayerStateChange with a state check
PHP код:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
newstate == && oldstate == 2)  KillTimer(Rainbow_Timer[playerid]);
    return 
1;




Re: changecolor timer - rfr - 23.02.2018

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
I'd say try this:
PHP код:
new Rainbow_Timer[MAX_PLAYERS];
CMD:rainbow(playeridparams[])
{
    if(
GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playeridCOLOR_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"2000true"i"playerid);
    return 
1;
}
forward RainBow(playerid);
public 
RainBow(playerid)
{
    if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVERChangeVehicleColor(GetPlayerVehicleID(playerid),-1,-1);
    
    return 
1;

And use:
Код:
KillTimer(Rainbow_Timer[playerid]);
At OnPlayerDisconnect strictly:
PHP код:
public OnPlayerDisconnect(playeridreason)
{
    
KillTimer(Rainbow_Timer[playerid]);
    return 
1;

and

OnPlayerStateChange with a state check
PHP код:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
newstate == && 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


Re: changecolor timer - RogueDrifter - 23.02.2018

Quote:
Originally Posted by rfr
Посмотреть сообщение
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.