Quote:
Originally Posted by Lordzy
I doubt your code is being excessively called when the keys are pressed repeatedly. Debug your code in such cases and also assign a default value for all indexed timers (Timer Ids other than -1 should be flagged as running timers)
pawn Код:
if( storeData[i][virtualID] == GetPlayerVirtualWorld(playerid) ) { if(robTimer[playerid] != -1) { //Then your usual code. } //Other than that, you know the timer is running so further calls aren't necessary. }
//Whenever you disable or kill your timer, set the robTimer array also to -1. KillTimer(robTimer); robTimer[playerid] = -1;
//Always assign indexed timers to -1 under OnPlayerConnect or your necessary callback.
I used to have a pre-defined KillTimer function to handle these indexed arrays within the function.
pawn Код:
stock KillTimerEx(&timerid) {
KillTimer(timerid); timerid = -1; }
I haven't gone thoroughly with your code, but try debugging using print or SendClientMessage functions if the problem still persists.
|
I followed what you suggested, and it seems to work but only on the second time you press the key; I pressed the key once and the timer started but continued very slowly, I pressed it again, and it continued at its normal pace.
Код:
if(newkeys & KEY_WALK)
{
for(new i = 0; i != sizeof(storeData); ++i)
{
if(IsPlayerInRangeOfPoint(playerid, 1.0, storeData[i][cpPos][0], storeData[i][cpPos][1], storeData[i][cpPos][2]))
{
if( storeData[i][virtualID] == GetPlayerVirtualWorld(playerid) )
{
if( robTimer[playerid] != -1 )
{
SendClientMessage(playerid, -1, "You have begun a robbery");
robTimer[playerid] = SetTimerEx("StoreRobbery", 1000, true, "i", playerid);
}
}
}
}
}
Код:
public StoreRobbery( playerid )
{
TimeLeft[playerid] --;
if( TimeLeft[ playerid ] > 0 )
{
SendClientMessage(playerid, -1, "-1");
}
else if( TimeLeft[ playerid ] == 0 )
{
SendClientMessage(playerid, -1, "You have completed a robbery");
KillTimer(robTimer[playerid]);
robTimer[playerid] = -1;
}
printf("%d", TimeLeft[playerid]);
return 1;
}
__________________________________________________ ________
Quote:
Originally Posted by Luicy.
|
I've tried this too, and it's still the same case. It goes slow on the first time you press it, but the second time you press it, it goes at its normal pace.