Squirrel/Functions/Timers/NewTimer
From Liberty Unleashed Wiki
(Difference between revisions)
(→Example2) |
|||
(7 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | + | {{Squirrel/Title|NewTimer}} | |
− | This creates a new timer | + | This function creates a new timer. |
== Syntax == | == Syntax == | ||
− | <code> | + | <code>Timer NewTimer( string function, int interval, int repeat, args... )</code> |
== Arguments == | == Arguments == | ||
− | * '''function''' This is the function the timer will call | + | * '''function''' - This is the function the timer will call |
− | * '''interval''' The interval the timer will fire at in milliseconds | + | * '''interval''' - The interval the timer will fire at in milliseconds |
− | * '''repeat''' How many times the function will repeat (0 is infinate) | + | * '''repeat''' - How many times the function will repeat (0 is infinate) |
− | * '''args''' Any arguments you want to pass to the function when called | + | * '''args''' - Any arguments you want to pass to the function when called |
− | == | + | == Example1 == |
This will start a timer saying ''BOO!'' 3 times every 5 seconds when a player joins | This will start a timer saying ''BOO!'' 3 times every 5 seconds when a player joins | ||
<code lang="squirrel"> | <code lang="squirrel"> | ||
− | function | + | function onPlayerJoin( player ) |
{ | { | ||
− | NewTimer( "MessagePlayer", 5000, 3, "BOO!", | + | NewTimer( "MessagePlayer", 5000, 3, "BOO!", player ); |
+ | } | ||
+ | </code> | ||
+ | |||
+ | == Example2 == | ||
+ | |||
+ | This will start a timer Giving The Player 2000$ 1 time when a player joins After 5 Sec. | ||
+ | |||
+ | <code lang="squirrel"> | ||
+ | function onPlayerJoin( player ) | ||
+ | { | ||
+ | NewTimer( "Cash", 5000, 1, player ); | ||
+ | } | ||
+ | |||
+ | function Cash( player ) | ||
+ | { | ||
+ | player.Cash += 2000; | ||
} | } | ||
</code> | </code> | ||
Line 26: | Line 42: | ||
=== Notes === | === Notes === | ||
− | The function [[Squirrel/Functions/ | + | The function [[Squirrel/Server/Functions/Messages/MessagePlayer|MessagePlayer]] and call [[Squirrel/Server/Events/Player/onPlayerJoin|onPlayerJoin]] were used in in this example. More info about them in corresponding pages. |
== Related Functions == | == Related Functions == | ||
{{Squirrel/Functions/Timers}} | {{Squirrel/Functions/Timers}} |
Latest revision as of 14:17, 10 August 2013
This function creates a new timer.
[edit] Syntax
Timer NewTimer( string function, int interval, int repeat, args... )
[edit] Arguments
- function - This is the function the timer will call
- interval - The interval the timer will fire at in milliseconds
- repeat - How many times the function will repeat (0 is infinate)
- args - Any arguments you want to pass to the function when called
[edit] Example1
This will start a timer saying BOO! 3 times every 5 seconds when a player joins
function onPlayerJoin( player ) { NewTimer( "MessagePlayer", 5000, 3, "BOO!", player ); }
[edit] Example2
This will start a timer Giving The Player 2000$ 1 time when a player joins After 5 Sec.
function onPlayerJoin( player ) { NewTimer( "Cash", 5000, 1, player ); } function Cash( player ) { player.Cash += 2000; }
[edit] Notes
The function MessagePlayer and call onPlayerJoin were used in in this example. More info about them in corresponding pages.
[edit] Related Functions
- NewTimer
- Timer.Delete
- Timer.Start
- Timer.Stop