10.08.2012, 03:47
(
Last edited by RedFusion; 25/08/2012 at 01:43 AM.
)
Global Time
Hey! This is my second tutorial.
This time it's about making a simple clock,
i saw a guy who had problems with it, and i guess others have too / will have at some point.
This is how it looks.
upload photo
This is in the top of the script.
Hour is for the amount of hours passed, obviously. (Real world Minutes)
Minute is the amount of minutes passed ingame (Real world Seconds)
timetext is the clock textdraw.
Ztimer is the ID for the timer, incase you want to kill the timer you need to assign an ID to it.
-----
When the script starts it sets Hours to 12 and Minutes to 00. So the time is now 12:00.
Ztimer = SetTimer This starts the timer, assigns it to "Ztimer" and sets it to repeat, 1 time each second.
The rest is the textdraw itself (the clock).
And last is the console printmessage.
-----
If you decide to unload the time FS this will destroy the textdraw, and kill the timer. (Ztimer)
-----
This is what the script will perform 1 time each second.
First of it adds 1 minute each second.
-----
Then it checks if the amount of Minutes is 60 and hours are less than 24.
(If the hours are 24, it goes to the next line)
If this is correct, it adds an hour, and sets minutes to 0.
-----
If hours is equal to 24 and minutes 00 It resets them both to 00. (New day)
-----
(Thanks to vince)
This line formats a string, the string to be shown to the players.
It adds a 0 infront of Minutes Or hours; If any or both of them are less than 10 (2 characters)
Otherwise it will look like "2:54" instead of "02:54".
Example: 20:43
-----
This sets the textdraw to show the formated string shown above.
And then Show the clock for all.
-----
This sets every player's time to the server time. (It's a loop) It sets the playertime to the Hours and Minutes shown on the clock.
I know most of you probably dont need a tutorial for this, but some do
FzTime.amx
FzTime.pwn
Good luck// Fusez
Hey! This is my second tutorial.
This time it's about making a simple clock,
i saw a guy who had problems with it, and i guess others have too / will have at some point.
This is how it looks.
upload photo
pawn Code:
#include <a_samp>
new Hour, Minute, timestring[6];//The time converted into a string for the textdraw.
new Text:timetext;//The textdraw
new Ztimer;//Timer ID.
Hour is for the amount of hours passed, obviously. (Real world Minutes)
Minute is the amount of minutes passed ingame (Real world Seconds)
timetext is the clock textdraw.
Ztimer is the ID for the timer, incase you want to kill the timer you need to assign an ID to it.
-----
pawn Code:
public OnFilterScriptInit()
{
Hour = 12;
Minute = 00;
Ztimer = SetTimer("timeupdate",1000,true);
////////////////////////////////////////////////////////////////////////////////
timetext = TextDrawCreate(547.000000, 23.000000, "00:00");
TextDrawBackgroundColor(timetext, 255);
TextDrawFont(timetext, 3);
TextDrawLetterSize(timetext, 0.599999, 2.100000);
TextDrawColor(timetext, -1);
TextDrawSetOutline(timetext, 1);
TextDrawSetProportional(timetext, 1);
////////////////////////////////////////////////////////////////////////////////
print("\n--------------------------------------");
print(" FzTime by Fusez successfully loaded!");
print(" Time (1 real minute = 1 second ingame)");
print("--------------------------------------\n");
return 1;
}
Ztimer = SetTimer This starts the timer, assigns it to "Ztimer" and sets it to repeat, 1 time each second.
The rest is the textdraw itself (the clock).
And last is the console printmessage.
-----
pawn Code:
public OnFilterScriptExit()
{
TextDrawDestroy(timetext);
KillTimer(Ztimer);
return 1;
}
-----
pawn Code:
forward timeupdate();
public timeupdate()
{
Minute += 01;
if(Minute == 60 && Hour < 24) Hour += 01, Minute = 00;
if(Hour == 24 && Minute == 00) Hour = 00, Minute = 00;
format(timestring, sizeof(timestring), "%02d:%02d", Hour, Minute);
TextDrawSetString(timetext,timestring);
TextDrawShowForAll(timetext);
for(new i = 0; i < MAX_PLAYERS; i++)
{
SetPlayerTime(i,Hour,Minute);
}
}
pawn Code:
Minute += 1;
First of it adds 1 minute each second.
-----
pawn Code:
if(Hour == 24 && Minute == 00) Hour = 00, Minute = 00;
(If the hours are 24, it goes to the next line)
If this is correct, it adds an hour, and sets minutes to 0.
-----
pawn Code:
if(Hour == 24 && Minute == 00) Hour = 00, Minute = 00;
-----
pawn Code:
format(timestring, sizeof(timestring), "%02d:%02d", Hour, Minute);
This line formats a string, the string to be shown to the players.
It adds a 0 infront of Minutes Or hours; If any or both of them are less than 10 (2 characters)
Otherwise it will look like "2:54" instead of "02:54".
Example: 20:43
-----
pawn Code:
TextDrawSetString(timetext,timestring);
TextDrawShowForAll(timetext);
And then Show the clock for all.
-----
pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)
{
SetPlayerTime(i,Hour,Minute);
}
I know most of you probably dont need a tutorial for this, but some do
FzTime.amx
FzTime.pwn
Good luck// Fusez