Forum

> > CS2D > Scripts > Lua question - error plz help!
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua question - error plz help!

6 replies
To the start Previous 1 Next To the start

old Lua question - error plz help!

Infinite Rain
Reviewer Off Offline

Quote
LUA ERROR: At line 4 bad argument #1 to 'player' (number expected, got nil)

1
2
3
4
5
function btp(id,sx,sy,ex,ey,mode)
   local prp
   if mode==1 then prp="" elseif mode==2 then prp="tile" end
   return (player(id,"exists") and player(id,prp.."x")>sx and player(id,prp.."x")<ex and player(id,prp.."y")>sy and player(id,prp.."y")<ey)
end

old Re: Lua question - error plz help!

J4x
User Off Offline

Quote
1
2
3
4
5
function btp(i,sx,sy,ex,ey,mode)
local prp
if mode==1 then prp="" elseif mode==2 then prp="tile" end
return (player(i,"exists") and player(i,prp.."x")>sx and player(i,prp.."x")<ex and player(i,prp.."y")>sy and player(i,prp.."y")<ey)
end
maybe this?

old Re: Lua question - error plz help!

Infinite Rain
Reviewer Off Offline

Quote
I always gott error maybe problrm in whole 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
function btp(id,sx,sy,ex,ey,mode)
   local prp
   if mode==1 then prp="" elseif mode==2 then prp="tile" end
   return (player(id,"exists") and player(id,prp.."x")>sx and player(id,prp.."x")<ex and player(id,prp.."y")>sy and player(id,prp.."y")<ey)
end

dofile("sys/lua/configs.lua")

function initArray(m)
	local array = {}
	for i = 1, m do
		array[i] = 0
	end
return array
end

oldx=initArray(32)
oldy=initArray(32)
timer=initArray(32)

for i=1,#house do
	house[i].var=initArray(32)
end

addhook("minute","addtime")
function addtime()
	for i=1,#house do
		if not house[i].owner==nil then
			timer[i]=timer[i]+1
		end
		if timer[i]==1440 then
			house[i].owner=nil
		end
	end
end

addhook("move","housecheck")
function housecheck(id,x,y,mode)
	for i=1,#house do
		if btp(x1,y1,x2,y2,2) then
			if not house[i].owner==player(id,"usgn") then
				msg2(id,"Its not your house!")
				parse("setpos "..id.." "..oldx.." "..oldy)
			end
		else
			oldx=x
			oldy=y
		end
	end
end

old Re: Lua question - error plz help!

JONY
User Off Offline

Quote
1
if btp(x1,y1,x2,y2,2) then

you send 5 parameters, function btp gets 6 parameters => 1 parameter is nil. Do this:
1
if btp(id,x1,y1,x2,y2,2) then
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview