SA-MP Forums Archive
3 minute delays between certain commands? - 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: 3 minute delays between certain commands? (/showthread.php?tid=338263)



3 minute delays between certain commands? - JAMMIEISFTW - 29.04.2012

its using DCMD

How can i put 3 minute delays between commands?



In OnPlayerCommandText:
pawn Код:
dcmd(wank, 4, cmdtext);

Code to the command
pawn Код:
dcmd_wank(playerid, params[])
{
    new id;
    if(gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_ARMY || gTeam[playerid] == TEAM_CIA) return SendClientMessage(playerid, -1, "Cops, CIA, and Army cannot wank!");
    if(sscanf(params, "u",id)
    {
        SendClientMessage(playerid, -1, "You wanked in public on nobody.. wanted level increased");
        SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1);
    }
    else
    {
    new name[24], string[128];
    GetPlayerName(id, name, sizeof name);
    format(string, sizeof string, "You wanked on %s, wanted level increased!", name);
    SendClientMessage(playerid, -1, string);
    SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 3);
    }
    return 1;
}



Re: 3 minute delays between certain commands? - Niko_boy - 29.04.2012

create a playe rvariable
new IsUsed[MAX_PLAYERS];
at top
then in command do like
if(IsUsed[playerid] == 1 ) return SendClientMessage(playerid, -1, "You Just used command");
so it will be like :-

pawn Код:
dcmd_wank(playerid, params[])
{
    new id;
   if(IsUsed[playerid] == 1 ) return SendClientMessage(playerid, -1, "You Just used command");
    if(gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_ARMY || gTeam[playerid] == TEAM_CIA) return SendClientMessage(playerid, -1, "Cops, CIA, and Army cannot wank!");
    if(sscanf(params, "u",id)
    {
        SendClientMessage(playerid, -1, "You wanked in public on nobody.. wanted level increased");
        SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1);
    }
    else
    {
    new name[24], string[128];
    GetPlayerName(id, name, sizeof name);
    format(string, sizeof string, "You wanked on %s, wanted level increased!", name);
    SendClientMessage(playerid, -1, string);
    SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 3);
    }
IsUsed[Playerid] =  1;
SetTimerEx("UsedReset",false,3*10000,"i",playerid);// 10000 = 1 minute so i did 3* to multiply it by 3 so it will be 3 minutes now
    return 1;
}
and :-

a new public function
Code:

pawn Код:
forward UsedReset(playerid);// at top
public UsedReset(playerid)
{
  IsUsed = 0;

}
some where down the script
this isnt fastest and best method though i have only tried this.
Also i Guess to do like this there will be needed for many new player variables; cause its command specific.
^fail english sorry.
=-----------=

You can also use OnCommandRecieved Function but i never tried it


Re: 3 minute delays between certain commands? - JAMMIEISFTW - 29.04.2012

Quote:
Originally Posted by Niko_boy
Посмотреть сообщение
create a playe rvariable
new IsUsed[MAX_PLAYERS];
at top
then in command do like
if(IsUsed[playerid] == 1 ) return SendClientMessage(playerid, -1, "You Just used command");
so it will be like :-
pawn Код:
dcmd_wank(playerid, params[])
{
    new id;
   if(IsUsed[playerid] == 1 ) return SendClientMessage(playerid, -1, "You Just used command");
    if(gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_ARMY || gTeam[playerid] == TEAM_CIA) return SendClientMessage(playerid, -1, "Cops, CIA, and Army cannot wank!");
    if(sscanf(params, "u",id)
    {
        SendClientMessage(playerid, -1, "You wanked in public on nobody.. wanted level increased");
        SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1);
    }
    else
    {
    new name[24], string[128];
    GetPlayerName(id, name, sizeof name);
    format(string, sizeof string, "You wanked on %s, wanted level increased!", name);
    SendClientMessage(playerid, -1, string);
    SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 3);
    }
IsUsed[Playerid] =  1;
SetTimerEx("UsedReset",false,3*10000,"i",playerid);// 10000 = 1 minute so i did 3* to multiply it by 3 so it will be 3 minutes now
    return 1;
}
and :-

