Forum

> > CS2D > Scripts > Respawn delay error: interval is empty
Forums overviewCS2D overview Scripts overviewLog in to reply

English Respawn delay error: interval is empty

3 replies
To the start Previous 1 Next To the start

old Respawn delay error: interval is empty

MikuAuahDark
User Off Offline

Quote
hi i want to create script again but it error and says
LUA ERROR: sys/lua/respawndelay.txt:32: bad argument #2 to 'random' (interval is empty)
when im killed and when im join team it says
LUA ERROR: sys/lua/respawndelay.txt:32: attempt to get length of field '?' (a nil value)
how to fix it?? here's my code:
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
-- Respawn Delay by Rian2_idih

if tonumber(game("sv_gm"))~=0 then

respawn = 5

parse("mp_respawndelay "..respawn)

pos = {
	[1] = {},
	[2] = {},
}

function definepos()
	for x,y in pairs(entitylist(1)) do
		table.insert(pos[1],{x,y})
	end
	for x,y in pairs(entitylist(2)) do
		table.insert(pos[2],{x,y})
	end
end

definepos()

addhook("team","startteam")
function startteam(id)
	spawndelay(id)
end

addhook("die","spawndelay")
function spawndelay(id)
	x = pos[player(id,"team")][math.random(1,#pos[player(id,"team")])][1]
	y = pos[player(id,"team")][math.random(1,#pos[player(id,"team")])][2]
	t = 1000*respawn
	timer(t,"parse","spawnplayer "..id.." "..(x*32).." "..(y*32))
end

end
as you can see, line 32 is
x = pos[player(id,"team")][math.random(1,#pos[player(id,"team")])][1]

old Re: Respawn delay error: interval is empty

Flacko
User Off Offline

Quote
If entities are not found for a reason I don't know, the call to math.random will look like this:
1
math.random(1,0)
Therefore, throwing an error. Maybe you're switching your team to spectator?
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview