SA-MP Forums Archive
Timer Not Working - 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: Timer Not Working (/showthread.php?tid=445842)



Timer Not Working - NoahF - 23.06.2013

When I go IG and spawn, after 3 minutes I do not get any score. (Yes, I loaded the FS.)
Here's the code:
Код:
forward ScoreTimer(playerid);
public OnPlayerSpawn(playerid)
{
	SetTimer("ScoreTimer", 180000, true);
	return 1;
}

public ScoreTimer(playerid)
{
        SetPlayerScore(playerid, GetPlayerScore(playerid) + 2);
	SendClientMessage(playerid, COLOR_LBLUE, "You have played for 3 minutes, you have earned +2 score!");
	return 1;
}
It's supposed to make each player get +2 score after 3 minutes of playing.


Re: Timer Not Working - Pangea - 23.06.2013

It does work but ScoreTimer needs a playerid.
SetTimer does not support parameters, which ScoreTimer needs.

Use SetTimerEx instead.
pawn Код:
public OnPlayerSpawn(playerid)
{
    SetTimerEx("ScoreTimer", 180000, true, "i", playerid);
    return 1;
}



Re: Timer Not Working - NoahF - 23.06.2013

Thank you. I have +REPPED you. :P


Re: Timer Not Working - NoahF - 23.06.2013

It still doesn't work though, just tested it


Re: Timer Not Working - Vince - 23.06.2013

Quote:
Originally Posted by Pangea
Посмотреть сообщение
It does work but ScoreTimer needs a playerid.
SetTimer does not support parameters, which ScoreTimer needs.

Use SetTimerEx instead.
pawn Код:
public OnPlayerSpawn(playerid)
{
    SetTimerEx("ScoreTimer", 180000, true, "i", playerid);
    return 1;
}
This actually won't work properly unless you destroy the timer in OnPlayerDeath and OnPlayerDisconnect. Every time the player spawns a new timer will be set while the old one is still running.


Re: Timer Not Working - NoahF - 23.06.2013

I get these errors:

Код:
C:\Users\Noah\Desktop\[sK] Zombie Apocalypse\filterscripts\autoscore.pwn(37) : error 055: start of function body without function header
C:\Users\Noah\Desktop\[sK] Zombie Apocalypse\filterscripts\autoscore.pwn(39) : error 010: invalid function or declaration
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
Lines:
Код:
public OnPlayerDisconnect(playerid, reason);
{
    KillTimer(ScoreTimer[playerid]);
    return 1;
}



Re: Timer Not Working - NoahF - 23.06.2013

Anyone?? I really need help with this :<


Re: Timer Not Working - Camorra - 23.06.2013

I thinks that need be under one of them
Код:
or
public OnPlayerConnect(playerid)
or
public OnGameModeInit()



AW: Timer Not Working - Skimmer - 23.06.2013

Try this and let me know if it works.

pawn Код:
new ScoreTimer[MAX_PLAYERS]; // Add this top of your script

public OnPlayerSpawn(playerid)
{
    ScoreTimer[playerid] = SetTimerEx("ScoreTimer", 180000, true, "i", playerid);
    return 1;
}

forward ScoreTimer(playerid);
public ScoreTimer(playerid)
{
    SetPlayerScore(playerid, GetPlayerScore(playerid) + 2);
    SendClientMessage(playerid, COLOR_LBLUE, "You have played for 3 minutes, you have earned +2 score!");
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    KillTimer(ScoreTimer[playerid]);
    return 1;
}



Re: Timer Not Working - NoahF - 23.06.2013

Код:
C:\Users\Noah\Desktop\[sK] Zombie Apocalypse\filterscripts\autoscore.pwn(13) : error 021: symbol already defined: "ScoreTimer"
C:\Users\Noah\Desktop\[sK] Zombie Apocalypse\filterscripts\autoscore.pwn(14) : error 021: symbol already defined: "ScoreTimer"
C:\Users\Noah\Desktop\[sK] Zombie Apocalypse\filterscripts\autoscore.pwn(18) : error 010: invalid function or declaration
Line 13:
Код:
forward ScoreTimer(playerid);
Line 14:
Код:
public ScoreTimer(playerid)
Line 18:
Код:
return 1;