SA-MP Forums Archive
Help timers - 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: Help timers (/showthread.php?tid=597230)



Help timers - Amunra - 28.12.2015

Why i Have problem with timers ? I Used y_timers in my filterscript,, The problem is : I Make 300000 for 1 coins // 300second.. But The Times is not work ,, Sometimes the timers Not 300 second but give players for 1 coins in 14 second..etc !! are you have SOME IDEA ? for this bug ?



Re: Help timers - AndySedeyn - 28.12.2015

Show us the code.


Re: Help timers - Amunra - 28.12.2015

Quote:

timer CoinHour[300000](playerid)
{
SendClientMessage(playerid, COLOR_GREEN, "LUCKY DRAW: You've got 1 Coins that can be used in /luckydraw");
DataPlayer[playerid][pcoin] += 1;
new INI:File = INI_Open(LDPath(playerid));
INI_SetTag(File,"DataPlayer");
INI_WriteInt(File,"Coins",DataPlayer[playerid][pcoin]);
INI_Close(File);
}

I Know the problem From Where ? But Maybe from here or My include


Re: Help timers - AndySedeyn - 28.12.2015

Can you show me the code where you call the timer?


Re: Help timers - Amunra - 28.12.2015

Quote:

public OnPlayerConnect(playerid)
{
DrawOn[playerid] = 0;
repeat CoinHour(playerid);
if(fexist(LDPath(playerid)))
{
INI_ParseFile(LDPath(playerid), "LoadPlayer_%s", .bExtra = true, .extra = playerid);
}
return 1;
}

Here


Re: Help timers - Amunra - 28.12.2015

PHP код:
public OnPlayerConnect(playerid)
{
     
DrawOn[playerid] = 0;
    
repeat CoinHour(playerid);
    if(
fexist(LDPath(playerid)))
    {
        
INI_ParseFile(LDPath(playerid), "LoadPlayer_%s", .bExtra true, .extra playerid);
    }
    return 
1;

Here ! The bug is : Player get Coins not On 300 second But Not Certainly


Re: Help timers - AndySedeyn - 28.12.2015

I personally would put this in a global task rather than an individual timer. The code underneath is using foreach:

PHP код:
public OnGameModeInit() {
    
HourTimer();
    return 
1;
}
task HourTimer[3600000]() {
    foreach(new 
Player) {
        
// Coin draw
        
SendClientMessage(iCOLOR_GREEN"LUCKY DRAW: You've got 1 coin that can be used in /luckydraw!");
        
DataPlayer[i][pcoin] ++;
        new 
INI:File INI_Open(LDPath(i));
        
INI_SetTag(File"DataPlayer");
        
INI_WriteInt(File"Coins"DataPlayer[i][pcoin]);
        
INI_Close(File);
    }

Alternatively (and I actually recommend it), you can check whether the player is logged in or not. If your script makes use of this, of course.

PHP код:
task HourTimer[3600000]() {
    foreach(new 
Player) {
        if(!
DataPlayer[i][ploggedin]) {
            continue;
        }
        
        
// Coin draw
        
SendClientMessage(iCOLOR_GREEN"LUCKY DRAW: You've got 1 coin that can be used in /luckydraw!");
        
DataPlayer[i][pcoin] ++;
        new 
INI:File INI_Open(LDPath(i));
        
INI_SetTag(File"DataPlayer");
        
INI_WriteInt(File"Coins"DataPlayer[i][pcoin]);
        
INI_Close(File);
    }