Forum

> > CS2D > Scripts > Why it won't work?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Why it won't work?

5 replies
To the start Previous 1 Next To the start

old Why it won't work?

NanuPlayer
User Off Offline

Quote
What is the wrong with this script?

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
mode = {}
parse("mp_hudscale 1")

for _,e in pairs(entitylist()) do
	if entity(e.x,e.y,"typename") == "Env_Hurt" and entity(e.x,e.y,"int0") == -100 and entity(e.x,e.y,"int1") == 2 then
		local x=e.x
		local y=e.y
		local x2=(e.x-1)+entity(e.x,e.y,"int2")
		local y2=(e.y-1)+entity(e.x,e.y,"int3")
		
		table.insert(safe,{x,x2,y,y2})
	end
end

function init_array(length,mode)
	local array = {}
	for i = 1,length do 
		array[i] = mode	
	end
	return array
end

player_safe = init_array(32,false)

addhook("movetile","movetile")
addhook("hit","hit")

function hit(id)
	if player_safe[id] then
		return 1
	end
	return 0
end

function movetile(id,x,y)
	for i in ipairs(safe) do
		if x >= safe[i][1] and x <= safe[i][2] and y >= safe[i][3] and y <= safe[i][4] then
			player_safe[id] = true
			mode[id] = "SAFE ZONE"
			break
		else
			player_safe[id] = false
			mode[id] = "NOT IN SAFE!"
		end
	end	
	update_hud(id)
end

function update_hud(id)
		parse("hudtxt2 "..id.." 1 "..mode[id].." 50 425 1")
end

addhook("join","join1")
function join1(id)
mode[id] = "NOT IN SAFE!"
end

old Re: Why it won't work?

Yates
Reviewer Off Offline

Quote
Could be line 5, 11 or 18.

My bet goes to 18. If not then definitely line 11.

old Re: Why it won't work?

Yates
Reviewer Off Offline

Quote
You have
mode
defined at the top which could conflict with the
init_array
function and its
mode
parameter.

safe
is not defined as far as I can see. Can't insert into a table that doesn't exist eyy. Just add it at the top:
1
safe = {}

Line 5 is me just thinking the entity isn't set to these strict statements. It's not really a code error. Double check it matches by spamming success messages inside the statement.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview