English Lua Scripts for CS2D

134 replies
Goto 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.83% (218)
Sounds good.
7.09% (18)
Bad idea. I hate Lua!
3.54% (9)
I have no idea.
3.54% (9)
254 votes cast
21.02.09 10:20:16 pm
Up
DC
Admin
Offline Off
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:
Code:
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
21.02.09 10:44:26 pm
Up
Thomazz
User
Offline Off
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 ?
21.02.09 10:55:49 pm
Up
PixelHunter
User
Offline Off
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
21.02.09 11:00:44 pm
Up
Dyingwish
User
Offline Off
i think lua scripts will make the complete game modable.
but you can script hacks or aimbots with it , this will be a problem.
Just Google it | sry das ich so letzte Zeit so negativ war , ändert sich wieder.
21.02.09 11:09:42 pm
Up
Lee
Moderator
Offline Off
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.
21.02.09 11:28:08 pm
Up
sonnenschein
User
Offline Off
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)
21.02.09 11:33:37 pm
Up
DC
Admin
Offline Off
@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
21.02.09 11:57:37 pm
Up
chuico123
User
Offline Off
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
21.02.09 11:58:47 pm
Up
Lee
Moderator
Offline Off
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.
22.02.09 12:02:19 am
Up
-Skull_
User
Offline Off
wow....this idea...really awsome
i love it!
IMG:http://i714.photobucket.com/albums/ww144/Skull_xr6/forum/sksig.png
22.02.09 12:12:30 am
Up
DC
Admin
Offline Off
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.
22.02.09 12:18:05 am
Up
-Skull_
User
Offline Off
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
IMG:http://i714.photobucket.com/albums/ww144/Skull_xr6/forum/sksig.png
22.02.09 12:24:50 am
Up
DC
Admin
Offline Off
lol... no, Lua is pretty small. The size of the exe file will grow just some kb. You will probably not even notice it.
22.02.09 12:25:31 am
Up
chuico123
User
Offline Off
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
22.02.09 12:30:31 am
Up
FME4Y_CQC
User
Offline Off
dc, if someone say badwords in another language???
IMG:http://img513.imageshack.us/img513/9623/fdprogress.jpg
if someone want to help me, PM me.
22.02.09 12:31:02 am
Up
-Skull_
User
Offline Off
how can i edit those script?
IMG:http://i714.photobucket.com/albums/ww144/Skull_xr6/forum/sksig.png
22.02.09 12:34:25 am
Up
DC
Admin
Offline Off
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.
22.02.09 12:34:47 am
Up
chuico123
User
Offline Off
-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
22.02.09 12:57:30 am
Up
mrc1
COMMUNITY BANNED
Offline Off
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?
[img is too large]
22.02.09 01:04:35 am
Up
Matsu-Kiri
User
Offline Off
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
IMG:http://oi42.tinypic.com/24dhlr9.jpg
To the start Previous 1 2 3 4 5 6 7 Next To the start