Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: Inferno on Nov 19, 2020, 03:57 AM

Title: Aligned Random Messages ( without Newtimer )
Post by: Inferno on Nov 19, 2020, 03:57 AM
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


}
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: NicusorN5 on Nov 21, 2020, 10:31 AM
Wait, is there a function called onTimeChange in VC:MP? Damn me, I never knew.
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: 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) .
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: NicusorN5 on Nov 21, 2020, 04:17 PM
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.
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: Inferno on Nov 21, 2020, 07:08 PM
Same. Until a friend used it for playtime system.
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: Sebastian on Nov 21, 2020, 09:02 PM
In such cases,  it's good to tell us so we can fix the wiki,  if it is the case.
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: Inferno on Nov 21, 2020, 11:17 PM
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.
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: KX on Nov 23, 2020, 01:46 AM
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
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: SHy^ on Nov 23, 2020, 03:25 AM
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..
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: Inferno on Nov 23, 2020, 04:53 AM
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.
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: NicusorN5 on Nov 23, 2020, 06:54 AM
Having a tick function IS ALWAYS better than timers. Timers are responsible for crashes and memory leaks. And that's a known fact.
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: Inferno on Nov 23, 2020, 07:21 AM
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.
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: Sebastian on Nov 23, 2020, 09:22 AM
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.
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: DizzasTeR on Nov 23, 2020, 12:06 PM
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
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: Inferno on Nov 23, 2020, 01:04 PM
So would it cause more memory leaks than actual NewTimer?
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: DizzasTeR on Nov 23, 2020, 01:26 PM
Quote from: Inferno on Nov 23, 2020, 01:04 PMSo would it cause more memory leaks than actual NewTimer?

No
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: NicusorN5 on Nov 24, 2020, 09:14 AM
But atleast it would be a workaround for the generic Timer crashes in VC:MP, right?
Title: Re: Aligned Random Messages ( without Newtimer )
Post by: Xmair on Nov 24, 2020, 09:53 AM
Quote from: Athanatos on Nov 24, 2020, 09:14 AMBut atleast it would be a workaround for the generic Timer crashes in VC:MP, right?
Yes but it's one of the worst workarounds you can think of. As the onTimeChange is dependent on the server's time rate, if you change the time rate, your whole server will be messed up.