Forum

> > CS2D > Scripts > Scope position error
Forums overviewCS2D overview Scripts overviewLog in to reply

English Scope position error

4 replies
To the start Previous 1 Next To the start

old Scope position error

MikuAuahDark
User Off Offline

Quote
oh no, im fail again on lua script. this time is i want to create a cursor coordinate at x and y near cursor. only can if using a scope. but it shows error when i press rightclick and says
1
LUA ERROR: sys/lua/new  2.lua:18: attempt to perform arithmetic on field '?' (a nil value)
what's wrong with this script below?
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
-- Scope position by Rian2_idih
function array(id,di)
	local lol = {}
	for dih = 1,id do
		lol[dih] = di
	end
	return lol
end
posx = array(32,0)
posy = array(32,0)
positionx = array(32,0)
positiony = array(32,0)
attacks = array(32,0)
snipers = {31,33,34,35,36,37}


function sethud(id)
	parse("hudtxt2 "..id.." 38 \""..posx[id].."\" "..(positionx[id]-20).." "..positiony[id][2])
	parse("hudtxt2 "..id.." 39 \""..posy[id].."\" "..positionx[id].." "..(positiony[id][2]-20))
end

addhook("always","chk")
function chk()
	for _, id in ipairs(player(0,"table")) do
		if attacks[id]>0 then
			reqcld(id,0)
			reqcld(id,2)
			timer(75,"sethud",id)
		end
	end
end

addhook("clientdata","set")
function set(id,mode,x,y)
	if mode==0 then
		positionx[id]=x
		positiony[id]=y
	end
	if mode==2 then
		posx[id]=x
		posy[id]=y
	end
end

addhook("attack2","weaponmode")
function weaponmode(id,mode)
	weapon=player(id,"weapontype")
	for _, l in ipairs(snipers) do
		if weapon==l then
			attacks[id]=mode
		end
	end
end

old Re: Scope position error

EngiN33R
Moderator Off Offline

Quote
user MikuAuahDark has written
1
2
3
4
function sethud(id)
	parse("hudtxt2 "..id.." 38 \""..posx[id].."\" "..(positionx[id]-20).." "..positiony[id][2])
	parse("hudtxt2 "..id.." 39 \""..posy[id].."\" "..positionx[id].." "..(positiony[id][2]-20))
end

user MikuAuahDark has written
1
positiony[id][2]


Your positiony is just a table, not a nested one, so change all instances of
1
positiony[id][2]

to

1
positiony[id]

old Re: Scope position error

MikuAuahDark
User Off Offline

Quote
thanks. but when i press rightclick on AWP, it shows this error
1
LUA ERROR: sys/lua/new  2.lua:18: attempt to perform arithmetic on field '?' (a nil value)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview