Forum

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

English table value

4 replies
To the start Previous 1 Next To the start

old table value

DX
User Off Offline

Quote
LUA ERROR: sys/lua/bul.lua:42: attempt to concatenate global 'pistol' (a table value)
-> sys/lua/bul.lua:42: in function <sys/lua/bul.lua:33>
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end

pistol_ammo=initArray(32)
ar_ammo=initArray(32)
rpg_ammo=initArray(32)
pistol = {1,2,3,4,5,6}

function contains(table, element)
     for _, value in pairs(table) do
          if value == element then
          return true
          end
     end
return false
end

addhook("say","says")
function says(id,say)
	if (say=="hi") then
		pistol_ammo[id]=pistol_ammo[id]+1000
		ar_ammo[id]=ar_ammo[id]+1000
		rpg_ammo[id]=rpg_ammo[id]+1000
	end
end

addhook("ms100","alw")
function alw(id)
	for _, id in pairs(player(0,'table')) do
		if player(id,"team")==2 then
			parse('hudtxt2 '..id..' 0 "©255255255pistol ammo: '..pistol_ammo[id]..' " 13 140')
			parse('hudtxt2 '..id..' 1 "©255255255rifle ammo: '..ar_ammo[id]..' " 13 160')
			parse('hudtxt2 '..id..' 2 "©255255255rpg ammo: '..rpg_ammo[id]..' " 13 180')
		end

		if pistol_ammo[id]==0 then
			parse("setammo "..id.." "..pistol.." 0 0 ")
		end

		if pistol_ammo[id]>0 then
			parse("setammo "..id.." "..pistol.." 1 0 ")
		end

		if ar_ammo[id]==0 then
			parse("setammo "..id.." 32 0 0 ")
		end

		if ar_ammo[id]>0 then
			parse("setammo "..id.." 32 1 0 ")
		end

		if rpg_ammo[id]==0 then
			parse("setammo "..id.." 46 0 0 ")
		end

		if rpg_ammo[id]>0 then
			parse("setammo "..id.." 46 1 0 ")
		end
	end
end

addhook("attack","att")
function att(id,mode)
	if contains(pistol,player(id,"weapon")) then
		pistol_ammo[id]=pistol_ammo[id]-1
	end

	if player(id,"weapontype")==32 then
		ar_ammo[id]=ar_ammo[id]-1
	end

	if player(id,"weapontype")==46 then
		rpg_ammo[id]=rpg_ammo[id]-1
	end
end

old Re: table value

VADemon
User Off Offline

Quote
This error means you try to turn a table
pistol = {1,2,3,4,5,6} (in Line 12)
to a string. In Lua this is not normally allowed to insert a table into string (unless you use tostring() or metatables)

Tell us what you wanted to do in Line 42? Only set ammo for pistol weapons that the player has?

old Re: table value

Cebra
User Off Offline

Quote
i'd recommend you to phrase a question instead of just inserting the error-text.

Anyway, the problem in your code is, that
pistol
ist a table, but you try to use it like a variable.
maybe you have a look at this

edit: user VADemon: was faster

old Re: table value

DX
User Off Offline

Quote
user VADemon has written
Tell us what you wanted to do in Line 42? Only set ammo for pistol weapons that the player has?

yes

old Re: table value

VADemon
User Off Offline

Quote
Line 41-47:
1
2
3
4
5
6
7
8
9
10
11
for pi = 1, #pistol do
				local pistolId = pistol[pi]
				-- set ammo for every existing pistol ID
				if pistol_ammo[id]==0 then
				   parse("setammo "..id.." "..pistolId.." 0 0 ")
				end

				if pistol_ammo[id]>0 then
				   parse("setammo "..id.." "..pistolId.." 1 0 ")
				end
			end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview