Forum

> > CS2D > Scripts > Setweapon; table value
Forums overviewCS2D overview Scripts overviewLog in to reply

English Setweapon; table value

4 replies
To the start Previous 1 Next To the start

old Setweapon; table value

Powermonger
User Off Offline

Quote
Hello again guys.

I have this problem with command setweapon.

When "flashlight" is OFF, players can use their weapons.
When it's ON, only knife is allowed. ( like Doom 3 )

Here is the script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
addhook("serveraction","D3serva")
function D3serva(id,sa)
	if sa == 3 then
		if flashlight == 0 then
			for i = 1,32 do
			if player(i,"exists") then
				weapon[i] = player(i,"weapontype")
				parse("setweapon "..i.." 50")
			end
			end
			flashlight = 1
			parse("trigger black")
		elseif flashlight == 1 then
			for i = 1,32 do
			if player(i,"exists") then
				parse("setweapon "..i.." "..weapon[i])
			end
			end
			flashlight = 0
			parse("trigger black")
		end
	end
end
When flashlight is turned ON, every players current weapon is saved to table weapon[id].
When flashlight is turned OFF, setweapon will set their previous weapon from table weapon[id].

I think the problem is that setweapon can't read table values, but how can I avoid this?

I tried to use local value
1
2
local wp = weapon[i]
parse("setweapon "..i.." "..wp)
but it didn't help : /

Please help me when you have time.
Thanks beforehand!

old Re: Setweapon; table value

DarkLight66
User Off Offline

Quote
I think you could use the actual game flashlight instead of a server action. I remember there was a cs2d lua function that let you get a table that contains every weapon of a player. However, after the 0.1.2.0 update, that function doesn't appear anywere in the info.txt file or on the cs2d help website, but it was called playerweapons(id), you can use it to get a table with every weapon of the person's id.

old Re: Setweapon; table value

Happy eyes
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
weapons={}
for a=1,32 do
	weapons[a]={}
end
function strip_weps(id)
	for n,w in pairs(playerweapons(id)) do
		table.insert(weapons[id],w)
		parse('strip '..id..' '..w)
	end
end

function give_weps(id)
	for n,w in pairs (weapons[id]) do
		parse('equip '..id..' '..w)
	end
	weapons[id]={}
end

Use these functions to strip all weapons but knife and to give weapons back to players (Link with flashlight or serveraction hook)

old Re: Setweapon; table value

Powermonger
User Off Offline

Quote
user Happy eyes has written
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
weapons={}
for a=1,32 do
	weapons[a]={}
end
function strip_weps(id)
	for n,w in pairs(playerweapons(id)) do
		table.insert(weapons[id],w)
		parse('strip '..id..' '..w)
	end
end

function give_weps(id)
	for n,w in pairs (weapons[id]) do
		parse('equip '..id..' '..w)
	end
	weapons[id]={}
end

Use these functions to strip all weapons but knife and to give weapons back to players (Link with flashlight or serveraction hook)

Thanks man, that script is working!


... But it's not exactly what I wanted.

I forgot to mention that I have also this hook:
1
2
3
4
5
6
7
8
addhook("select","D3flash")
function D3flash(id)
	if flashlight == 1 then
		if player(id,"weapontype") ~= 50 then
			parse("setweapon "..id.." 50")
		end
	end
end
This part prevents player to change weapon.
( Sorry that I didn't bring this up at the topic. )

And so, I only want players weapons switched to their weapon when the flashlight was turned off.

Is it possible to get this ...
1
parse("setweapon "..i.." "..weapon[i])
... work?

old Re: Setweapon; table value

Kisses
User Off Offline

Quote
1
2
3
4
5
oldparse = parse
function parse(data)
print(data)
oldparse(data)
end

Use this debug code working, tested √
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview