How To Script..
#1

How to script for example at 6 o'clock and give all the Online players a message that is now 6 o'clock and gives the Online players some money?

Reply
#2

use settimer
https://sampwiki.blast.hk/wiki/SetTimer

If need I make a base.
Reply
#3

There can be multiple approaches to this:

1. (Do not try approach) Run a timer every few seconds and get the time and compare it to 6 and then give them some money.
2. (Efficient approach) On server start, get current time and minutes, do calculation and get the time when 6'o clock "will happen", set a timer with the "time" you got and tadaah!!! you made it.
Reply
#4

I'll assume you have time changes scripted somehow, because the other way it's weird.
In my script e.g. I have a timer for each second, just as Logic_ wouldn't advice as of before:
Код:
1. (Do not try approach) Run a timer every few seconds and get the time and compare it to 6 and then give them some money.
In this case, I just check for what time is it every time this function called upon a timer is done. Naturally, in this case I might want to make the timer looped.
Код:
new Hour, Minute, Second;
gettime(Hour, Minute, Second);
...
if(Hour == 6 && Minute == 0 && Second == 0) //The other way around, well... You'll get the action done every second of an hour, which means 3599 actions you didn't want to happen.
{
     //Do actions required
}
...
Your personal approach only depends on you though. What I wrote above might not be the best way in means of performance, just like Logic_ stated.
Reply
#5

I do this under OnGameModeInit:
PHP код:
    new minutes;
    
gettime(gHourminutes);
    
minutes 60 minutes;
    
SetTimer("ClockTimer", (minutes 60000) + 5000false);
    
SetWorldTime(gHour); 
So every time server restarts, it does some calculation and set's a timer when the next hour "will happen". And then I do:

PHP код:
forward ClockTimer();
public 
ClockTimer()
{
    new 
string[25];
    
gettime(gHour);
    
    
format(stringsizeof string"The time is now %d:00."gHour);
    
SendClientMessageToAll(COLOR_GREYstring);
    
    
SetTimer("ClockTimer"3600000true); // That interval = 1 hour but in milliseconds.
    
return 1;

The difference might be of 1 minute but that won't hurt.

EDIT: I've defined my variable 'gHour' on the top of the script.
Reply
#6

Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)