Help with my Clock code please [Not Realtime] - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help with my Clock code please [Not Realtime] (
/showthread.php?tid=206547)
Help with my Clock code please [Not Realtime] -
<Weponz> - 04.01.2011
Ok so this code is simple as we all know thanks to the function
But im not sure how i should do it to make it more efficient.
This is what i have so far,Can someone with experience tell me if the way im doing it is correct and will it work and if possible show me how to make it more efficient and faster please.
What i want exactly is the clock to change like In-Game every min is 1 in-game hour and announce the time in main chat and change it using SetWorldTime.
Heres my code:
pawn Код:
//Clock Test
#include <a_samp>
new GameHour;
forward timechange();
public OnGameModeInit()
{
SetWorldTime(12);
GameHour = 12;
SetTimer("timechange",60000,true);
}
public timechange()
{
if(GameHour == 1)
{
SendClientMessageToAll(0x0,"[Time]: 1.00 am");
}
else if(GameHour == 2)
{
SendClientMessageToAll(0x0,"[Time]: 2.00 am");
}
else if(GameHour == 3)
{
SendClientMessageToAll(0x0,"[Time]: 3.00 am");
}
else if(GameHour == 4)
{
SendClientMessageToAll(0x0,"[Time]: 4.00 am");
}
else if(GameHour == 5)
{
SendClientMessageToAll(0x0,"[Time]: 5.00 am");
}
else if(GameHour == 6)
{
SendClientMessageToAll(0x0,"[Time]: 6.00 am");
}
else if(GameHour == 7)
{
SendClientMessageToAll(0x0,"[Time]: 7.00 am");
}
else if(GameHour == 8)
{
SendClientMessageToAll(0x0,"[Time]: 8.00 am");
}
else if(GameHour == 9)
{
SendClientMessageToAll(0x0,"[Time]: 9.00 am");
}
else if(GameHour == 10)
{
SendClientMessageToAll(0x0,"[Time]: 10.00 am");
}
else if(GameHour == 11)
{
SendClientMessageToAll(0x0,"[Time]: 11.00 am");
}
else if(GameHour == 12)
{
SendClientMessageToAll(0x0,"[Time]: 12.00 pm");
}
else if(GameHour == 13)
{
SendClientMessageToAll(0x0,"[Time]: 1.00 pm");
}
else if(GameHour == 14)
{
SendClientMessageToAll(0x0,"[Time]: 2.00 pm");
}
else if(GameHour == 15)
{
SendClientMessageToAll(0x0,"[Time]: 3.00 pm");
}
else if(GameHour == 16)
{
SendClientMessageToAll(0x0,"[Time]: 4.00 pm");
}
else if(GameHour == 17)
{
SendClientMessageToAll(0x0,"[Time]: 5.00 pm");
}
else if(GameHour == 18)
{
SendClientMessageToAll(0x0,"[Time]: 6.00 pm");
}
else if(GameHour == 19)
{
SendClientMessageToAll(0x0,"[Time]: 7.00 pm");
}
else if(GameHour == 20)
{
SendClientMessageToAll(0x0,"[Time]: 8.00 pm");
}
else if(GameHour == 21)
{
SendClientMessageToAll(0x0,"[Time]: 9.00 pm");
}
else if(GameHour == 22)
{
SendClientMessageToAll(0x0,"[Time]: 10.00 pm");
}
else if(GameHour == 23)
{
SendClientMessageToAll(0x0,"[Time]: 11.00 pm");
}
else if(GameHour == 24)
{
SendClientMessageToAll(0x0,"[Time]: 12.00 am");
}
}
//While the server is running and its cycling the time will people join at w/e time its upto or will it set it to 12?
Thanks in advanced!
Re: Help with my Clock code please [Not Realtime] -
Kwarde - 04.01.2011
So you want the time to change?
Whatever try this:
When the "timechange" is gonna be called, do GameHour + 1. (Use "GameHour += 1" or "GameHour++")
When it's above 24, set it to 0. And no needed to use all the 'if' statements (and the else if's)
pawn Код:
public timechange()
{
new str[128]; //To format the message
GameHour++; //Gamehour + 1
if(GameHour > 24) GameHour = 0; //Is the hour 25 (or above)? Set it to 0
SetWorldTime(GameHour); //Change the server's time
format(str, 128, "Gametime: %02d.00", GameHour); //Format the message: GAMEHOUR.00 (so it will be '07.00'. when gamehour = 7. It's %02d (02) so it use 2 integers. 7 = 07, not 7
SendClientMessageToAll(0xFFFFFFAA, str); //Send white message to everyone
return 1;
}
Re: Help with my Clock code please [Not Realtime] -
<Weponz> - 04.01.2011
nice thanks alot man..just to get it clear i just run a 60 sec timer for timechange then it will change 1 hour every min correct?
Re: Help with my Clock code please [Not Realtime] -
Kwarde - 04.01.2011
Yes that's correct, IF it works.