Aligned Random Messages ( without Newtimer )

Started by Inferno, Nov 19, 2020, 03:57 AM

Previous topic - Next topic

Inferno

Features

Quote• Shows random messages after every 60 seconds without using a timer.
• Will show different message every minute.
• Message #1 will be repeated once it reaches last recorded message i.e Message #10. And so on.
• This snippet doesn't require Random(min,max) function.









OnScriptLoad
MSGTick <- 0;
tCount <- 0;


OnTimeChange
if(MSGTick < 61) { //check to increase
MSGTick++; // INCREASES EVERY SECOND
}
else if(MSGTick > 59) {  // checks when 1min passes
MSGTick = 0;
tCount ++;
local m1 = "[#ffff00]Add the server to favourites", m2 = "please read /rules",  m3 = "[#FFFFFF]Server made by : YOURNAME";  // You can edit these and add even more messages here make sure to tCount = 0; on last msg.
if(tCount == 1) {
 Message(" "+m1+" ");
}
else if(tCount == 2) {
 Message(" "+m2+" ");
}
else if(tCount == 3) { // 3rd and last msg
 Message(" "+m3+" ");
tCount = 1; // to return to message #1


}
Viva la VU
VFS Developer
VCCNR Administrator

NicusorN5

Wait, is there a function called onTimeChange in VC:MP? Damn me, I never knew.

Inferno

Quote from: Athanatos on Nov 21, 2020, 10:31 AMWait, is there a function called onTimeChange in VC:MP? Damn me, I never knew.

Yeah. Its like OnTimeChange(newHr, oldHr, newMin, oldMin) .
Viva la VU
VFS Developer
VCCNR Administrator

NicusorN5

Quote from: Inferno on Nov 21, 2020, 11:22 AM
Quote from: Athanatos on Nov 21, 2020, 10:31 AMWait, is there a function called onTimeChange in VC:MP? Damn me, I never knew.

Yeah. Its like OnTimeChange(newHr, oldHr, newMin, oldMin) .
Never saw it in the VC:MP's documentation.

Inferno

Same. Until a friend used it for playtime system.
Viva la VU
VFS Developer
VCCNR Administrator

Sebastian

In such cases,  it's good to tell us so we can fix the wiki,  if it is the case.

Inferno

Official wiki was down and i was using Thijn's one until the adtec one came.


There are many event functions which i recently came across


This OnTimeChange
And OnPlayerModuleList.
Viva la VU
VFS Developer
VCCNR Administrator

KX

but why OnTimeChange when we can use a timer? I guess doing same thing with a timer is same unless you hate "newtimer" word :P

SHy^

Quote from: KX on Nov 23, 2020, 01:46 AMbut why OnTimeChange when we can use a timer? I guess doing same thing with a timer is same unless you hate "newtimer" word :P
Perhaps, he posted a example to let others know how the function can be useful like timer..

Inferno

Quote from: KX on Nov 23, 2020, 01:46 AMbut why OnTimeChange when we can use a timer? I guess doing same thing with a timer is same unless you hate "newtimer" word :P

Having a tick function is more effecient in some cases over newTimer.

I had been using a bankcamp timer using NewTimer, and it used to kick me out of bank even when i left bank before 60s and enter at like 58 or 59s.
Since on Linus servers, its not preferred to kill timers.

Also as Shy mentioned above. Its just an example of How this can be as useful as NewTimer.

You can basically use this for any Continuous 1s interval timer. Or even others.
Viva la VU
VFS Developer
VCCNR Administrator

NicusorN5

Having a tick function IS ALWAYS better than timers. Timers are responsible for crashes and memory leaks. And that's a known fact.

Inferno

Quote from: Athanatos on Nov 23, 2020, 06:54 AMHaving a tick function IS ALWAYS better than timers. Timers are responsible for crashes and memory leaks. And that's a known fact.
Exactly, also it can be manually stopped/start using variables unlike timers which even can memory leaks upon starting/stopping.
Viva la VU
VFS Developer
VCCNR Administrator

Sebastian

Quote from: Inferno on Nov 21, 2020, 11:17 PMOfficial wiki was down and i was using Thijn's one until the adtec one came.


There are many event functions which i recently came across


This OnTimeChange
And OnPlayerModuleList.

Fixed.

DizzasTeR

#13
Everyone gangsta until I tell you that onTimeChange is the same thing as Timers except that it may even be SLOWER in official squirrel plugin since the internals of the plugin uses onServerFrame (An unexposed event) which checks for game time change EVERY TICK and triggers onTimeChange when last value doesn't match new one.

Whereas Timer's are also processed at each FRAME but don't go through the checks of:-
1) Process TIMERS
2) Last game time (onTimeChange)

Whereas timer only checks for:
1) Process Timer

https://i.imgur.com/LUcrUoe.png

Inferno

So would it cause more memory leaks than actual NewTimer?
Viva la VU
VFS Developer
VCCNR Administrator