Commands/Lua
Reference for console commands, Lua hooks and Lua commands in CS2D.
- Console Commands are entered in console, executed with key-binds, cfg-files or with Lua parse
- Lua Hooks execute Lua when events occur - some have a return value which can change the game behavior
- Lua Commands are used to retrieve game data or to perform actions in Lua scripts
CS2D Console Commands
Lua Hooks
Lua Commands
Category: all (86)
- addbind
- addhook
- ai_aim
- ai_attack
- ai_build
- ai_buy
- ai_debug
- ai_drop
- ai_findtarget
- ai_freeline
- ai_goto
- ai_iattack
- ai_move
- ai_radio
- ai_reload
- ai_respawn
- ai_rotate
- ai_say
- ai_sayteam
- ai_selectweapon
- ai_spray
- ai_use
- checksumfile
- checksumstring
- closehostage
- closeitems
- closeobjects
- closeplayers
- entity
- entitylist
- fow_in
- freehook
- freeimage
- freetimer
- funcs
- game
- hascloseplayers
- hostage
- image
- imagealpha
- imageblend
- imagecolor
- imageframe
- imagehitzone
- imageparam
- imagepos
- imagescale
- inentityzone
- item
- itemtype
- map
- menu
- msg
- msg2
- object
- objectat
- objecttype
- parse
- player
- playerammo
- playerweapons
- projectile
- projectilelist
- randomentity
- randomhostage
- removeallbinds
- removebind
- reqcld
- reqhttp
- setentityaistate
- sethookstate
- stats
- steamstats
- tile
- tileproperty
- timer
- tween_alpha
- tween_animate
- tween_color
- tween_frame
- tween_move
- tween_rotate
- tween_rotateconstantly
- tween_scale
- vars
timerCategories
Parameters
- time
- "function"
- ["parameter"] (optional)
- [count] (optional)
Info
Creates a timer which will call the Lua function "function" after a certain time in milliseconds (time). Moreover it can pass an optional string parameter ("parameter") to this function. The timer calls the function once by default. However you can call it several times by entering the optional count parameter (count). Using 0 or negative count values will make the timer call the function infinite times or until it is removed via freetimer.
Note: Time is specified in ms (milliseconds, 1000 ms = 1 sec)
Note: This will throw an "attempt to call a nil value" Lua error in the console when the specified function ("function") does not exist. "function" must be a string which equals the name of an existing Lua function.
Note: CS2D is single threaded and runs with a locked maximum frame rate. This means that the FPS lock also limits the precision of timers. Be aware that - depending on the FPS - timers might be executed a few milliseconds later than specified: capped @ 60 FPS, 1000 ms / 60 FPS = 16.6 ms timer precision (in best case). This imprecision may also sum up when executing a timer more often (count<=0 or count>1).
Attention: Creating many timers with a high frequency (low time value) and a high/infinite count can slow down the game if the executed functions are complex. Use freetimer to remove unused timers!
Attention: CS2D does not check if equal timers already exist. It will just create a new timer whenever you call the timer command. This can lead to multiple exactly equal timers.
Sample 1: Executing a function once with 5 secs delay and without parameter
timer(5000,"dothislater")
function dothislater()
msg("This text is displayed 5 seconds after using timer")
end
Sample 2: Executing a function 10 times with a 1 second delay
timer(1000,"tick","",10)
function tick()
msg("*tick*")
end
Sample 3: Delayed execution with parameter
timer(3000,"delayedtext","Hi, this is displayed delayed using a timer")
function delayedtext(text)
msg(text)
end
Sample 4: Using the parse Lua function to execute CS2D commands with delay (note how ' and " are used for string encapsulation!)
timer(1000,"parse",'sv_msg "Server shutdown in 5 secs"')
timer(2000,"parse",'sv_msg "... 4 secs"')
timer(3000,"parse",'sv_msg "... 3 secs"')
timer(4000,"parse",'sv_msg "... 1 sec"')
timer(5000,"parse",'disconnect')
Categories
Parameters
- time
- "function"
- ["parameter"] (optional)
- [count] (optional)
Info
Creates a timer which will call the Lua function "function" after a certain time in milliseconds (time). Moreover it can pass an optional string parameter ("parameter") to this function. The timer calls the function once by default. However you can call it several times by entering the optional count parameter (count). Using 0 or negative count values will make the timer call the function infinite times or until it is removed via freetimer.
Sample 1: Executing a function once with 5 secs delay and without parameter
Sample 2: Executing a function 10 times with a 1 second delay
Sample 3: Delayed execution with parameter
Sample 4: Using the parse Lua function to execute CS2D commands with delay (note how ' and " are used for string encapsulation!)
Note: Time is specified in ms (milliseconds, 1000 ms = 1 sec)
Note: This will throw an "attempt to call a nil value" Lua error in the console when the specified function ("function") does not exist. "function" must be a string which equals the name of an existing Lua function.
Note: CS2D is single threaded and runs with a locked maximum frame rate. This means that the FPS lock also limits the precision of timers. Be aware that - depending on the FPS - timers might be executed a few milliseconds later than specified: capped @ 60 FPS, 1000 ms / 60 FPS = 16.6 ms timer precision (in best case). This imprecision may also sum up when executing a timer more often (count<=0 or count>1).
Attention: Creating many timers with a high frequency (low time value) and a high/infinite count can slow down the game if the executed functions are complex. Use freetimer to remove unused timers!
Attention: CS2D does not check if equal timers already exist. It will just create a new timer whenever you call the timer command. This can lead to multiple exactly equal timers.
Sample 1: Executing a function once with 5 secs delay and without parameter
timer(5000,"dothislater")
function dothislater()
msg("This text is displayed 5 seconds after using timer")
end
function dothislater()
msg("This text is displayed 5 seconds after using timer")
end
Sample 2: Executing a function 10 times with a 1 second delay
timer(1000,"tick","",10)
function tick()
msg("*tick*")
end
function tick()
msg("*tick*")
end
Sample 3: Delayed execution with parameter
timer(3000,"delayedtext","Hi, this is displayed delayed using a timer")
function delayedtext(text)
msg(text)
end
function delayedtext(text)
msg(text)
end
Sample 4: Using the parse Lua function to execute CS2D commands with delay (note how ' and " are used for string encapsulation!)
timer(1000,"parse",'sv_msg "Server shutdown in 5 secs"')
timer(2000,"parse",'sv_msg "... 4 secs"')
timer(3000,"parse",'sv_msg "... 3 secs"')
timer(4000,"parse",'sv_msg "... 1 sec"')
timer(5000,"parse",'disconnect')
timer(2000,"parse",'sv_msg "... 4 secs"')
timer(3000,"parse",'sv_msg "... 3 secs"')
timer(4000,"parse",'sv_msg "... 1 sec"')
timer(5000,"parse",'disconnect')