gettime not working - 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: gettime not working (
/showthread.php?tid=596796)
gettime not working -
DetoNater - 22.12.2015
Actually my aim is to script for Happy hour(were a score is a bit extra, in my server) and i want it to work it only for 2 hours, that is from 18h to 20h so here's my code!
P.S I dont get any compile errors, but have i placed it in wrong place??
pawn Код:
public OnPlayerUpdate(playerid)
{
if(happyhour[playerid] == 0)
{
happyhour[playerid] = 0;
}
//Happy Hour
new hours,minutes,seconds;
gettime(hours, minutes, seconds);
if(hours > 18)
{
happyhour[playerid] = 1;
}
if(hours < 20)
{
happyhour[playerid] = 0;
}
is there any problem in mine??
Re: gettime not working -
Mencent - 22.12.2015
Hello!
You can test it and see if you have some mistakes, but I would write it like this:
PHP код:
public OnPlayerUpdate(playerid)
{
new hours,minutes,seconds;
gettime(hours,minutes,seconds);
if(hours >= 18 && hours <= 20)
{
happyhour[playerid] = 1;
}
else happyhour[playerid] = 0;
return 1;
}
Re: gettime not working -
PrO.GameR - 22.12.2015
Yes there is, you simply shouldn't use OPU for this simple thing
Make a check that triggers in Gamemodeinit, check the hour, set a timer accordingly which sets happy hour for everyone in a loop, thats the most optimized way to do it I guess.
Re: gettime not working -
TwinkiDaBoss - 22.12.2015
PHP код:
SetTimerEx("CheckHappyHour", 60000, true, "i", playerid); //OnPlayerLogin, 60 seconds is enough.
forward CheckHappyHour(playerid);
public CheckHappyHour(playerid)
{
new hours,minutes,seconds;
gettime(hours,minutes,seconds);
if(hours >= 18 && hours <= 20)
{
happyhour[playerid] = 1;
}
else happyhour[playerid] = 0;
return 1;
}
Re: gettime not working -
DetoNater - 23.12.2015
thank y'all it help, +rep for all!