Forum

> > CS2D > Scripts > "use" hook, script runs well.
Forums overviewCS2D overview Scripts overviewLog in to reply

English "use" hook, script runs well.

23 replies
Page
To the start Previous 1 2 Next To the start

old Re: "use" hook, script runs well.

Yazir
User Off Offline

Quote
Yeah, but how to put inventory array inside, and how to acces it?

@edit
What i have to change in this piece of 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
function lootresp() -- func join
	lootarr = {}
	local i = 1
	repeat
	local xpix = tonumber(map("xsize")) *32 
	local ypix = tonumber(map("ysize")) *32
	local randomx = math.floor(math.random(1,xpix/32))*32-16
	local randomy = math.floor(math.random(1,ypix/32))*32-16
	lootarr[i] = {x = randomx, y = randomy}
	image("gfx/movecs2d/dayz/loot.PNG",randomx,randomy,1)
	print(i)
	i = i + 1
	until (i > 35)
end

function lootop(id,x,event,data,x,y) -- func use
	local i = 1
	repeat
	if (x == lootarr[i][x]) then
		if (y == lootarr[i][y]) then
			menu(id, "test,test2,lol")
		end
	end
	until (i == #lotarr) -- error is here
end
I want to open menu when i press e on decal that has x,y wrote to array.
Error:
lua:106: attempt to index global 'lotarr' (a nil value)
lua:106 is at until (i == #lotarr)
edited 2×, last 28.01.15 02:30:38 pm

old Re: "use" hook, script runs well.

Bowlinghead
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function lootresp() -- func join
     lootarr = {}
     local i = 1 -- Note: You set i = 1
     repeat
     local xpix = tonumber(map("xsize")) *32 
     local ypix = tonumber(map("ysize")) *32
     local randomx = math.floor(math.random(1,xpix/32))*32-16
     local randomy = math.floor(math.random(1,ypix/32))*32-16
     lootarr[i] = {x = randomx, y = randomy}
     image("gfx/movecs2d/dayz/loot.PNG",randomx,randomy,1)
     print(i)
     i = i + 1 -- You set i = i+1
     until (i > 35)
end
Actually you have an array called lootarr.
You try to put random x and y datas into lootarr[i].
I think you want to have it like this:
In the first time you call this function i=1, in the second time you call this function i=2, and so on.
When you call the function again then you set i to 1 again (line 3!). The i=i+1 doesn´t affect anything, you know?

Fix it like this:
Write this on the start of your script
1
i = 1
And delete the 3rd line of your code completly!
Warning: Use another variable name if "i" is used multiple times!

More >


Code not tested

old Re: "use" hook, script runs well.

Yazir
User Off Offline

Quote
Everything got fixed, works and now i have even more functions. But however, i have last one final question (i hope). Is there any way to configure the attack speed, mag ammo and any other stuff of weapon, i know that it's possible to change weapon for every player id?
edited 1×, last 29.01.15 03:14:19 am

old Re: "use" hook, script runs well.

Bowlinghead
User Off Offline

Quote
Should be hard but possible to realise that!

For mag ammo you can watch the players weapon name and then just count.
For the attack spped simply strip the weapon between each shot to make a delay. If you want higher attack speed then I don´t know (Maybe adding a bullet picture that acts like a bullet).
(Use the cs2d lua hook attack and cs2d lua hook attack2 hooks)
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview