SA-MP Forums Archive
[HELP] How can i do a command with time? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] How can i do a command with time? (/showthread.php?tid=109883)



[HELP] How can i do a command with time? - akis_tze - 22.11.2009

for example
i want to create a command which every player can use it every 15 seconds


if you know how plz help me


Re: [HELP] How can i do a command with time? - -xy! - 22.11.2009

https://sampwiki.blast.hk/wiki/SetTimer


Re: [HELP] How can i do a command with time? - ExoSanty - 23.11.2009

Quote:
Originally Posted by -xy!
will be more like https://sampwiki.blast.hk/wiki/SetTimerEx since you will have to give along the playerid to the timer...

Код:
new CmdTimer[MAX_PLAYERS];
new bool:CanUseCmd[MAX_PLAYERS];
forward releasecmd(playerid);
in the public OnPlayerConnect(playerid):

Код:
CanUseCmd[playerid] = true;
in the OnPlayerCommandText:

Код:
if (strcmp("/yourcommand", cmdtext, true) == 0)
{
	if(CanUseCmd[playerid] == true)
	{
		// let your command do what is must do... +
		CanUseCmd[playerid] = false;
		CmdTimer[playerid] = SetTimerEx("releasecmd", 15000, false, "i", 1, playerid);
	} else {
		//let the player know he has to wait...
	}
	return 1;
}
and finaly:

Код:
stock releasecmd(playerid)
{
   CanUseCmd[playerid] = true;
   KillTimer(CmdTimer[playerid]); //suggest you place this line in the onplayerdisconnect as well
}
havent tested this, so i dont know if it will work. at least it sets you in the right direction...




Re: [HELP] How can i do a command with time? - Abernethy - 23.11.2009

Quote:
Originally Posted by ExoSanty
Quote:
Originally Posted by -xy!
will be more like https://sampwiki.blast.hk/wiki/SetTimerEx since you will have to give along the playerid to the timer...

Код:
new CmdTimer[MAX_PLAYERS];
new bool:CanUseCmd[MAX_PLAYERS];
forward releasecmd(playerid);
in the public OnPlayerConnect(playerid):

Код:
CanUseCmd[playerid] = true;
in the OnPlayerCommandText:

Код:
if (strcmp("/yourcommand", cmdtext, true) == 0)
{
	if(CanUseCmd[playerid] == true)
	{
		// let your command do what is must do... +
		CanUseCmd[playerid] = false;
		CmdTimer[playerid] = SetTimerEx("releasecmd", 15000, false, "i", 1, playerid);
	} else {
		//let the player know he has to wait...
	}
	return 1;
}
and finaly:

Код:
stock releasecmd(playerid)
{
   CanUseCmd[playerid] = true;
   KillTimer(CmdTimer[playerid]); //suggest you place this line in the onplayerdisconnect as well
}
havent tested this, so i dont know if it will work. at least it sets you in the right direction...

That code is fucked up the rear.

pawn Код:
// Top of Script
new bool:CommandAvailable[MAX_PLAYERS];

forward CommandTimer(playerid);
pawn Код:
public OnPlayerConnect(playerid)
{
  CommandAvailable[playerid] = true;
    return true;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
    if (CommandAvailable[playerid] == true) return GameTextForPlayer(playerid, "~r~Wait 15 seconds", 1000, 1);
   
    else if (CommandAvailable[playerid] == true)
    {
      //effect
      SetTimerEx("CommandTimer(playerid)", 15000, false, "i", playerid); // Not sure of the placeholder, sorry :3
    }
    return true;
    }
   
    return false;
}
pawn Код:
// Bottom of script
public CommandTimer(playerid)
{
    CommandAvailable[playerid] = true;
    return true;
}



Re: [HELP] How can i do a command with time? - ExoSanty - 23.11.2009

Quote:
Originally Posted by Aber▲
That code is fucked up the rear.
as i said, in the right direction...


Re: [HELP] How can i do a command with time? - Donny_k - 23.11.2009

You don't need a timer for this, I'll post some code from my anti include which you can use, just change the code to suit.

Global:
pawn Код:
#define TIME_BETWEEN_SPAMCHAT       3

#if !defined NO_SPAM_PROTECTION
    new
        gLastTime[ MAX_PLAYERS ] = 0;
       
    #if TIME_BETWEEN_SPAMCHAT < 1
        #error The value of TIME_BETWEEN_SPAMCHAT should be greater than zero
    #endif
#endif
Connect and Disconnect:
pawn Код:
#if !defined NO_SPAM_PROTECTION
        gLastTime[ playerid ] = 0;
    #endif
Text callbacks like OnPlayerText/Command etc:

pawn Код:
#if !defined NO_SPAM_PROTECTION
    new
            current_time = gettime() - gLastTime[ playerid ];

    if ( current_time < TIME_BETWEEN_SPAMCHAT ) return false;
    else gLastTime[ playerid ] = gettime();
    #endif
As you can see no timers are required and ignore the indentation as it's fine in the script.