Counter-Strike 2D supports Lua scripts since Beta 0.1.1.4

It uses the Lua engine Version 5.1.4
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)

Attention:
Using many complex Lua scripts can make the game slower.
Wrong or excessive usage of certain commands can lead to
increased traffic and lags.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

AUTOMATICALLY EXECUTED FILES:

CS2D will automatically load and execute
"sys\lua\server.lua" when hosting a server.
(only if the setting "mp_luaserver" is "server.lua")

In addition it will execute "maps\MAPNAME.lua" when
loading a map as server (MAPNAME = name of the map).
This happens AFTER executing the "server.lua" and only
if there is a Lua file for the map!
(also the setting "mp_luamap" has to be "1")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

HOW TO HOOK:

The following hooks are available. You have to create
Lua functions and then you have to attach these functions
to the hook by using the command
addhook("hook", "function" [,priority])
CS2D will execute all attached functions whenever the
corresponding hook action occurs in-game.

Priority is only important if there is more than one
function attachted to the same hook!
It is an optional parameter which sets the priority
for this function. Default is 0, higher numbers = higher
priority, lower numbers (also negative) = lower priority.
The attached function with the HIGHEST priority is the LAST
function which will be executed. Moreover CS2D will take
the return value of this function (if there is any)!

CS2D will pass parameters to most functions. You can use
these parameters but you don't have to.

Some of the hook-functions can also have a return value.
This return value influences the way how CS2D behaves.
Returning nothing is like returning 0, "" or nil.
In many cases you can skip the actual action in CS2D
by returning 1 (return 1).

Always use just the name of the hook/function for adhook!
Don't enter the brackets or parameters there!
example:
wrong: addhook("leave(id,reason)","myleavehook(id,reason)")
right: addhook("leave","myleavehook")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

LIST OF AVAILABLE HOOKS:

ms100()							every 100 milliseconds (1/10 sec)


second()						each second


minute()						each minute


always()						always (each frame)


join(id)						on join
-id: player id


leave(id, reason)					on leave
-id: player id
-reason: reason id (0 normal, >0 kick/ban/timeout)


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


spawn(id)						on spawn
-id: player id
>return:	"" - (nothing) spawn with regular items
		"x" - spawn with melee weapon only
		"typeid,typeid,..." - spawn with these items and melee


startround(mode)					on start of round
-mode: start/end mode id


endround(mode)						on end of round
-mode: start/end mode id


name(id, oldname, newname)				on name change
-id: player id
-oldname: old player name
-newname: new player name
>return:	0 - proceed normally
		1 - don't change name


mapchange(newmap)					on map change
-newmap: name of new map


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


serveraction(id,action)					on server action key
-id: player id
-action: action key 1,2 or 3


trigger(trigger,source)					on trigger (once per trigger)
-trigger: trigger name
-source: triggered by 0=map/1=script
>return:	0 - proceed normally
		1 - don't trigger

triggerentity(x,y)					on trigger (for triggered entities)
-x: entity x position (tiles)
-y: entity y position (tiles)
>return:	0 - proceed normally
		1 - don't trigger


buy(id, weapon)						on buy
-id: player id
-weapon: type id of requested weapon
>return:	0 - proceed normally
		1 - don't allow buying


walkover(id,iid,type,ain,a,mode)			on walking over an item
-id: player id
-iid: item id
-type: item type
-ain: ammo in weapon / item count
-a: additional ammo
-mode: item mode
>return:	0 - proceed normally (collect?)
		1 - don't collect


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


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 (tiles)
-y: drop y position (tiles)
>return:	0 - proceed normally (drop?)
		1 - don't drop


select(id,type,mode)					on select weapon
-id: player id
-type: item type
-mode: item mode


reload(id,mode)						on reload
-id: player id
-mode: reload action (1 start, 2 finish)


attack(id)						on attack
-id: player id


attack2(id,mode)					on attack2
-id: player id
-mode: weapon mode


projectile(id,weapon,x,y)				on projectile/grenade impact
-id: id of player who shot
-weapon: weapon type of projectile
-x: x position of impact (pixels)
-y: y position of impact (pixels)


move(id,x,y,walk)					on player movement
-id: id of player who moved
-x: new x position of player (pixels)
-y: new y position of player (pixels)
-walk: walked? (0 run, 1 walk)


hit(id,source,weapon,hpdmg,apdmg)			on hit/damage
-id: player id
-source: source player id or 0
-weapon: weapon type / source type id
-hpdmg: caused damage (health)
-apdmg: caused damage (armor)
>return:	0 - proceed normally
		1 - ignore this hit (no damage)


