Robtimer help
#1

So, i want to make this when a player robs the casino, he can't rob it again until the time pass [30 mins]. I've done something like this.

Code:
CMD:robbank(playerid,params[])
{
	if(PlayerInfo[playerid][pVIP] == 1)
	{
        if(GetPlayerInterior(playerid) == 3)
        {
				new rand=75000 +(random(35000));
				new Pname[MAX_PLAYER_NAME];
				GetPlayerName(playerid, Pname, sizeof(Pname));
				new str[100];
				new str1[100];
				format(str,sizeof(str),"You've robbed the bank and got $ %d from the robbery", rand);
				format(str1,sizeof(str1)," %s has robbed the bank of Las Venturas and stole $ %d", Pname, rand);
				SendClientMessageToAll(COLOR_ORANGE,str1);
				SendClientMessage(playerid,COLOR_WHITE,str);
				GivePlayerMoney(playerid, rand);
				SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 4);
				SetTimer("RobTimer",300000,0);
		}
		else SendClientMessage(playerid,COLOR_RED,"You're not inside the bank to rob it.");
	}
	else SendClientMessage(playerid,COLOR_RED,"You're not a VIP Member to rob the bank.");
	return 1;
}
And a timer, this is the part i dont know what to do.

Code:
forward RobTimer(playerid);
public RobTimer(playerid)
{
	SendClientMessage(playerid,COLOR_ORANGE,"You can now rob again.");
	return 1;
}
What should i add more? I don't know a thing about timers.
Reply
#2

I think you should add something that won't let the player to rob... (you said that you need). Like a global boolean that stores if the player can rob, checking if a player can rob inside the command, setting that the player can't rob in the command, setting that the player can rob in the timer.
Reply
#3

PHP Code:
new JustRobbed[MAX_PLAYERS]; 
PHP Code:
CMD:robbank(playerid,params[])
{
    if(
PlayerInfo[playerid][pVIP] == && JustRobbed[playerid] == 0)
    {
        if(
GetPlayerInterior(playerid) == 3)
        {
                new 
rand=75000 +(random(35000));
                new 
Pname[MAX_PLAYER_NAME];
                
GetPlayerName(playeridPnamesizeof(Pname));
                new 
str[100];
                                
JustRobbed[playerid] = 1;
                new 
str1[100];
                
format(str,sizeof(str),"You've robbed the bank and got $ %d from the robbery"rand);
                
format(str1,sizeof(str1)," %s has robbed the bank of Las Venturas and stole $ %d"Pnamerand);
                
SendClientMessageToAll(COLOR_ORANGE,str1);
                
SendClientMessage(playerid,COLOR_WHITE,str);
                
GivePlayerMoney(playeridrand);
                
SetPlayerWantedLevel(playeridGetPlayerWantedLevel(playerid) + 4);
                
SetTimer("RobTimer",300000,0);
        }
        else 
SendClientMessage(playerid,COLOR_RED,"You're not inside the bank to rob it.");
    }
    else 
SendClientMessage(playerid,COLOR_RED,"You're not a VIP Member to rob the bank.");
    return 
1;

PHP Code:
forward RobTimer(playerid);
public 
RobTimer(playerid)
{
    
SendClientMessage(playerid,COLOR_ORANGE,"You can now rob again.");
        
JustRobbed[playerid] = 0;
    return 
1;

Reply
#4

There's no need to use 2 variables to send a message. Format the first one, send it. Then do the same with the other.


Code:
SetTimer("RobTimer",300000,0);
is not going to work.

https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#5

Thank you everyone, works like a charm now.
Reply
#6

Quote:
Originally Posted by Escobabe
View Post
Thank you everyone, works like a charm now.
Hello regarding your problem, I think it will not work 100%, because if the player can disconnect and connect with another ID and you can steal again unless you have a system to save, another thing that may happen is that the player is disconnected and the timer will continue to run and the player that connects with that ID will tell him that he can steal again, in my case I would use gettime ()

I will give you an example and it is much better because this way you can not abuse the command.

PHP Code:
new JustRobTime[MAX_PLAYERS]; 
PHP Code:
CMD:robbank(playerid,params[]) 

    if(
PlayerInfo[playerid][pVIP] == && JustRobTime[playerid] < gettime()) //Check if you can steal by comparing the time
    

        if(
GetPlayerInterior(playerid) == 3
        { 
                new 
rand=75000 +(random(35000)); 
                new 
Pname[MAX_PLAYER_NAME]; 
                
GetPlayerName(playeridPnamesizeof(Pname)); 
                new 
str[100]; 
                
JustRobTime[playerid] = gettime()+1800;//1800 Seconds = 30 Minuts
                
format(str,sizeof(str),"You've robbed the bank and got $ %d from the robbery"rand); 
                
SendClientMessage(playerid,COLOR_WHITE,str); 
                
format(str,sizeof(str)," %s has robbed the bank of Las Venturas and stole $ %d"Pnamerand); 
                
SendClientMessageToAll(COLOR_ORANGE,str);  
                
GivePlayerMoney(playeridrand); 
                
SetPlayerWantedLevel(playeridGetPlayerWantedLevel(playerid) + 4); 
        } 
        else 
SendClientMessage(playerid,COLOR_RED,"You're not inside the bank to rob it."); 
    } 
    else 
SendClientMessage(playerid,COLOR_RED,"You're not a VIP Member to rob the bank."); 
    return 
1

With this command you can see how much time you need to steal again.

PHP Code:
CMD:robtime(playeridparmas[])
{
    if(
JustRobTime[playerid] < gettime()) return SendClientMessage(playerid, -1"You can steal again");
    new 
RobString[72];
    
format(RobStringsizeof(RobString), "[Rob]  Wait {37B9F5}%d minut(s){FFFAFF} to re-steal",  (JustRobTime[playerid] - gettime()/60)); 
    
SendClientMessage(playerid, -1RobString);
    return 
1;

I would do it this way avoided using Timer.
I did that so I can give you the minutes even if I did not try or compile it, do it and tell me if it works, remember to delete the variable when the player disconnects and load it where you load your users account.

And as they say above do not use two variables to give the format with one is enough I leave the code without the two variables. Another thing is that if you use timer with parameter for example playerid. Use SetTimerEx in SetTimer because the code you passed uses SetTimer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)