A Cs2D clan
HomeFAQSearchMemberlistUsergroupsRegisterLog in


 lua tutorial

Go down 


Posts : 348
Join date : 2010-12-22
Age : 27
Location : Austria

lua tutorial Empty
PostSubject: lua tutorial   lua tutorial Icon_minitimeSat Dec 25, 2010 11:10 am

There are normal CS2D scripts and Lua scripts in CS2D. These are two different things. CS2D scripts are essential. They are used to control the game (settings are saved as scripts for example).
Lua is a scripting language which is included in CS2D for server sided scripts. Lua scripts are optional. They can be used to change the behavior of the game and to write own modifications.
Please use the help-button in the CS2D main menu for details and/or read "sys\lua\info.txt" in your CS2D folder!

I translated this so please report me if there is something wrong.

the original is at www.big-tut.de there are many tutorials. user write for users tut´s for everything. PHP,dedicated server, lua, cs2d on linux,...,and and and

lua for cs2d

To script Lua use Notepad + +, because this program has a syntax highlighter for Lua and other Script-/Programmierlanguages.

CS2D hooks used to "communicate" with lua

Spawn of the hook that the spawning of a player calls a function,

AddHook ([[spawn]],[[spawner]])
function spawn (id)
a local
if not a then a = 0 end
a = a + 1

The function spawner increases the (local) variable a always by one when a player Spawns

Here is a list of a few hooks what work with:
AddHook (hookname, function)

added to a function:

Hook () - When the hook is used.
> Return values. Return (s)

join (id) - When a player on the server join
Id: The ID of the player connected.
> Return: none

spawn (id) - When a player spawn.
Id: The ID of the player is spawned.
> Return "" - normally spawn
"X" - only with Knife
"Item id 1, item id 2 ,..." - With the specified item spawning

hit (id, source, weapon, hpdmg, apdmg) - When you make a player.
Id: The ID of the player is attacked.
Source: The ID of the player has taken the.
weapon: The weapon was taken.
-Hpdmg: The damage suffered by the players taken in the life.
-Apdmg: The damage suffered by the player taken at the tank.
> Return: 1 - not calculate the damage.
0 - Calculate normal damage.

always () - Every Frame (50) times per second.

MS100 () - Each tenth of a second.

second () - Every second.

minute () - Every minute.

and so on.
then there are functions of the Creators of CS2D, Peter Schauss, such as:

parse (a cs2d command)
msg ("Display a msg in-game.")
msg2 (id, "To send a msg in-game player in particular.")<- like a whisper function. An example of annotated code with hooks:

AddHook ("join", "joiner")
joiner function (id)
msg ('players' player .. (id,' name').." takes part in the game @ C ") - Leave a MSG show, who the server says the joint.

AddHook ([[spawn]],[[spawner]])
function spawn (id)
return "3,32,83" - Deagle, M4A1 and Super Armor Equippers.
I have intentionally used "''and [[]], because you can use these to create a string.

links for lua tutorials:
Back to top Go down
View user profile
lua tutorial
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Team Fruit|Fruit| :: GFX ,SFX area :: Lua and binds-
Jump to: