Gettime - 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 (
/showthread.php?tid=597798)
Gettime -
w3b - 05.01.2016
Why not go?It should go only between 20 and 22 hours. Excuse my bad english.
PHP код:
new hour,minute,second;
gettime(hour,minute,second);
if(hour < 20 && hour > 22)
{
return 1;
}
Re: Gettime -
justinnater - 05.01.2016
You are now checking if the hour is below 20 and above 22 at the same time.
Re: Gettime -
w3b - 05.01.2016
Well I want to go just that command between that range (20-22) (to go at 20, 21, 22 not in other hours) Srry my english
Re: Gettime -
justinnater - 05.01.2016
In that case you would have to use if (hour >=20 && hour <=22)
Re: Gettime -
w3b - 05.01.2016
FIX
if(hour != 20 || hour != 21 || hour != 22)
{
return 1;
}
Re: Gettime -
justinnater - 05.01.2016
I assumed you wanted to perform the actions within the check I provided.
Otherwise you only had to change && to || from your first code.
Re: Gettime -
AmigaBlizzard - 05.01.2016
You could make a switch:
pawn Код:
select hour
{
case 20, 21, 22:
{
// Your code here
}
}
If you plan to change the times later on, or add some extra hour-values, you can easily add them to that list.
Otherwise you need to extends and possibly rewrite the entire if-statement.
Perhaps you want to run that code at hour 6 and 15 later on as well, you could easily do:
pawn Код:
select hour
{
case 6, 15, 20, 21, 22:
{
// Your code here
}
}
Using "if" would make it pretty long and more complex:
pawn Код:
if (((hour >=20 && hour <=22)) || (hour == 6) || (hour == 15))
Re: Gettime -
AbyssMorgan - 05.01.2016
PHP код:
if(hour == 20 || hour == 21){
//20:00:00 - 21:59:59
}