Time limiter for /rob help! -
Panormitis - 28.09.2011
guys how can i add a time limiter in this code?
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/rob", true) == 0) // If they type /rob
{
if(IsPlayerInCheckpoint(playerid)) // Check if they are in a checkpoint
{
GivePlayerMoney(playerid, random(2000+1)); // Give the player the money!
}
return 1; //return one to prevent "SERVER: Unknown command"
}
return 0;
}
I mean that, i want when someone /rob a place, then he must wait 60 minutes for the next /rob, how to add this to the script?
Thanks
Re: Time limiter for /rob help! -
[Diablo] - 28.09.2011
set the variable like robbed = 1; and then set the timer, which will set the robbed back to 0 after x amount of time.
Re: Time limiter for /rob help! -
Panormitis - 28.09.2011
Quote:
Originally Posted by [Diablo]
set the variable like robbed = 1; and then set the timer, which will set the robbed back to 0 after x amount of time.
|
i didn't understand
Re: Time limiter for /rob help! -
[MWR]Blood - 28.09.2011
pawn Код:
new Canrob[MAX_PLAYERS];
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/rob", true) == 0) // If they type /rob
{
if(IsPlayerInCheckpoint(playerid)) // Check if they are in a checkpoint
{
if(CanRob[playerid] == 1)
{
GivePlayerMoney(playerid, random(2000+1)); // Give the player the money!
Canrob[playerid] = 0;
SetTimerEx("CanRob",60000,false,"i",playerid);
else return SendClientMessage(playerid,-1,"You must wait 60 seconds before robbing again!");
}
return 1; //return one to prevent "SERVER: Unknown command"
}
return 0;
}
forward CanRob(playerid);
public CanRob(playerid)
{
Canrob[playerid] = 1;
return 1;
}
Re: Time limiter for /rob help! - suhrab_mujeeb - 28.09.2011
Quote:
Originally Posted by Panormitis
i didn't understand 
|
It's really simple, just read
SetTimer or
SetTimerEx and use variables to help you with the timers. I would've done it for ya but my laptop is dead

.
EDIT: Sorry the above post was posted while I was writing. The above script is exactly how you do it.
Re: Time limiter for /rob help! -
iggy1 - 28.09.2011
Here's a way, there is no need for a timer. You will need to edit make the "iLastRobbery" var an array and assign robbery shops ids to it.
pawn Код:
new iLastRobbery;
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/rob", true) == 0) // If they type /rob
{
if(IsPlayerInCheckpoint(playerid))
{
if(GetTickCount() > iLastRobbery) //if iLastRobbey is less than tickcount. ie. iLastRobbey = GetTickCount + 60 seconds.
{
GivePlayerMoney(playerid, random(2000+1));
iLastRobbery = GetTickCount() + 60000;//iLastRobbery is GetTickCount plus 60 secons
return 1;
}
else {
SendClientMessage(playerid, 0xFF0000AA, "ERROR: That shop has only recently been robbed.");
return 1;
}
}
}
return 0;
}
You need to keep in mind that a player will be able to rob cash at any checkpoint since you only check if they are in a checkpoint and not in a specific checkpoint.
Re: Time limiter for /rob help! -
[Diablo] - 28.09.2011
jap iggy1's way is even better. gj
Re: Time limiter for /rob help! -
Panormitis - 28.09.2011
Quote:
Originally Posted by iggy1
Here's a way, there is no need for a timer. You will need to edit make the "iLastRobbery" var an array and assign robbery shops ids to it.
pawn Код:
new iLastRobbery;
public OnPlayerCommandText(playerid, cmdtext[]) { if(strcmp(cmdtext, "/rob", true) == 0) // If they type /rob { if(IsPlayerInCheckpoint(playerid)) { if(GetTickCount() > iLastRobbery) //if iLastRobbey is less than tickcount. ie. iLastRobbey = GetTickCount + 60 seconds. { GivePlayerMoney(playerid, random(2000+1)); iLastRobbery = GetTickCount() + 60000;//iLastRobbery is GetTickCount plus 60 secons return 1; } else { SendClientMessage(playerid, 0xFF0000AA, "ERROR: That shop has only recently been robbed."); return 1; } } } return 0; }
You need to keep in mind that a player will be able to rob cash at any checkpoint since you only check if they are in a checkpoint and not in a specific checkpoint.
|
i added this, but when i type /rob nothing happens :\
Re: Time limiter for /rob help! -
iggy1 - 28.09.2011
Quote:
Originally Posted by Panormitis
i added this, but when i type /rob nothing happens :\
|
I don't understand why not I'm afraid. I have just tested it several times and it works for me. (i tested without the checkpoint check)