Forum

> > CS2D > Scripts > Code error.
Forums overviewCS2D overview Scripts overviewLog in to reply

English Code error.

7 replies
To the start Previous 1 Next To the start

old Code error.

Xirot
User Off Offline

Quote
Well , I don't need to explain you.
I have little bug on this lua in line 68
Error Message :
Spoiler >


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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
menus = {"VIP menu,Give 5 speed,Give 120 HP,Normal HP,Normal Speed,Remove Items",
		"Moderator menu,Give 10 speed,Give 160 HP,Normal HP,Normal Speed,VIP House P-1,VIP House P-2,Remove Items",
		"Admin menu,Give 20 speed,Give 250 HP,Normal HP,Normal Speed,Admin Gun,Super Armor,VIP House P-1,VIP House P-2,Remove Items",
		"Hats menu,Previous hat,Next hat,No hat",
		"VIP's weapons,Deagle,Flamethrower,M3,Molotov Cocktail,Chainsaw,Rocket Launcher,Medic Armor",
		"MOD's weapons,Deagle,RPG Launcher,FN F2000,Flamethrower,Chainsaw,Grenade Launcher,Gas Grenade,Medic Armor",
		"Admin's weapons,Deagle,M3,RPG Launcher,M134,FN F2000,Machete,Chainsaw,Satchel Charge,Medic Armor"}
admins = {{}, --VIP USGNS
		{95753}, --MOD USGNS
		{}, --ADMIN USGNS
		{44770}} --SUPER ADMINS USGNS

zone = {sx = 44,
		sy = 87,
		fx = 75,
		fy = 111}
		
teleport = {x = 64,
			y = 2}
	
pos = {{29,204}, --VIP COORDINATES
		{75,201}, --MOD COORDINATES
		{58,108}, --ADMIN COORDINATES
		{60,216}} --SUPER ADMINS COORDINATES
	
lvls = {{"VIP","©255000255"},
		{"MOD","©000255000"},
		{"ADMIN","©255000000"},
		{"SUPER-ADMIN","©255255255"}}
hatsdir = "gfx/!gfx dust town!/hats"
hats = {"hat1.png","hat2.png","hat3.png","hat4.png","hat5.png","hat6.png","hat7.png","hat8.png","hat9.png"}
		
function Array(s,v)
	local a = {}
	for i = 1,s do
		a[i] = v
	end
	return a
end
function checklvl(id)
	for key,t in ipairs(admins) do
		for _,usgn in ipairs(t) do
			if usgn == player(id,"usgn") then
				return key
			end
		end
	end
	return 0
end

hat = Array(32,nil)
ehat = Array(32,0)
alvl = Array(32,0)

addhook("movetile","movet")
function movet(id,x,y)
	if x >= zone.sx and x <= zone.fx and y >= zone.sy and y <= zone.fy then
		if not lvlboolean(id,1) then
			parse("setpos "..id.." "..(teleport.x*32+16).." "..(teleport.y*32+16))
		end
	end
end
		

addhook("usebutton","muse")
function muse(id,x,y)
	if entity(x,y,"name") ~= nil then
		menu(id,menus[tonumber(entity(x,y,"name"))])
	end
end

addhook("join","mjoin")
function mjoin(id)
	alvl[id] = 0
	if checklvl(id) > 0 then
		
		alvl[id] = checklvl(id)
	end
end

addhook("spawn","mmjoin")
function mmjoin(id)
	if checklvl(id) > 0 then
		parse("setpos "..id.." "..(pos[checklvl(id) ][1]*32+16).." "..(pos[checklvl(id) ][2]*32+16))
	end
end

addhook("say","masd")
function masd(id,txt)
	if checklvl(id) > 0 then
		if string.lower(txt):sub(1,6) == "!home" then
			parse("setpos "..id.." "..(pos[checklvl(id) ][1]*32+16).." "..(pos[checklvl(id) ][2]*32+16))
			return 1
		end
	end
end
function menuhat(id)
	if hat[id] ~= nil then
		freeimage(hat[id])
	end
	hat[id] = image(hatsdir.."/"..hats[ehat[id]],1,1,200+id)
	menu(id,menus[7])
end
function lvlboolean(id,l)
	if alvl[id] >= l then
		return true
	end
	return false
