Simple Scripting

From Unreal Software English Wiki
Jump to: navigation, search
px This article is a stub.
You can help by expanding it

CS2D uses Lua as its scripting engine.

Introduction to scripting

Lua is a powerful and light scripting engine, and it is used by CS2D. Lua allows anyone to create scripts for Counter-Strike 2D since it is easy to use and has user-friendly syntax.

Simple Scripting

Here is an "Hello World!" example in Counter-Stike 2D.

print("Hello, World!")

Note that print will only show text in the console, it will not be shown in-game. To show text in-game, you must use msg or msg2



addhook is the major method to detect whether a player did a specific action.

addhook("serveraction", "_sva")
function _sva(p, b)
	if b == 1 then 
		parse("setscore "..p.." 0")
 		parse("setdeaths "..p.." 0")
 		msg2(p, "Score reset!")
 	end
end



There are several types of statements in lua, the most common one is the if and for statement.

addhook("serveraction", "_sva")
function _sva(p, b)
	if b == 1 then 
		local a = {"USGN: "..player(p, "usgn"); "IP: "..player(p, "ip"); "Name: "..player(p, "name")}
		for _, i in pairs(a) do 
			msg2(p, i) 
		end
	end
end

External Links

Unrealsoftware file archive(Lua scripts) The Lua 5.1 Manual

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox