CMD:getgift(playerid)
{
if(!IsPlayerConnected(playerid))
return SendClientMessage(playerid, -1, "You must be logged in to do this.");
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;
}
gettime();
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. |
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; }
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; } |