Timers and values getting mixed up
#1

Hello, I recently experienced an unknown problem for me where the values and some timers get mixed up in my script. When I was using SetTimer and I was ID 1, the function activated for my friend with ID 0. I tried using SetTimerEx, but what that did, it now sets isabletoscrap[playerid] to be 0 for one of us, despite me writing new isabletoscrap[MAX_PLAYERS] = 1; in the top of the script. I have absolutely no idea what causes this, although it might be staring me right in the face... as always. So, here's the code:

Код:
new smaterials[MAX_PLAYERS] = 0;

new isabletoscrap[MAX_PLAYERS] = 1;

forward scrapTimer(playerid);
public scrapTimer(playerid)
{
 	new scrapvehicle = GetPlayerVehicleID(playerid);
	smaterials[playerid] += 40;
	SendClientMessage(playerid,0x03D687FF,"You scrapped a car for 40 materials!");
	SetTimerEx("waitscrapTimer", 900000, false, "i", playerid);
	SendClientMessage(playerid,0x03D687FF,"You can scrap again in 15 minutes!");
	TogglePlayerControllable(playerid,1);
	 SetVehicleToRespawn(scrapvehicle);
	 isabletoscrap[playerid] = 0;
}
forward waitscrapTimer(playerid);
public waitscrapTimer(playerid)
{

 SendClientMessage(playerid,COLOR_GREEN,"You can now scrap again!");
 isabletoscrap[playerid] = 1;

}



CMD:scrapcar(playerid, params[])
{
	new scrapvehicle = GetPlayerVehicleID(playerid);
    if(GetVehicleModel(scrapvehicle) == 604 || GetVehicleModel(scrapvehicle) == 605)
    {
    
	if (isabletoscrap[playerid] == 0) return SendClientMessage(playerid,0x03D687FF,"You can scrap again after 15 minutes have passed!");
	
	if(IsPlayerInRangeOfPoint(playerid, 10.0, 4.1837700,1345.4106400,8.5145000))
   			{
        	SendClientMessage(playerid, 0xC9FF78FF, "You have started scrapping your vehicle, please wait 10 seconds..");
    		//SetTimer("scrapTimer", 6000, false);
    		SetTimerEx("scrapTimer", 10000, false, "i", playerid);
    		SetVehicleToRespawn(scrapvehicle);
    		RemovePlayerFromVehicle(playerid);
    		TogglePlayerControllable(playerid,0);
    		}
    else return SendClientMessage(playerid,COLOR_RED,"You aren't near the /scrapcar checkpoint!");
    }
    else return SendClientMessage(playerid,COLOR_RED,"You must be in a scrappable vehicle! ((Broken Sadler and Broken Glendale))");
    return 1;
    
}
I would greatly appreciate any help regarding this issue! Thanks very much for reading!
Reply
#2

Use variables for timers:
at top:
Код:
new timer[MAX_PLAYERS];//for all players
and when you start the timer, use
Код:
timer[playerid] = SetTimerEx(.......);
Reply
#3

Quote:

Use variables for timers:
at top:
Code:

new timer[MAX_PLAYERS];//for all players

and when you start the timer, use
Code:

timer[playerid] = SetTimerEx(.......);
Thanks very much, that worked perfectly!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)