04.06.2007, 00:35
And I made an exaple of using it. It just draws to all players time how long you are running your server.
So lets start with global variables and forward...:
In OnGameModeInit we need to add the timer which calls TimeServerRunning which draws the time:
And the function that timer calls:
TimeConvert() function - converts time (seconds) into string. e.g.: 92 -> "1:32"
I hope it will give some idea how it works. It is not as difficult as it looks like.
So lets start with global variables and forward...:
pawn Code:
new gSeconds = 0; // counts how many seconds server is running
new Text: gText; // global "Text"
forward TimeServerRunning();
pawn Code:
SetTimer("TimeServerRunning", 1000, true); // call function every second
pawn Code:
public TimeServerRunning() {
new string[16];
TextDrawDestroy(gText);
gSeconds++;
format(string, sizeof string, "%s", TimeConvert(gSeconds));
text1 = TextDrawCreate(10.0, 100.0, string);
TextDrawUseBox(gText, true);
TextDrawTextSize(gText, 50.0, 20.0);
TextDrawShowForAll(gText);
}
pawn Code:
TimeConvert(time) {
new minutes;
new seconds;
new string[256];
if(time > 59){
minutes = floatround(time/60);
seconds = floatround(time - minutes*60);
if(seconds>9)format(string,sizeof(string),"%d:%d",minutes,seconds);
else format(string,sizeof(string),"%d:0%d",minutes,seconds);
}
else{
seconds = floatround(time);
if(seconds>9)format(string,sizeof(string),"0:%d",seconds);
else format(string,sizeof(string),"0:0%d",seconds);
}
return string;
}
I hope it will give some idea how it works. It is not as difficult as it looks like.