changecolor timer
#1

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

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); 
Reply
#3

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");
    }

Reply
#4

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.
Reply
#5

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
Reply
#6

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

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.
Reply
#8

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;

Reply
#9

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
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)