Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Cena on Apr 08, 2016, 02:29 PM

Title: NewTimer
Post by: Cena on Apr 08, 2016, 02:29 PM
can someone tell me how to use pstats[ plr.ID ].test in NewTimer. Thanx
Title: Re: NewTimer
Post by: Xmair on Apr 08, 2016, 02:56 PM
What?
Title: Re: NewTimer
Post by: Cena on Apr 08, 2016, 03:04 PM
Like
 NewTimer("pstats[ player ].Mute", 1000, 1 "true");
 NewTimer("pstats[ player ].Mute", 5000, 1 "false");
Title: Re: NewTimer
Post by: ysc3839 on Apr 08, 2016, 03:10 PM
I think NewTimer(function(){pstats[ player ].Mute=true}, 1000, 1); would be better.
Title: Re: NewTimer
Post by: Cena on Apr 08, 2016, 03:19 PM
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FT8PFcZZ.png&hash=f206eefbf37f55b92de05fb4492a46a42a311cbe)

using this

NewTimer(function(){pstats[ plr ].Mute}, 1000, 1 "true");
NewTimer(function(){pstats[ plr ].Mute}, 10000, 1 "true");
Title: Re: NewTimer
Post by: KAKAN on Apr 08, 2016, 03:49 PM
You're too good to do it.
You can't pass instance.
Use this:
NewTimer( @( bool, plrID ){ pstats[ plrID ].Mute = bool; }, 1000, true );
Title: Re: NewTimer
Post by: . on Apr 08, 2016, 05:03 PM
@KAKAN Yes you can pass instances (http://forum.vc-mp.org/?topic=1487.0) if you know to implement it.

@ysc3839 You'd want to take the player instance as a argument because the index 'player' is not captured from the context of the parent function.
Title: Re: NewTimer
Post by: KAKAN on Apr 08, 2016, 05:28 PM
Quote from: S.L.C on Apr 08, 2016, 05:03 PM@KAKAN Yes you can pass instances (http://forum.vc-mp.org/?topic=1487.0) if you know to implement it.
Probably the newbies won't get your snip. So, it's better for 'em to use the NewTimer function.
And also, do you think that @Cena would be able to understand your snippet?
Title: Re: NewTimer
Post by: . on Apr 08, 2016, 05:34 PM
Quote from: KAKAN on Apr 08, 2016, 05:28 PM
Quote from: S.L.C on Apr 08, 2016, 05:03 PM@KAKAN Yes you can pass instances (http://forum.vc-mp.org/?topic=1487.0) if you know to implement it.
Probably the newbies won't get your snip. So, it's better for 'em to use the NewTimer function.
And also, do you think that @Cena would be able to understand your snippet?

But it works just like the example you gave. Except if he tries that on the default NewTimer it won't work because it expects a string and not a function object. Did you just forgot what you recommended?

Quote from: KAKAN on Apr 08, 2016, 03:49 PMYou're too good to do it.
You can't pass instance.
Use this:
NewTimer( @( bool, plrID ){ pstats[ plrID ].Mute = bool; }, 1000, true );

How complicated is this compared to what you recommended? Except this one actually works.
_Timer.Create( @( bool, plrID ) (pstats[ plrID ].Mute = bool), 1000, 1, true, player.ID );
For example... You included {} curly braces in a lambda. You specified a function object as the name of the function. You forgot to specify the number of times the timer should execute. You forgot to add the player ID to the timer parameters/arguments.

And also something I've omitted for the sake of simplicity is to check if that player still exists after 1000ms. Because he could easily disconnect during that time and then you'd modify a player that doesn't exist. Thus... cause an error.