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



Help with timers - KtotheYle - 12.01.2014

Hello, so I am doing a pursuit system and it is based so that when the cop uses the command /chase when every 5 seconds a new marker will appear for police that will be followable by other police.

This is the command

Код:
CMD:chase(playerid, params[])
{
	if(PlayerInfo[playerid][pFaction] == LSPD)
	{
	    new string[128];
	    new sendername[MAX_PLAYER_NAME];
	    GetPlayerName(playerid, sendername, sizeof(sendername));
	    SetTimer(Pursuit(playerid), 5000, true);
	    format(string, sizeof(string), "Dispatcher: All units be advised there is a pursuir on behave of %s!", sendername);
	    SendFactionMessage(LSPD, COLOR_BLUE, string);
	}
	else
	{
	    SendClientMessage(playerid, COLOR_RED, "You are not a LEO!");
	}
}
The error

Код:
error 035: argument type mismatch (argument 1)
And the line the error is on

Код:
SetTimer(Pursuit(playerid), 5000, true);
Also here is the public

Код:
public Pursuit(playerid)
{
	new Float:x, Float:y, Float:z;
	GetPlayerPos(playerid, x, y, z);
	SetPlayerCheckpoint(x, y, z, 5);
}
and if it is needed the command to stop the pursuit

Код:
CMD:killchase(playerid, params[])
{
	if(PlayerInfo[playerid][pFaction] == LSPD)
	{
		KillTimer(Pursuit(playerid));
	}
}
Thank you for any help!


Re: Help with timers - Konstantinos - 12.01.2014

pawn Код:
new
    Pursuit_Timer[MAX_PLAYERS] = {-1, ...};
                                 
// OnPlayerConnect:
Pursuit_Timer[playerid] = -1;

forward Pursuit(playerid);
public Pursuit(playerid)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for (new i; i != MAX_PLAYERS; ++i) if (PlayerInfo[i][pFaction] == LSPD) SetPlayerCheckpoint(i, x, y, z, 5);
}

CMD:chase(playerid, params[])
{
    if(PlayerInfo[playerid][pFaction] == LSPD)
    {
        new string[128];
        new sendername[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sendername, sizeof(sendername));
        Pursuit_Timer[playerid] = SetTimer("Pursuit", 5000, true, "i", playerid);
        format(string, sizeof(string), "Dispatcher: All units be advised there is a pursuir on behave of %s!", sendername);
        SendFactionMessage(LSPD, COLOR_BLUE, string);
    }
    else SendClientMessage(playerid, COLOR_RED, "You are not a LEO!");
    return 1;
}

CMD:killchase(playerid, params[])
{
    if(PlayerInfo[playerid][pFaction] == LSPD)
    {
        KillTimer(Pursuit_Timer[playerid]);
    }
    return 1;
}



Re : Help with timers - S4t3K - 12.01.2014

PHP код:

// First one
// Top of your GM
new pursuitTimer[MAX_PLAYERS] = 0;
CMD:chase(playeridparams[])
{
    if(
PlayerInfo[playerid][pFaction] == LSPD)
    {
        new 
string[128];
        new 
sendername[MAX_PLAYER_NAME];
        
GetPlayerName(playeridsendernamesizeof(sendername));
        
pursuitTimer[playerid] = SetTimer("Pursuit"5000true);
        
format(stringsizeof(string), "Dispatcher: All units be advised there is a pursuir on behave of %s!"sendername);
        
SendFactionMessage(LSPDCOLOR_BLUEstring);
    }
    else
    {
        
SendClientMessage(playeridCOLOR_RED"You are not a LEO!");
    }
}
// I've just removed the (playerid) of the timer. The public function is forwarded so the playerid here is useless and the compiler gives you this error.
// Second one
KillTimer(pursuitTimer[playerid]);
// Timerid doesn't mean function name that the timer call.
// You need to create a var with new, and to assign the var to the timer when you use SetTimer.
// It also works for SetTimerEx. 
Enjoy

EDIT : Konstantinos has been faster than me


Re: Help with timers - dakata994 - 12.01.2014

Just change this
Код:
SetTimer(Pursuit(playerid), 5000, true);
To This:
Код:
SetTimer("Pursuit", 5000, true);

And for that
Код:
CMD:killchase(playerid, params[])
{
    if(PlayerInfo[playerid][pFaction] == LSPD)
    {
        KillTimer(Pursuit_Timer[playerid]);
    }
    return 1;
}
Use That
Код:
CMD:killchase(playerid, params[])
{
    if(PlayerInfo[playerid][pFaction] == LSPD)
    {
        KillTimer("Pursuit");
    }
    return 1;
}



Re: Help with timers - Konstantinos - 12.01.2014

Quote:
Originally Posted by dakata994
Посмотреть сообщение
Just change this
Код:
SetTimer(Pursuit(playerid), 5000, true);
To This:
Код:
SetTimer("Pursuit", 5000, true);
Unfortunately, that will not work either. He should pass playerid as argument in SetTimerEx (SetTimer does not have parameters for its callbacks) because everytime the timer's callback will be called, it'll get the position of the player with ID 0.


Re: Help with timers - KtotheYle - 12.01.2014

Thanks guys for the reply!