Forum

> > CS2D > Scripts > Lua Scripts/Questions/Help
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua Scripts/Questions/Help

6,770 replies
Page
To the start Previous 1 232 33 34338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
KaiserWilhelm has written
sorry for asking, but in your description on the download page it says that you have an improved infection system. What exactly does that mean, and where is it? I'm interested because i'm looking for some code to splice into my own for my zombie maps. I want to create a random chance (1 in 10 or something) that when attacked by a zombie with its claw, a survivor is"infected" and in a set amount of time turns into a zombie. it would be even better if this happened ON THE SPOT. instead of just killing the survivor and sending it to the Terrorist spawn. Woukd the latter part even be allowed in Lua or is that to high level?


I don't know who are you asking to, but i'll suggest you something:

Create a table to store which players are 'infected'
When a zombie attacks a CT, use math.random(1,10), if it returns X number of your choice, the CT is infected
Use the second hook to decrease the health of the infected player and check if he's going to be turned into a zombie in that second
If the last thing is true, then use parse("maket "..player) and use spawn player to set it's position.

I hope you know how to script

old Re: Lua Scripts/Questions/Help

sonnenschein
User Off Offline

Quote
@Flacko
Somthing like this? I hope it doesn't have errors

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
infectedpl = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 

--Hooks
addhook("join","infzero")
addhook("second","isinf")
addhook("hit","infect")

--Functions
function infzero(id)
	infextedpl[id] = 0
end

function infect(id,source,weapon,hpdmg,apdmg)
	if (player(source,"team") == 1) then
		if (weapon == 78) then
			local rand = math.random(1,10)
			local x = player(id,"x")
			local y = player(id,"y")
				if (rand == 3) then
					infectedpl[id] = 1
				elseif (rand == 7) then
					parse("customkill "..source.." infected "..id)
					parse("spawnplayer "..x.." "..y)
					msg2(id, "You have been infected by "..player(source,"name"))
				end
		end
	end
end

function isinf()
	for (i = 1,32,1) do
		if (player(i,"exists")) then
			if (infectedpl[i] == 1) then
				parse("sethealth "..id.." "..player(i,"health")-10)
			end
		end
end

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
The isinf function should look more like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function isinf()
	for i=1,32 do
		if(player(i,"exists")) then
			if(infectedpl[i]==1 and player(i,"team")==2) then
				if(player(i,"health")<=10) then --If player is about to be turned into zombie
					local x = player(i,"x")
					local y = player(i,"y")
					parse("maket "..i)
					parse("spawnplayer "..i.." "..x.." "..y)
				else
					parse("sethealth "..i.." "..(player(i,"health")-10))
				end
			end
		end
	end
end

and you could leave the infect function like this:
1
2
3
4
5
6
7
8
9
10
function infect(id,source,weapon,hpdmg,apdmg)
	if (player(source,"team") == 1) then
		if (weapon == 78) then
			local rand = math.random(1,10)
			if (rand == 3) then
				infectedpl[id] = 1
			end
		end
	end
end

And you should also use the die hook to set infectedpl[id] to 0 when they turn to zombie, but I've added the player(i,"team")==2 to make sure infection only damages zombies

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Flacko has written
Blazingxxx, your code is a mess xD, tab it.
Also, you can push zombies into walls Dx.

I have tabbed if you want..
I deleting tabs couse those assh**es who are stealing my scripts and changing names as their own.
But for you I can give tabbed

Btw I cant fix wall bug while I can know where is wall.
I think DC maybe are going to do something for this in next cs2d version

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Quote
Btw I cant fix wall bug while I can know where is wall.


You can always use the map files themselves with lua. Lua does support low level datatypes (those found in C and blitz) and can be used to parse maps. Just make sure that you use a soft break. (Check out 3rr0r's map.py and my struct.lua, there's also a template file inside amx2d that allows you to do collision detection in cs2d)

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Blazzingxx has written
I have tabbed if you want..
I deleting tabs couse those assh**es who are stealing my scripts and changing names as their own.
But for you I can give tabbed

