How To Script.. - 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: How To Script.. (
/showthread.php?tid=651555)
How To Script.. -
xRadical3 - 22.03.2018
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?
Re: How To Script.. -
PowerMwK - 22.03.2018
use settimer
https://sampwiki.blast.hk/wiki/SetTimer
If need I make a base.
Re: How To Script.. -
Logic_ - 22.03.2018
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.
Re: How To Script.. -
Maxandmov - 22.03.2018
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.
Re: How To Script.. -
Logic_ - 22.03.2018
I do this under OnGameModeInit:
PHP код:
new minutes;
gettime(gHour, minutes);
minutes = 60 - minutes;
SetTimer("ClockTimer", (minutes * 60000) + 5000, false);
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(string, sizeof string, "The time is now %d:00.", gHour);
SendClientMessageToAll(COLOR_GREY, string);
SetTimer("ClockTimer", 3600000, true); // 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.
Re: How To Script.. -
xRadical3 - 22.03.2018
Thanks