a new public function
Код:
forward UsedReset(playerid);// at top
public UsedReset(playerid)
{
  IsUsed = 0;

}
some where down the script
this isnt fastest and best method though i have only tried this.
Also i Guess to do like this there will be needed for many new player variables; cause its command specific.
^fail english sorry.
=-----------=

You can also use OnCommandRecieved Function but i never tried it
C:\Users\Public\Documents\neww\gamemodes\SFCRRPG.p wn(13166) : error 033: array must be indexed (variable "IsUsed")
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.


Re: 3 minute delays between certain commands? - Niko_boy - 29.04.2012

oh my mistake
pawn Код:
public UsedReset(playerid)
{
  IsUsed[playerid] = 0; //fix here

}



Re: 3 minute delays between certain commands? - JAMMIEISFTW - 29.04.2012

Thanks, plus i had to fix u putting Playerid instead of playerid lol


Re: 3 minute delays between certain commands? - JAMMIEISFTW - 29.04.2012

didnt work, rofl..


Re: 3 minute delays between certain commands? - Niko_boy - 29.04.2012

try this ?
pawn Код:
dcmd_wank(playerid, params[])
{
    new id;
   if(!IsUsed[playerid] == 1)
{
    if(gTeam[playerid] == TEAM_COP || gTeam[playerid] == TEAM_ARMY || gTeam[playerid] == TEAM_CIA) return SendClientMessage(playerid, -1, "Cops, CIA, and Army cannot wank!");
    if(sscanf(params, "u",id)
    {
        SendClientMessage(playerid, -1, "You wanked in public on nobody.. wanted level increased");
        SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1);
    }
    else
    {
    new name[24], string[128];
    GetPlayerName(id, name, sizeof name);
    format(string, sizeof string, "You wanked on %s, wanted level increased!", name);
    SendClientMessage(playerid, -1, string);
    SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 3);
    }
IsUsed[Playerid] =  1;
SetTimerEx("UsedReset",false,3*10000,"i",playerid);// 10000 = 1 minute so i did 3* to multiply it by 3 so it will be 3 minutes now
}else SendClientMessage(playerid, -1, "You Just used command");
    return 1;
}
that ^


Re: 3 minute delays between certain commands? - JAMMIEISFTW - 29.04.2012

C:\Users\Public\Documents\neww\pawno\include\dutil s.inc(2 : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\dutil s.inc(132) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\dutil s.inc(172) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\dutil s.inc(280) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\dutil s.inc(337) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\dutil s.inc(379) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\dini. inc(239) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\dprop s.inc(25) : warning 219: local variable "name" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\dprop s.inc(34) : warning 219: local variable "name" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\dprop s.inc(45) : warning 219: local variable "name" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\sscan f2.inc(101) : warning 219: local variable "name" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\sscan f2.inc(21 : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\sscan f2.inc(21 : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\sscan f2.inc(27 : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\pawno\include\sscan f2.inc(27 : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\gamemodes\SFCRRPG.p wn(936) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\gamemodes\SFCRRPG.p wn(944) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Public\Documents\neww\gamemodes\SFCRRPG.p wn(1443) : warning 219: local variable "string" shadows a variable at a preceding level


Re: 3 minute delays between certain commands? - MP2 - 29.04.2012

No need for timers.

pawn Код:
new pWankLimit[MAX_PLAYERS];
dcmd_cmd(playerid, params[])
{
    if(gettime()-pWankLimit[playerid] < (3*60)) return SendClientMessage(playerid, COLOR_RED, "You have wanked recently.");
    // code
    pWankLimit[playerid] = gettime();
    return 1;
}



Re: 3 minute delays between certain commands? - JAMMIEISFTW - 29.04.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
No need for timers.

pawn Код:
new pWankLimit[MAX_PLAYERS];
dcmd_cmd(playerid, params[])
{
    if(gettime()-pWankLimit[playerid] < (3*60)) return SendClientMessage(playerid, COLOR_RED, "You have wanked recently.");
    // code
    pWankLimit[playerid] = gettime();
    return 1;
}
where do i put it all??

P.s i need this for other commands too, like /spit /vomit /piss