end
addhook("menu","mhookm")
function mhookm(id,t,b)
	if t == "Hats menu" then
		if b == 1 then
			if ehat[id] > 1 then
				ehat[id] = ehat[id] - 1
			else
				ehat[id] = #hats
			end
			menuhat(id)
		elseif b == 2 then
			if ehat[id] < #hats then
				ehat[id] = ehat[id] + 1
			else
				ehat[id] = 1
			end
			menuhat(id)
		elseif b == 3 then
			if hat[id] ~= nil then
				freeimage(hat[id])
			end
		end
	elseif t == "VIP menu" then
		if lvlboolean(id,1) then
			if b == 1 then
				parse("speedmod "..id.." 5")
			elseif b == 2 then
				parse("setmaxhealth "..id.." 120")
				parse("sethealth "..id.." 120")
			elseif b == 3 then
				parse("setmaxhealth "..id.." 100")
				parse("sethealth "..id.." 100")
			elseif b == 4 then
			    parse("speedmod "..id.." normal")
			elseif b == 5 then
			    parse("strip "..id.." ")
				parse("setarmor "..id.." 0")
			end
		end
	elseif t == "Moderator menu" then
		if lvlboolean(id,2) then
			if b == 1 then
				parse("speedmod "..id.." 10")
			elseif b == 2 then
				parse("setmaxhealth "..id.." 160")
				parse("sethealth "..id.." 160")
			elseif b == 3 then
				parse("setmaxhealth "..id.." 100")
				parse("sethealth "..id.." 100")
			elseif b == 4 then
			    parse("speedmod "..id.." normal")
			elseif b == 5 then
			    parse("setpos "..id.." 526 2992")
			elseif b == 6 then
			    parse("setpos "..id.." 723 3411")
			elseif b == 7 then
			    parse("strip "..id.." ")
				parse("setarmor "..id.." 0")
			end
		end
	elseif t == "Admin menu" then
		if lvlboolean(id,3) then
			if b == 1 then
				parse("speedmod "..id.." 20")
			elseif b == 2 then
				parse("setmaxhealth "..id.." 250")
				parse("sethealth "..id.." 250")
			elseif b == 3 then
				parse("setmaxhealth "..id.." 100")
				parse("sethealth "..id.." 100")
			elseif b == 4 then
			    parse("speedmod "..id.." normal")
			elseif b == 5 then
			    parse("equip "..id.." 4")
			elseif b == 6 then
			    parse("equip "..id.." 83")
			elseif b == 7 then
			    parse("setpos "..id.." 526 2992")
			elseif b == 8 then
			    parse("setpos "..id.." 723 3411")
			elseif b == 9 then
			    parse("strip "..id.." ")
				parse("setarmor "..id.." 0")
			end
		end
		elseif t == "VIP's weapons" then
		if lvlboolean(id,1) then
			if b == 1 then
				parse("spawnitem 3 67 90")
			elseif b == 2 then
				parse("spawnitem 46 67 90")
			elseif b == 3 then
				parse("spawnitem 10 67 90")
			elseif b == 4 then
				parse("spawnitem 73 67 90")
			elseif b == 5 then
				parse("spawnitem 85 67 90")
			elseif b == 6 then
				parse("spawnitem 48 67 90")
			elseif b == 7 then
				parse("spawnitem 82 67 90")
			end
		end
		elseif t == "MOD's weapons" then
		if lvlboolean(id,2) then
			if b == 1 then
				parse("spawnitem 3 53 98")
			elseif b == 2 then
				parse("spawnitem 47 53 98")
			elseif b == 3 then
				parse("spawnitem 91 53 98")
			elseif b == 4 then
				parse("spawnitem 46 53 98")
			elseif b == 5 then
				parse("spawnitem 85 53 98")
			elseif b == 6 then
				parse("spawnitem 49 53 98")
			elseif b == 7 then
				parse("spawnitem 72 53 98")
			elseif b == 8 then
				parse("spawnitem 82 53 98")
			end
		end
		elseif t == "Admin's weapons" then
		if lvlboolean(id,3) then
			if b == 1 then
				parse("spawnitem 3 61 108")
			elseif b == 2 then
				parse("spawnitem 10 61 108")
			elseif b == 3 then
				parse("spawnitem 47 61 108")
			elseif b == 4 then
				parse("spawnitem 90 61 108")
			elseif b == 5 then
				parse("spawnitem 91 61 108")
			elseif b == 6 then
				parse("spawnitem 69 61 108")
			elseif b == 7 then
				parse("spawnitem 85 61 108")
			elseif b == 8 then
				parse("spawnitem 89 61 108")
			elseif b == 9 then
				parse("spawnitem 82 61 108")
			end
		end
	end
end
edited 3×, last 15.09.12 01:53:16 pm

old Re: Code error.

Gaios
Reviewer Off Offline

Quote
1
2
3
4
5
6
zone = {
	sx = {44},
	sy = {87},
	fx = {75},
	fy = {111},
}
edited 3×, last 15.09.12 02:22:00 pm

old Re: Code error.

omg
User Off Offline

Quote
u used tonumber() on a string that doesnt have any numbers...

old Re: Code error.

EP
User Off Offline

Quote
@user omg: I think those entities are supposed to be 1..2..3.. so he converts those to integers.

old Re: Code error.

uaiek
User Off Offline

Quote
The function works fine. I have tested them (creating a new map with trigger_use entities which their names are 1,2,3,..,9). I used button 1-7 and they showed me menus correctly. But next, I used the 8th and 9th button, I saw your error in the console.
The problem is your menus. The menus table has only 7 menus, then when you call the 8th or more menu Lua showed the error because they are nil.

Maybe you made some mistakes making your map or forgot to add your new menus.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview