Forum

> > CS2D > General > Lua Scripts for CS2D
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Lua Scripts for CS2D

134 replies
Page
To the start Previous 1 2 3 4 5 6 7 Next To the start

Poll Poll

What do you think about Lua support in CS2D?

Only registered users are allowed to vote
Awesome!
85.88% (225)
Sounds good.
7.25% (19)
Bad idea. I hate Lua!
3.44% (9)
I have no idea.
3.44% (9)
262 votes cast

old closed Poll Lua Scripts for CS2D

DC
Admin Off Offline

Quote
The next version of CS2D will support Lua scripting!
Lua is a very powerful and fast script language which is used in many games (like garry's mod or crysis).

You will be able to use Lua scripts for maps and on your server. Clients will not be able to write Lua scripts due to security reasons.

The whole system works with hooks/events (comparable with Stranded II scripting).

For example you can write a function hook_say in your Lua script. CS2D will always call this function when someone on your server says something. It also will automatically pass all information about this event as parameters to your Lua function.
For hook_say it's the ID of the player who says something and of course the actual message.

here is a Lua script example which is already working:
1
2
3
4
5
6
7
8
9
10
11
function hook_say(p,t)
	badwords = {"hitler","fuck","bitch","cunt","ass"};
	t=string.lower(t);
	for i = 1,#badwords,1 do
		if (string.find(t,badwords[i])~=nil) then
			parse("sv_msg \""..player(p,"name").." said a bad word ("..badwords[i]..")!\"");
			parse("kick "..p);
			break;
		end
	end
end
this script sends the message "XXX said a bad word (YYY)" and kicks the player who says one of the words in the badwords-table.

the command "parse" is used to execute normal cs2d commands within your lua script.

"player" is used to get information of a player with a certain id. in this case it gets the "name" of the player who said something. It can also be used to get infos like ip, ping, health, armor, position, team, look, weapons etc.

Lua scripting will make it possible to create own game mode mods and customizations for servers and very dynamic and interactive maps.
edited 1×, last 08.02.11 01:33:25 pm

old Re: Lua Scripts for CS2D

Thomazz
User Off Offline

Quote
so u can make ur own mod like Zombie Mod, which is already included, and other players can download it ?!

oh and why not writing in German ForumSection ?

old Re: Lua Scripts for CS2D

PixelHunter
User Off Offline

Quote
This lua will includes:?
-weapon modifications
-variables, drawing varibles
-message to a specified player
-changing player stats like armor and health (pernamently to the round)
-and so on

old Re: Lua Scripts for CS2D

Dyingwish
User Off Offline

Quote
i think lua scripts will make the complete game modable.
but you can script hacks or aimbots with it , this will be a problem.

old Re: Lua Scripts for CS2D

Lee
Moderator Off Offline

Quote
sweet, did you use that wrapper from blitz or did you write your own wrapper?

Quote
but you can script hacks or aimbots with it , this will be a problem.


Lua is only available on the server side, it's not a client side modification, and if I remember correctly, there are custom scoping of the lua hooks so it can't access all parts of the system, meaning there are some limitations to what you can and can't do with the script. (Apparently, the only accessor method currently exposed to the lua runtime is the parse function)

----------------

And one more thing, is there any chance that you can expose a few more accessor methods because imo only exposing the parse command to the runtime is pretty limited.

old Re: Lua Scripts for CS2D

sonnenschein
User Off Offline

Quote
does this mean that I'm gonna need to learn how to script? i don't even know how to make simple command in Qbasic

*EDIT*
If i can't ask someone to make me a script, or its too hard, where can i learn Lua scripting

Dyingwish has written
i think lua scripts will make the complete game modable.
but you can script hacks or aimbots with it , this will be a problem.

No, just server side, that means: no entering in servers that have hacking script. (but i think DC will add anti hack solution)

old Re: Lua Scripts for CS2D

DC
Admin Off Offline

Quote
@Thomazz: No. You will not download anything. It is on the server and stays on the server.

@PixelHunter: You can't add new weapons or something like that. But you could extend the behaviour. For example you could add that a weapon teleports a player or pushs him (the whole thing is restricted to serverside stuff). Lua contains variables, tables (arrays), functions and much more.

@Dyingwish: It will neither make the game completely modable nor make script hacks etc. possible because it is serverside only! scripts just do not run clientside.

@leegao: I used the existing wrapper. It works pretty well and is very fast. This is just an example and of course it will be extended.

After defining all your hook functions you have to call updatehooks() in your Lua script. This will initialize the hooks (it sets flags in CS2D for hooks which are defined in your scripts. so CS2D will only try to run hook functions which are actually defined in your Lua scripts).
There are also hooks which are executed every second, every minute or even every frame, hooks for killing, joining, buying, building, using, spraying etc.

@LinuxGuy
Google for Lua tutorials. There are lots of tutorials online and there are also a lot of books you could read
edited 1×, last 21.02.09 11:45:03 pm

old Re: Lua Scripts for CS2D

chuico123
User Off Offline

Quote
OMG!!! (ô_Ô) <(:awesome!:) aaaaaaa!!!

as i have read until now i can just imagine how CS2D will be in the future!! this will make CS2D a lot more dynamic!!

any examples of what we could make? any ideas?

and about the hack thing that guy have said, as it is only serverside, if he hacks, speedhack for example, everyone in the server will be running fast! but only in that server

old Re: Lua Scripts for CS2D

Lee
Moderator Off Offline

Quote
LinuxGuy has written
If i can't ask someone to make me a script, or its too hard, where can i learn Lua scripting


The official documentation is on the lua homepage, the language is actually relatively easy to learn, straightforward and takes after what you would expect out of a structural language.

Quote
After defining all your hook functions you have to call updatehooks() in your Lua script. This will initialize the hooks (it sets flags in CS2D for hooks which are defined in your scripts. so CS2D will only try to run hook functions which are actually defined in your Lua scripts).
There are also hooks which are executed every second, every minute or even every frame, hooks for killing, joining, buying, building, using, spraying etc.


Hmm, just for curiosity's sake, are there any variables that will be exposed to the lua runtime on a global scale and how detailed are the event connectors between lua and the actual game? (I know you've already mentioned position and command parsing, but will there be things like entity creation, variable manipulation, or things that are a bit more dynamic?)

