GETGIFT CMD
#1

Hello guys my friend gave me this CMD
PHP код:
CMD:getgift(playerid)
{
    if(!
IsPlayerConnected(playerid))
        return 
SendClientMessage(playerid, -1"You must be logged in to do this.");
    
GetObjectPos(giftboxobjectgiftPos[0], giftPos[1], giftPos[2]);
    if(
IsPlayerInRangeOfPoint(playerid5.0giftPos[0], giftPos[1], giftPos[2]) && giftboxcreated == 1)
    {
    
RandomGift(playerid);
    }
    return 
1;

But this CMD can be used like 100's of times together so i want that each player can only be able to do /getgift once they are active for 2 hour like i mean after every 2 hours they can /getgift and if they forget to collect the gift then they can use /getgift after 4 hours 2 times!
Reply
#2

use settimerEX and boolean variable for this purpose
Reply
#3

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
use settimerEX and boolean variable for this purpose
hey! how are u?? and can u plz set the cmd and gimme??
Reply
#4

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
use settimerEX and boolean variable for this purpose
Don't do it.

Use
PHP код:
gettime(); 
to return current Unix timestamp, to that add 2 hours in seconds and store that. Next time player uses this command compare stored timestamp with current one (returned from gettime()).

https://sampwiki.blast.hk/wiki/Gettime
Quote:

This function is useful for measuring time intervals by using its timestamp characteristics. This can be particularly useful if you want to restrict some functionality based on a time (e.g. a command that can only be executed every 30 seconds). Using this method you don't have to rely on timers.

https://en.wikipedia.org/wiki/Unix_time
Reply
#5

i seriously don't know what to do kindly make me the cmd?
Reply
#6

Basically
Код:
new TimeCMD[MAX_PLAYERS];

CMD:getgift(playerid) 
{ 
    if(!IsPlayerConnected(playerid)) 
        return SendClientMessage(playerid, -1, "You must be logged in to do this."); 
	
	if(TimeCMD[playerid] > gettime())
		return SendClientMessage(playerid, -1, "You used this command."); 
	
	TimeCMD[playerid] = 2 * 60 * 60 + gettime();
	
	GetObjectPos(giftboxobject, giftPos[0], giftPos[1], giftPos[2]); 

    if(IsPlayerInRangeOfPoint(playerid, 5.0, giftPos[0], giftPos[1], giftPos[2]) && giftboxcreated == 1) 
    { 
    RandomGift(playerid); 
    } 
    return 1; 
}
Reply
#7

Quote:
Originally Posted by F1N4L
Посмотреть сообщение
Basically
Код:
new TimeCMD[MAX_PLAYERS];

CMD:getgift(playerid) 
{ 
    if(!IsPlayerConnected(playerid)) 
        return SendClientMessage(playerid, -1, "You must be logged in to do this."); 
	
	if(TimeCMD[playerid] > gettime())
		return SendClientMessage(playerid, -1, "You used this command."); 
	
	TimeCMD[playerid] = 2 * 60 * 60 + gettime();
	
	GetObjectPos(giftboxobject, giftPos[0], giftPos[1], giftPos[2]); 

    if(IsPlayerInRangeOfPoint(playerid, 5.0, giftPos[0], giftPos[1], giftPos[2]) && giftboxcreated == 1) 
    { 
    RandomGift(playerid); 
    } 
    return 1; 
}
Thanks! +rep!
Reply
#8

Remember: When the player leaves the server and back can use the cmd again. Save the value of this variable with the player data for not abuse the command!
Thx for the rep.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)