kill(killer,victim,weapon,x,y)				on kill
-killer: player id
-victim: player id
-weapon: weapon type id
-x: death x (pixels)
-y: death y (pixels)


die(victim,killer,weapon,x,y)				on death
-victim: player id
-killer: player id
-weapon: weapon type id
-x: death x (pixels)
-y: death y (pixels)
>return:	0 - proceed normally
		1 - drop bomb/flag only


use(id, event, data, x, y)				on use
-id: player id
-event: use event type
-data: additonal data
-x: use x (tiles) or hostage id
-y: use y (tiles)


say(id, message)					on say
-id: player id
-message: actual chat message
>return:	0 - proceed normally
		1 - don't show message


sayteam(id, message)					on sayteam
-id: player id
-message: actual chat message
>return:	0 - proceed normally
		1 - don't show message


radio(id, message)					on radio
-id: player id
-message: radio message type id
>return:	0 - proceed normally
		1 - don't show message


spray(id)						on spray
-id: player id


vote(id,mode,param)					on vote
-id: player id
-mode: vote mode (1 kick, 2 map)
-param: player id or map


buildattempt(id,type,x,y)				on build attempt
-id: player id
-type: building type
-x: building x (tiles)
-y: building y (tiles)
-mode: building mode
>return:	0 - proceed normally
		1 - don't build


build(id,type,x,y,mode,objectid)			on (effective) build
-id: player id
-type: building type
-x: building x (tiles)
-y: building y (tiles)
-mode: building mode
-objectid: id of new building object
>return:	0 - proceed normally
		1 - don't build


menu(id, title, button)					on Lua menu button selection
-id: player who clicked a Lua menu button
-title: title of the Lua menu
-button: id of button. 1-9 or 0 for cancel


log(text)						on logging
-text: text line
>return:	0 - proceed normally
		1 - don't log this line


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

LIST OF LUA FUNCTIONS FOR CS2D

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 to all
- msg2(id,"text")		send "text" to a certain player only
- parse("commands")		execute CS2D script commands
- vars()			show Lua variables in main table
- funcs()			show Lua functions in main table
- addhook("hook","func",[prio])	attach a function to a hook
- freehook("hook","func")	remove a function from a hook
- sethook("hook",enable)	Enable(1)/Disable(0) a hook completely
- menu(id,"tile,b1,b2,...,b9")	Open a menu on the screen of
				a certain player or at the
				screen of every player (id=0)

[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, nextmap

[MAP]
- map("value")			Return info about the current map:
				name, xsize, ysize, tileset,
				tilecount, back_img, back_scrollx,
				back_scrolly, back_scrolltile,
				back_r, back_g, back_b, storm_x,
				storm_y, mission_vips,
				mission_hostages, mission_bombspots,
				mission_ctfflags, mission_dompoints,
				nobuying, noweapons, teleporters

[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,
				speedmod, maxhealth
				Moreover there is:
				player(0,"table"): table with all player IDs

- playerweapons(id)		Return a table containing the
				types of all items carried by
				this player
				

[ITEM]
- item(id,"value")		Return a value of an item:
				exists, name, type, player, ammo,
				ammoin, mode, x, y, dropped,
				droptimer
				Moreover there is:
				item(0,"table"): table with all dropped item IDs

- 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

[ENTITY]
- entity(x,y,"value")		Return a value of an entity:
				exists, typename, type, name,
				trigger, state, int0, int1, int2,
				int3, int4, int5, int6, int7,
				int8, int9, str0, str1, str2,
				str3, str4, str5, str6, str7,
				str8, str9
				(int0-9 and str0-9 are used
				for entity settings and are
				different for each entity type)

[HOSTAGE]
- hostage(id,"value")		Return a value of a hostage:
				exists, health, follow, look,
				x, y, rot, tilex, tiley
				Moreover there is:
				hostage(0,"table"): table with all hostage IDs

[DYNAMIC OBJECT (BUILDING)]
(dynamic objects are used for buildings, mines etc.!)

- object(id,"value")		Return a value of a dynamic object:
				exists, typename, type,
				health, mode, team, player,
				x, y, rot, tilex, tiley,
				countdown, rootrot, idle,
				rotvar, target, upgrade
				Moreover there is:
				object(0,"table"): table with all dynamic object IDs


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

www.lua.org
www.UnrealSoftware.de
www.CS2D.com
www.USGN.de