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 Re: Lua Scripts for CS2D

ohaz
User Off Offline

Quote
oh, i think if you use lua with cs2d it's very easy!
Just wait for cs2d 0.1.1.4, there are some samples and a file where the meanings of the commands are.
if you watch them sometime, you will get a feeling for it and you will be able to write your own lua scripts (I even made a gungame without training lua

old Re: Lua Scripts for CS2D

Zune5
COMMUNITY BANNED Off Offline

Quote
Relatively it's like any other programming language. You read about it you learn.

old Re: Lua Scripts for CS2D

syntaku
User Off Offline

Quote
does this mean we may be able to script vehicles (yays i may be able to make a mech battlefield map)

old Re: Lua Scripts for CS2D

Lee
Moderator Off Offline

Quote
syntaku has written
does this mean we may be able to script vehicles (yays i may be able to make a mech battlefield map)


Nope, this is on the server side only

old Re: Lua Scripts for CS2D

DC
Admin Off Offline

Quote
you would need some server-controlled in-game objects you can modify and move with Lua scripts.
there are so called "dynamic objects" in cs2d (used for buildings and mines). maybe these could be used to create something like vehicles. however you will probably not be able to access and modify these objects with Lua in the next release. this will be added later.

so leegao is right. you will not be able to script vehicles with the next release.

old Re: Lua Scripts for CS2D

chuico123
User Off Offline

Quote
will it be able to scrip the max amount of turrets and dispensers? and also to remove the distance limit between each building? that would make possible to make super fortress

old Re: Lua Scripts for CS2D

DC
Admin Off Offline

Quote
please read my previous post more carefully. I wrote something about the dynamic objects which are used for buildings (so turrets and dispenser too!). I explained that you will PROBABLY NOT be able to influence them with the next release and that it will be added later.

old Re: Lua Scripts for CS2D

chuico123
User Off Offline

Quote
ah ok, i tough it was not possible to edit the physics of the object, but to edit the number of objects, but anyway i got it now

old Re: Lua Scripts for CS2D

Zune5
COMMUNITY BANNED Off Offline

Quote
Has anyone been working on a GunGame script or a non-click respawn for Lua yet?

old Re: Lua Scripts for CS2D

Lee
Moderator Off Offline

Quote
moreover, unless you precache the needed graphics for the "vehicles" into your map, you won't get anywhere

@Zune: Yeah, I'm in the middle of the GG and a few other mods, I'm about 2000 lines of code in total so it should be close.

old Re: Lua Scripts for CS2D

Zune5
COMMUNITY BANNED Off Offline

Quote
One more question...

Possible to make a anti-cheating script/mod against speed hackers? Auto-kick/ Ban...

old Re: Lua Scripts for CS2D

Lee
Moderator Off Offline

Quote
yes but it's not advisable to do it via lua since movement related events are very time sensitive, and the only viable way of detecting if a person is speed hacking is to check with the server speed var, and determine based on the latency a range of acceptable relative speed in the last 100miliseconds or so. The problem here is that people with ping of 100 or over will almost certainly have an inflated speed as compared to the other people, so it's nearly impossible to determine it just through lua.

old Re: Lua Scripts for CS2D

Zune5
COMMUNITY BANNED Off Offline

Quote
Haha yeah. I guess this is up to DC than because it doesn't look like his anti-cheat protection is doing much work.

Nevertheless, good luck on your more-than-2000-line-script xD.

old Re: Lua Scripts for CS2D

DC
Admin Off Offline

Quote
I also scripted a simple gungame mod as one of the example scripts which come along with the next release. it's less than 150 lines with 10 levels/different weapons (saved in a table/array so it's easy to modify/extend). however it makes cs2d quit without any errors sometimes. probably a bug in cs2d. didn't manage to find/fix the problem yet...