Anyways, awsome add, can't wait to try it out.

old Re: Lua Scripts for CS2D

DC
Admin Off Offline

Quote
I'm currently still planning and testing it so I can't tell much about that in detail.

Probably the next version will only allow pretty simple hooking which means just adding functionality without changing the existing and hard coded behaviors.

I'll try to give Lua access (read only) to all relevant game variables (which are pretty much).
just as example the values of a player which are currently available in Lua:
Quote
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

in fact you have to use a function to get these values. they are not available as normal Lua variables because it could be fatal for some values to change them in the wrong moment etc. But of course there will be also a lot of commands to change important values. Like changing the position of a player.

Most commands will be regular CS2D commands which can be used in Lua with parse. This has the advantage that you can use them in your Lua scripts and in the old school cs2d scripts for binds etc.

All commands to get values will be pure Lua commands since cs2d script does not even support variables.

old Re: Lua Scripts for CS2D

-Skull_
User Off Offline

Quote
ermm..dc after u added the lua script will it become 6mb or something example:Now i download cs2d only 5mb after you added the lua script it become 6mb

old Re: Lua Scripts for CS2D

DC
Admin Off Offline

Quote
lol... no, Lua is pretty small. The size of the exe file will grow just some kb. You will probably not even notice it.

old Re: Lua Scripts for CS2D

chuico123
User Off Offline

Quote
CS2D is getting each time cooler and cooler, its awesome how CS2D inproves itself at each release

just for some curiosity, will the server be able to make single player maps? and if it is online, make all the players join a single team and then co-operate, just like in Left 4 Dead, where u can play multiplayer, but still in a campaign whit objectives that are not team based, in my mind the idea is perfect, but i cant explain it correctly in words, if you didnt understand please tell me

old Re: Lua Scripts for CS2D

DC
Admin Off Offline

Quote
Well I don't really want comment that. It's too early to say something about it. Adding a singleplayer mode/campaign and a coop mode is an option but I'm not sure if it's going to happen.

old Re: Lua Scripts for CS2D

chuico123
User Off Offline

Quote
-Skull_ has written
how can i edit those script?


wait until it releases it! probably there will be a "readme" file for further explanation about the scripting and also for help

EDIT: if it is possbile please make it! im sure it will be a great success! single-player mode is very expected, then is just up to us to make the maps and the scripting

ok now im going to prepare myself and im going to learn some Lua scripting

old Re: Lua Scripts for CS2D

mrc1
COMMUNITY BANNED Off Offline

Quote
well, its possible to separate for example,
for fun gaming and professional playing...?
i dont understand it very well, or its just
to make mods?

old Re: Lua Scripts for CS2D

Matsu-Kiri
User Off Offline

Quote
how hard can it be to make a campaign map is in cs2d now? just play offline with bots and make like, if u blow up this box u win or watever, simple
To the start Previous 1 2 3 4 5 6 7 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview