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
addhookCategories
Parameters
- "hook"
- "func"
- [prio] (optional)
Info
Attaches the Lua function "func" to the hook "hook". CS2D will always call that Lua function when the event related to that hook occurs.
You can add an unlimited amount of different functions to each hook - but bear in mind that this might affect the performance in a negative way. Especially for hooks which are called frequently.
Click here for a list of all available hooks
Hook Parameters
CS2D passes parameters to most hooked Lua functions. These parameters contain information about the event that occurred and triggered the hook. If you want to use these parameters you have to define them in the function you add to the hook. Otherwise they won't be available in your script. You only have to add the parameters you actually use but they have to be in the same order as defined in the hook. So if you only need the last one you also have to define all other ones.
Hook Return Value
Some of the hook-functions can also have a return value. This return value influences the way CS2D reacts. Returning nothing is equal to returning 0, "" or nil.
When returning nothing CS2D will react in the normal way - as if no Lua script was executed.
In many cases you can skip the action in CS2D by returning 1 (return 1) in a hooked Lua function.
Read the description of the hook you want to use to learn more about possible return values.
Hook Priority (Optional)
Priority is only relevant if there is more than one function attached to the same hook.- Default priority is 0
- higher numbers = higher priority
- lower numbers (negative is allowed too) = lower priority
The attached function with the HIGHEST priority is the function which will be executed LAST. CS2D will take the return value of this last function (if there is any) only. All other return values will be ignored. This is because CS2D can only react in ONE way at a time and therefore it can only process ONE return value even though there are multiple hooked functions.
In most cases you will just omit the priority parameter (it is [optional]).
Example: Show a custom message if a player says something. Return 1 suppresses the normal chat output.
addhook("say","mySayFunc")
function mySayFunc(playerId,chatMessage)
msg(player(playerId,"name").." just said "..chatMessage)
return 1
end
Attention: The "hook" and the "func" parameters must be strings! Do not forget the " or ' around them!
Please only use the plain hook and function names. Do not add any function parameters or anything else in the addhook-call.
RIGHT: addhook("leave","myleavehook")
WRONG: addhook("leave(id,reason)","myleavehook(id,reason)")
WRONG: addhook(leave,myleavehook)
Attention: "func" can be either a simple function in the Lua main table (aka a global function) e.g. "helloWorld" or a function nested in a table e.g. "foo.bar" or even multiple tables e.g. "this.is.nested". Table accessors like [] are NOT supported here. So instead of "foo['bar']" you have to write "foo.bar".
Categories
Parameters
- "hook"
- "func"
- [prio] (optional)
Info
Attaches the Lua function "func" to the hook "hook". CS2D will always call that Lua function when the event related to that hook occurs.
You can add an unlimited amount of different functions to each hook - but bear in mind that this might affect the performance in a negative way. Especially for hooks which are called frequently.
Click here for a list of all available hooks
Hook Parameters
CS2D passes parameters to most hooked Lua functions. These parameters contain information about the event that occurred and triggered the hook. If you want to use these parameters you have to define them in the function you add to the hook. Otherwise they won't be available in your script. You only have to add the parameters you actually use but they have to be in the same order as defined in the hook. So if you only need the last one you also have to define all other ones.
Hook Return Value
Some of the hook-functions can also have a return value. This return value influences the way CS2D reacts. Returning nothing is equal to returning 0, "" or nil.
When returning nothing CS2D will react in the normal way - as if no Lua script was executed.
In many cases you can skip the action in CS2D by returning 1 (return 1) in a hooked Lua function.
Read the description of the hook you want to use to learn more about possible return values.
Hook Priority (Optional)
Priority is only relevant if there is more than one function attached to the same hook.
In most cases you will just omit the priority parameter (it is [optional]).
Example: Show a custom message if a player says something. Return 1 suppresses the normal chat output.
You can add an unlimited amount of different functions to each hook - but bear in mind that this might affect the performance in a negative way. Especially for hooks which are called frequently.
Click here for a list of all available hooks
Hook Parameters
CS2D passes parameters to most hooked Lua functions. These parameters contain information about the event that occurred and triggered the hook. If you want to use these parameters you have to define them in the function you add to the hook. Otherwise they won't be available in your script. You only have to add the parameters you actually use but they have to be in the same order as defined in the hook. So if you only need the last one you also have to define all other ones.
Hook Return Value
Some of the hook-functions can also have a return value. This return value influences the way CS2D reacts. Returning nothing is equal to returning 0, "" or nil.
When returning nothing CS2D will react in the normal way - as if no Lua script was executed.
In many cases you can skip the action in CS2D by returning 1 (return 1) in a hooked Lua function.
Read the description of the hook you want to use to learn more about possible return values.
Hook Priority (Optional)
Priority is only relevant if there is more than one function attached to the same hook.
- Default priority is 0
- higher numbers = higher priority
- lower numbers (negative is allowed too) = lower priority
In most cases you will just omit the priority parameter (it is [optional]).
Example: Show a custom message if a player says something. Return 1 suppresses the normal chat output.
addhook("say","mySayFunc")
function mySayFunc(playerId,chatMessage)
msg(player(playerId,"name").." just said "..chatMessage)
return 1
end
function mySayFunc(playerId,chatMessage)
msg(player(playerId,"name").." just said "..chatMessage)
return 1
end
Attention: The "hook" and the "func" parameters must be strings! Do not forget the " or ' around them!
Please only use the plain hook and function names. Do not add any function parameters or anything else in the addhook-call.
RIGHT:
WRONG:
WRONG:
Please only use the plain hook and function names. Do not add any function parameters or anything else in the addhook-call.
RIGHT:
addhook("leave","myleavehook")
WRONG:
addhook("leave(id,reason)","myleavehook(id,reason)")
WRONG:
addhook(leave,myleavehook)
Attention: "func" can be either a simple function in the Lua main table (aka a global function) e.g. "helloWorld" or a function nested in a table e.g. "foo.bar" or even multiple tables e.g. "this.is.nested". Table accessors like [] are NOT supported here. So instead of "foo['bar']" you have to write "foo.bar".