Holding timers in arrays [Question]

Started by Mötley, Oct 23, 2016, 03:02 PM

Previous topic - Next topic

Mötley

Is this bad practice?

I will create a demonstration of usage
//- The array
login_Timer <- array( 128 );

''When the player joins and the account exist"
login_Timer[ player.ID ] = NewTimer("NologinKick",10000, 1, player.ID )

"On player part || on login"
local timer = login_Timer[ player.ID ];
if ( timer ) timer.Delete();

Others would consider

function onPlayerJoin( player )
{
    login_Timer <- NewTimer( "example", 5000, 0, player );
}
     
function onPlayerPart( player, PartID )
{
    login_Timer.Delete();
}

But that's not attached to the player, I would believe that would be more of a server timer??

KAKAN

Quote from: Mötley on Oct 23, 2016, 03:02 PMBut that's not attached to the player, I would believe that would be more of a server timer??
The first one is way better than the second and you know why. Also, its not a bad practice. But, why have a timely kick and not change the name instead? That would be easier and will be simpler too. Anyway, the timers won't actually lag the server if you're just checking some variables( registerd or logged_in etc )
For ex: This won't lag the server:-
NewTimer("Test", 1000, 0 );
function Test(){
if( /* Check some conditions */ ){
/* Somehow get the player */
player.Kick();
}
}
But, this will lag:-
NewTimer("Test", 1000, 0 );
function Test(){
/* Do 100s of query */
if( /* Check some conditions */ ){
/* Somehow get the player */
player.Kick();
}
}
Many newbies do that and tell that the timers are the things which lag the server while actually they're not.
oh no

Mötley

Quote from: KAKAN on Oct 23, 2016, 04:31 PM
Quote from: Mötley on Oct 23, 2016, 03:02 PMBut that's not attached to the player, I would believe that would be more of a server timer??
The first one is way better than the second and you know why. Also, its not a bad practice. But, why have a timely kick and not change the name instead? That would be easier and will be simpler too. Anyway, the timers won't actually lag the server if you're just checking some variables( registerd or logged_in etc )
For ex: This won't lag the server:-
NewTimer("Test", 1000, 0 );
function Test(){
if( /* Check some conditions */ ){
/* Somehow get the player */
player.Kick();
}
}
But, this will lag:-
NewTimer("Test", 1000, 0 );
function Test(){
/* Do 100s of query */
if( /* Check some conditions */ ){
/* Somehow get the player */
player.Kick();
}
}
Many newbies do that and tell that the timers are the things which lag the server while actually they're not.

Well honestly... I have no loop method right now, None, I plan to attach the login timer kick to my entire loop method.

The loop method will consist of a 5 min timer. that loop method will get converted into a seconds to minute, for server uptime to maybe :: Maybe mute timers, to time allowed to spawn another vehicle "Then remove that vehicle".

On future scripting I plan to do this, is that terrible?

On login I would do something like

if (logged[ player.ID ] == true) logged[player.ID]--;
But massive amounts of scripting In one timer/loop method I am afraid that will lag the server as well.

I will admit I am not the greatest at all, But I really try to succeed

KAKAN

you can use time() or clock() for many of your work.
For server uptime too, you can use 'em. Ex: http://forum.vc-mp.org/?topic=1523.0
For mute:-
Mute[ player.ID ] = time(); //The time when the player was muted.
if( Mute[ player.ID ] < time() ) //Allow the player to chat.
if( Mute[ player.ID ] > time() ) //Don't allow to chat.
oh no

Mötley

Neat Idea, But in the mute command I would like to manually set the minutes on the mute, Default maybe 10 minutes,

But I might use a similar method instead

.

Quote from: Mötley on Oct 23, 2016, 03:02 PM//- The array
login_Timer <- array( 128 );

''When the player joins and the account exist"
login_Timer[ player.ID ] = NewTimer("NologinKick",10000, 1, player.ID )

"On player part || on login"
local timer = login_Timer[ player.ID ];
if ( timer ) timer.Delete();

This sh!t will start to get even sh!ttier the moment you realize the official squirrel plugin is limited to about 255 timers. And seeing how ya'll love timers so much that you can't do sh!t without them. I'd suggest you being more conservative of them. But then again, who gives a sh!t.
.

Mötley

^

Already basically said that. That was only a question and example., I do plan to be conservative ;)

http://forum.vc-mp.org/?topic=3843.msg28692#msg28692

.

#7
Also, why was that array created with 128 elements when VCMP supports a maximum of 100 players?

And don't claim it was for the sake of example. I know you people are lacking some of the knowledge and the desire to acquire it which makes you a bit insecure and therefore a bit generous with your values in the hopes of removing all doubts. So you can't throw that bs around me.

Or maybe you like power of 2 numbers so much that being wastefull is less of a worry than using non power of 2 numbers :D
.

Mötley

Come on dude I am in the middle of a build and I wanted to create something interesting for the server, Therefore I created a whatever script for testing, During testing I thought it would be simpler to just use an array for 128 players "I'm not even close to portforwarding to know this", as i haven't created a loop method in my server yet, Reading thoroughly at one of my post you would of noticed this instead of looking for something to talk down on someone for, I was looking forward to hearing something interesting and really smart from you when I noticed you replied, Not a smart a#$ rant.



Either way you are off topic and if I really got technical with that play around function I would of just ran
login_Timer <- array(GetMaxPlayers(), 0);
But the server is not going to even be operated on arrays. As there will be a class,

With a nice loop that will be down converted for minutes and seconds, One timer, A loop for minutes and down convert that loop to operate into seconds.
Was all of this necessary,..

Quote from: Mötley on Oct 23, 2016, 04:58 PMWell honestly... I have no loop method right now, None, I plan to attach the login timer kick to my entire loop method.

The loop method will consist of a 5 min timer. that loop method will get converted into a seconds to minute, for server uptime to maybe :: Maybe mute timers, to time allowed to spawn another vehicle "Then remove that vehicle".

On future scripting I plan to do this, is that terrible?

On login I would do something like

if (logged[ player.ID ] == true) login_Timers[player.ID]--; //Was supposed to be this

But massive amounts of scripting In one timer/loop method I am afraid that will lag the server as well.

I will admit I am not the greatest at all, But I really try to succeed

KAKAN

Quote from: Mötley on Oct 23, 2016, 05:18 PMNeat Idea, But in the mute command I would like to manually set the minutes on the mute, Default maybe 10 minutes,

But I might use a similar method instead
Then just do something like:-
Mute[ player.ID ] = time() + ( 60*10 );Replace 10 with the minutes you want.
oh no