( and btw it's still not much easier to detect speedhackers by using the original code of cs2d. mp_trace was an attempt which terribly failed [it is disabled by default therefore. the principle works only if pings are low enough]. lags and network delays make it very hard and nearly impossible. there would always be border cases where the system fails and thinks that innocent people are using speedhacks. )

old Re: Lua Scripts for CS2D

Lee
Moderator Off Offline

Quote
oke, I've just finished my rendition of the Gun Game mod using my system and here it is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
--mod_gg.lua
init_mod("gg")
gg.var("wpnlvl", {}, "svar")
gg.var("players", {}, "svar")
gg.var("maxlvl", 0)
gg.var("minlvl", 0)
function gg.setlevel(p, level, b)
	if b then
		msg("Player \""..player(p, "name").."\" is now on level "..level)
	end
	gg.players[p].level = level
	gg.players[p].kills = 0
	setWeapon(p, gg.wpnlvl[level].wpn_id)
end
function hook_init_gg()
	for line in io.lines(conf_dir.."gungame.cfg") do
		local r = toTable(line)
		gg.wpnlvl[tonumber(r[1])] = {wpn_name = r[2],wpn_id = _G[r[2]], kills = tonumber(r[3])}
		if tonumber(r[1]) > gg.maxlvl then
			gg.maxlvl = tonumber(r[1])
		elseif tonumber(r[1]) < gg.minlvl then
			gg.minlvl = tonumber(r[1])
		end
	end
	for i = 1, 32, 1 do
		gg.players[i] = {level = 0, kills = 0}
	end
end
function hook_startround_gg(typ)
	for i = 1, 32, 1 do
		gg.players[i] = {level = 0, kills = 0}
	end
	for i=1, #players, 1 do
		if player(i, "health") > 0 then
			gg.setlevel(i, 1)
		end
	end
end
function hook_changeteam_gg(p, t)
	gg.players[p].kills = 0
	gg.players[p].level = gg.players[p].level - 1
	if gg.players[p].level < 1 then gg.players[p].level = 1 end
	gg.setlevel(p, gg.players[p].level)
end
function hook_leave_gg(p, t)
	gg.players[p] = {level = 0, kills = 0}
end
function hook_join_gg(p, t)
	gg.setlevel(p, 1)
end
function hook_kill_gg(k, v, w)
	if gg.players[k].level > gg.maxlvl or gg.players[k].level <= gg.minlvl then return nil end
	if w == gg.wpnlvl[gg.players[k].level].wpn_id then
		gg.players[k].kills = gg.players[k].kills + 1
	end
	if gg.players[k].kills >= gg.wpnlvl[gg.players[k].level].kills then
		gg.setlevel(k, gg.players[k].level+1, true)
	end
end
return gg.name
which is exactly 60 lines and includes backwards leveling for switching teams and ability to set custom levels, kills to advance levels, and to curtail the minimum and maximum levels.

Output of the above code:
1
2
3
4
5
6
7
8
9
10
11
12
13
All	Player 2 has been killed by Player 1 with 40
All	Player 1 has been killed by Player 2 with 40
All	Player 2 has been killed by Player 1 with 40
All	Player "Player 1" is now on level 2
All	Player 3 has been killed by Player 2 with 40
All	Player "Player 2" is now on level 2
All	Player 3 has been killed by Player 1 with 33
All	Player 4 has been killed by Player 2 with 33
All	Player 2 has been killed by Player 1 with 33
All	Player "Player 1" is now on level 3
All	Player 4 has been killed by Player 1 with 31
All	Player 2 has been killed by Player 1 with 31
All	Player "Player 1" is now on level 4

I'll add more commands as I go along with this.

old Re: Lua Scripts for CS2D

Lee
Moderator Off Offline

Quote
Well, I was actually using what the original AMX version of GG had that so you can pick up new weapons but you'll have to kill with the weapon on your level to actually level up.

old Re: Lua Scripts for CS2D

Zune5
COMMUNITY BANNED Off Offline

Quote
Hey lee, just a suggestion for your gungame script, if you knife someone than you should be brought back a level except if your ACTUALLY on the level knife (Level 21?)
To the start Previous 1 2 3 4 5 6 7 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview