Timer problem - 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: Timer problem (
/showthread.php?tid=590659)
I just found out - Delete this -
Mikkel_RE - 02.10.2015
Thank you for helping me out this.
Re: Timer problem -
PrO.GameR - 02.10.2015
Timers are a bit off, you need to use the
fix to use the timer, although 40% is kinda bit too much, it should be around ~20-25%
Re: Timer problem -
Mikkel_RE - 02.10.2015
But the jail timer Works fine, and its made in the same way
Delete -
Mikkel_RE - 02.10.2015
Delete this
Re: Timer problem -
Crayder - 02.10.2015
This isn't something you would want to use a timer for anyways.
Make a variable that holds the last time the player executed. Example:
pawn Код:
PlayerInfo[playerid][pLastDropTime]
When the dropcar command is executed, do this:
pawn Код:
PlayerInfo[playerid][pLastDropTime] = gettime();
Before the command is executed you can do this to prevent use within 20 minutes:
pawn Код:
if((PlayerInfo[playerid][pLastDropTime] + (20 * 60 * 1000)) < gettime())
{
// rest of command here
}
That's it! No timers needed!
Here is the full command:
pawn Код:
if(strcmp(cmd, "/dropcar", true) == 0)
{
if((PlayerInfo[playerid][pLastDropTime] + (20 * 60 * 1000)) < gettime())
{
//if(PlayerInfo[playerid][pJob] == 5)
//{
if(PlayerOnMission[playerid] > 0)
{
SendClientMessage(playerid, COLOR_GREY, " On a mission right now, can't use this command !");
return 1;
}
if((GetPlayerState(playerid)) == 3){//checks if passenger
SendClientMessage(playerid, COLOR_GREY, " Hey, this isn't your vehicle!"); // sends error
return 1;
}
GameTextForPlayer(playerid, "~w~Car Selling ~n~~r~Drop the car at the Crane", 5000, 1);
CP[playerid] = 1;
SetPlayerCheckpoint(playerid, 2506.9529,-2629.9968,13.6465,8.0);
PlayerInfo[playerid][pLastDropTime] = gettime();
//}
//else
//{
// SendClientMessage(playerid, COLOR_GREY, " You are not a Car Jacker !");
//}
}
else
{
format(string, sizeof(string), "You already sold a car, you'll have to wait %d minutes before you can sell another.", SecondsToMinutes(PlayerInfo[playerid][pLastDropTime]));
SendClientMessage(playerid, COLOR_GREY, string);
return 1;
}
return 1;
}
ALSO: You should really switch to a command processor, using OnPlayerCommandText is stupid for plenty of reasons. I removed IsPlayerConnected in the command because that is useless, a player would have to be connected to execute a command. If you don't want it removed for some weird, stupid reason you should put it at the top of OnPlayerCommandText. You should ditch OnPlayerCommandText completely anyways like I said before. Use the best of what you got, command processors such as ZCMD, YCMD, iZCMD. OnPlayerCommandText is by far the worst option.