Oh, I get it

leegao has written
You can always use the map files themselves with lua. Lua does support low level datatypes

So, we should use binary input to get info about map's tiles?
I never realized about that, Imma try it...

old Re: Lua Scripts/Questions/Help

KaiserWilhelm
User Off Offline

Quote
Holy crap your fast. I'm gonna have to test that script. Time to go get bit by some zombies...

Other than that the only problem I can see is that it displays a message as to who is infected, not hard for me to fix, and nothing big. The point is to keep players on their toes and continually paranoid as to who could turn into a zombie at any minute. Other than the fact you should watch more movies, i'm thoroughly impressed.

old Re: Lua Scripts/Questions/Help

sonnenschein
User Off Offline

Quote
Lol, Flacko, tnx for fixing my script
If it was mine, lol, everybody who has been hit with claw would loose 10 HP every second, no matter is he zombie or survivor.

old Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Quote
leegao has written
Quote
Btw I cant fix wall bug while I can know where is wall.


You can always use the map files themselves with lua. Lua does support low level datatypes (those found in C and blitz) and can be used to parse maps. Just make sure that you use a soft break. (Check out 3rr0r's map.py and my struct.lua, there's also a template file inside amx2d that allows you to do collision detection in cs2d)
Yeah you can also do a lua setpos check, right? - Right?

You write setpos in console with a high value in e.g. "9999x(width) | 9999y(height)" it will teleport you to a random position but away from walls/obstacles (and closed rooms if I remember correctly). Does that feature already exist in lua, I'm not sure.

