Counter-Strike 2D supports Lua scripts since Beta 0.1.1.4
It uses the Lua engine Version 5.1.2
Please visit the Lua homepage for a documentation
www.lua.org
Lua scripting in CS2D is based on events/hooks
Hooks work only SERVERSIDE and NOT CLIENTSIDE!
(due to security reasons)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CS2D will automatically load and execute
"sys\lua\server.lua" when hosting a server
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following hooks are available. You can create them as
Lua functions and CS2D will execute these function whenever
the corresponding action occurs.
CS2D will pass parameters to most functions. You can use
these parameters but you don't have to!
Some of the hook-functions can have a return value!
This return value influences the way how CS2D behaves.
Call updatehooks() after defining all hook-functions!
Please make sure that you define every hook function only
once. Otherwise you will overwrite existing functions.
hook_second() each second
hook_minute() each minute
hook_always() always (each frame)
hook_join(id) on join
-id: player id
hook_leave(id, reason) on leave
-id: player id
-reason: reason id (0 normal, >0 kick/ban/timeout)
hook_team(id, team, look) on teamchange
-id: player id
-team: 0 spec, 1 t, 2 ct
-look: look id 0,1,2 or 3
>return: 0 - proceed normally
1 - don't change team + close menu
hook_spawn(id) on spawn
-id: player id
hook_startround(mode) on start of round
-mode: start round mode id
hook_name(id, oldname, newname) on name change
-id: player id
-oldname: old player name
-newname: new player name
hook_mapchange(newmap) on map change
-newmap: name of new map
hook_parse(text) on parse (console/binds/rcon)
-text: text/commands to parse
>return: 0 - proceed normally
1 - normal parsing, ignore unknown cmds
2 - skip CS2D parsing
hook_buy(id, weapon) on buy
-id: player id
-weapon: type id of bough weapon
hook_collect(id,iid,type,ain,a,mode) on collect
-id: player id
-iid: item id
-type: item type
-ain: ammo in weapon / item count
-a: additional ammo
-mode: item mode
hook_drop(id,iid,type,ain,a,mode,x,y) on drop
-id: player id
-iid: item id
-type: item type
-ain: ammo in weapon / item count
-a: additional ammo
-mode: item mode
-x: drop x position
-y: drop y position
hook_select(id,type,mode) on select weapon
-id: player id
-type: item type
-mode: item mode
hook_reload(id,mode) on reload
-id: player id
-mode: reload action (1 start, 2 finish)
hook_attack(id) on attack
-id: player id
hook_attack2(id,mode) on attack2
-id: player id
-mode: weapon mode
hook_hit(id,source,weapon) on hit/damage
-id: player id
-source: source player id or 0
-weapon: weapon type / source type id
hook_kill(killer,victim,weapon,x,y) on kill
-killer: player id
-victim: player id
-weapon: weapon type id
-x: death x
-y: death y
hook_die(victim,killer,weapon,x,y) on death
-victim: player id
-killer: player id
-weapon: weapon type id
-x: death x
-y: death y
hook_use(id, event, data, x, y) on use
-id: player id
-event: use event type
-data: additonal data
-x: use x tile position
-y: use y tile position
hook_say(id, message) on say
-id: player id
-message: actual chat message
hook_sayteam(id, message) on sayteam
-id: player id
-message: actual chat message
hook_radio(id, message) on radio
-id: player id
-message: radio message type id
hook_spray(id) on spray
-id: player id
hook_vote(id,mode,param) on vote
-id: player id
-mode: vote mode (1 kick, 2 map)
-param: player id or map
hook_build(id,type,x,y,mode,objectid) on build
-id: player id
-type: building type
-x: building x
-y: building y
-mode: building mode
-objectid: id of new object
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can use all Lua functions in your CS2D Lua scripts
Moreover CS2D has the following own Lua functions:
[BASIC]
- print("text") show "text" in console
- msg("text") send "text" as server message
- msg2(id,"text") send "text" to certain player
- parse("commands") execute CS2D script commands
- vars() show all Lua variables
- funcs() show all Lua functions
- updatehooks() update all Lua-CS2D hooks
[GAME]
- game("value") Return a game state/setting
You can use ALL settings like
sv_name to get their current
value as string(!). Moreover you
can get the following values:
version, dedicated, phase,
round, score_t, score_ct,
winrow_t, winrow_ct
[PLAYER]
- player(id,"value") Return a value of a player
exists, name, ip, port, usgn, ping,
idle, bot, team, look, x, y,
rot, tilex, tiley, health,
armor, money, score, deaths,
teamkills, hostagekills,
teambuildingkills, weaponid,
weapontype, nightvision,
defusekit, bomb, flag,
reloading, process,
sprayname, spraycolor,
votekick, votemap, favteam
[ITEM]
- item(id,"value") Return a value of an item
exists, name, type, player, ammo,
ammoin, mode, x, y, dropped,
droptimer
- itemtype(type,"value") Return a value of an item type
name, dmg, dmz_z1, dmg_z2,
rate, reload, ammo, ammoin,
price, range, dispersion,
slot, recoil