Here comes my pathetic try code...
1
2
3
4
5
6
7
8
9
10
11
12
addhook("hit","setpos_check")
tiletypes = { ["wall"]=1,["obstacle"]=2,["tile"]=0
wall = {false}
obstacle = {false}
tile = {true}
true==1
ignore=="return 0"
function setpos_check(id,source,weapon,hpdmg,apdmg)
if (player(id,"x,y")==false then ignore
elseif (player(id,"x,y")==true then do
parse(setpos (player(0,"table") and (player(id,"x,y")==1)
return 1

Code to prevent people from jumping into walls, I am sure it has plenty of errors. Appreciate my try lol.
edited 4×, last 25.07.09 11:46:22 pm

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Ok lee, I have downloaded your struct.lua
Now, how do I use this?
I have worked with file i/o in C++, but I never understood its workings, neither I understand how are CS2D maps written or organized or wathever

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Flacko has written
Ok lee, I have downloaded your struct.lua
Now, how do I use this?
I have worked with file i/o in C++, but I never understood its workings, neither I understand how are CS2D maps written or organized or wathever


Well, they're modeled after Blitz's ReadType and WriteType. They basically convert any string into a stream-able object and reads the data off the stack.

Here's an example of reading the map file

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
if not ReadLine then
	dofile("struct.lua")
end

if not table.dump then
	--dofile("table.lua")
end

map = {
	code = "99856x63$160312%28176708",
	name = "de_dust",
	[2] = {},
	[1] = {},
	collision = {},
	maxx = 0,
	maxy = 0,
	vipspawn = {0, 0},
	vipescape = {},
	hostages = {},
	hostagecount = 0,
	resethostages = {},
	hostagerescure = {},
}

mapdir = "maps/"
mapheader = "Unreal Software's Counter-Strike 2D Map File"
mapcheck = 'ed.erawtfoslaernu'

function loadmap(mapname)
	map.name = mapname
	map.typ = 0
	mapc = io.open(mapname..".map")
	if not mapc then return print("Can Not Load File: "..mapname) end
	mapname = mapc:read(100)
	while true do
		local block = mapc:read(100)
		if not block then break end
		mapname = mapname..block
	end
	--mapname = mapc:read(2^13)
	mapc:close()
	maphd = ReadLine(mapname)
	--print(maphd)
	if maphd == mapheader then
		for i=1, 9, 1 do
			ReadByte(mapname)
		end
		for i=1, 10, 1 do
			ReadInt(mapname)
		end
		for i=1, 10, 1 do
			ReadLine(mapname)
		end
	elseif maphd == "Unreal Software's Counter-Strike 2D Map File (max)" then
		for i = 1, 10, 1 do
			ReadLine(mapname)
		end
	else
		return print("Wrong Map Header")
	end
	map.code = ReadLine(mapname)

	ReadLine(mapname)

	maptilesc_loaded = ReadByte(mapname)
	--print(maptilesc_loaded)
	maxx = ReadInt(mapname)
	maxy = ReadInt(mapname)
	--print(maptilesc_loaded, maxx, maxy)
	map.maxx = maxx
	map.maxy = maxy

	ReadLine(mapname)
    ReadInt(mapname)
    ReadInt(mapname)
    ReadByte(mapname)
    ReadByte(mapname)
    ReadByte(mapname)

	if not (ReadLine(mapname) == mapcheck) then
		return print("Wrong MapCheck")
	end
	tile_modes = {}
	n = 1
	for i = 1, maptilesc_loaded+1, 1 do
		tile_modes[i] = ReadByte(mapname)
		--print(tile_modes[i])

	end

	map.map = {}
	for i = 1, maxx+1, 1 do

		local cache = {}
		for o = 1, maxy+1, 1 do
			local bytecache = ReadByte(mapname)
			if n == 442 then
				print(#mapname)
				print(#s_get(mapname))
				print(ReadLine(mapname))
				return
			end
			--print(bytecache)
			if bytecache > maptilesc_loaded then
				--print(bytecache)
				bytecache = 0
			else
				bytecache = tile_modes[bytecache]
			end
			table.insert(cache, bytecache)
			n=n+1
		end
		table.insert(map.map, cache)
	end
	print(n)
	--table.dump(map.map)
	ec = ReadInt(mapname)
	--print(ec)
	print(s_get(mapname))
end

loadmap("maps/de_cs2d")

old Re: Lua Scripts/Questions/Help

MusicMonkey17
User Off Offline

Quote
2 Quick Questions I need Help With
1. How do you get rid of gut bomb?
2. How do you lay out weapons in your map?
I'm new to CS2D, but it's loads of fun

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Hey lee, I've tried to load de_dust but it was always printing "Wrong Map Header", I made the function to return maphd, and it printed "Unrealsoftware's Counter-Strike 2D Map File (max"
o.O

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Oh yeah, I forgot, for the struct.lua, use the find function of your text editor to find the following code block.

1
2
3
4
5
if x then
			s = string.sub(s, 1, i-2)
		else
			s = string.sub(s, 1, i-1)
		end

and change it to

1
2
3
4
5
if x then
			s = string.sub(s, 1, i-1)
		else
			s = string.sub(s, 1, i-1)
		end

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Ok lee, I started studying your function and I have these 2 questions:

What is the map code for? For example, the map code for de_cs2d is
1
520x79$163948%1835235


Why in the map file appears a link to unrealsoftware.de inverted o.O?
1
ed.erawtfoslaernu
edited 1×, last 27.07.09 06:50:39 am

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
the map-code is an abstract checksum for the map file, used mostly for ID-ing the map. As for the mapcheck, it's a security check for the map parser engine.

The map code is calculated as thus
map_xsize*map_ysize+"x"+map_tilesc+"$"+Replace(CurrentTime(),":","")+"%"+MilliSecs()

On some of the lua engines, there are faulty eof-markers which makes it impossible to accurately determine whether you have the full file or only a partial file.

old Re: Lua Scripts/Questions/Help

playa slaya
COMMUNITY BANNED Off Offline

Quote
I need help.Icant figure out how to make lua files i downloaded to work.I put them in the sys\lua folder but it doesnt work when i start a map.
To the start Previous 1 232 33 34338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview