Pick a random spectator
8 replies



30.06.21 01:02:26 am
Basically what I'm looking for is this:
A player kill another player (1v1), the victim goes to spectator (easy part, already done). Now the script should pick a random player in spectator and join that empty team. Also it would be good to not select the latest "victim".
A player kill another player (1v1), the victim goes to spectator (easy part, already done). Now the script should pick a random player in spectator and join that empty team. Also it would be good to not select the latest "victim".

CS2DBR @ Comunidade Brasileira de CS2D | https://cs2d.com.br
set sv_specmode 2 then set sv_specmode 0,system will give you a random spec
CS2D Chinese Station(CS2DCN) Founder。Chinese language translation submitter!As you see,We are the second largest player group of CS2D! | Our Discord
What?
how changing specmode will make the game select a player and make him join an available team?

CS2DBR @ Comunidade Brasileira de CS2D | https://cs2d.com.br
maybe something like this? (untested code)
but you have to care take about the team joining.
The code can break quite simple
but you have to care take about the team joining.
The code can break quite simple
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
if wrapper~=true then dofile("sys/lua/wrapper.lua") end
addhook("kill", "_k")
function _k(kid, vid, weapon, x, y, kobj, assist)
playerlist=player(0,"table")
if #playerlist > 2 then
tempteam = player(vid,"team")
makespec(vid)
randid = 0
repeat
randid = playerlist[math.random(#playerlist)]
until randid ~= vid and player(randid,"team") == 0
if tempteam == 1 then
maket(randid)
else
makect(randid)
end
end
end
addhook("kill", "_k")
function _k(kid, vid, weapon, x, y, kobj, assist)
playerlist=player(0,"table")
if #playerlist > 2 then
tempteam = player(vid,"team")
makespec(vid)
randid = 0
repeat
randid = playerlist[math.random(#playerlist)]
until randid ~= vid and player(randid,"team") == 0
if tempteam == 1 then
maket(randid)
else
makect(randid)
end
end
end
loading...
@
Cebra: nice, it's working! And how about this: pick a player in order (in spectators) instead random, so every player will be in a queue or something. Also a message displaying how many players remaining until ur turn.

CS2DBR @ Comunidade Brasileira de CS2D | https://cs2d.com.br
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
26
27
28
29
30
31
32
33
34
35
36
37
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
--untested
if wrapper~=true then dofile("sys/lua/wrapper.lua") end
function initArray(m,v)
if v == null then v = 0 end
local array={}
for i=1, m do
array[i]=v
end
return array
end
function removeFirstElement(t)
for i =2, #t, 1 do
t[i-1] = t[i]
end
t[#t] = nil
end
queue = {}
addhook("kill", "_k")
function _k(kid, vid, weapon, x, y, kobj, assist)
tempteam = player(vid,"team")
makespec(vid)
queue[#queue + 1]=vid
if tempteam == 1 then
maket(queue[0])
else
makect(queue[0])
end
removeFirstElement(queue)
for pos, id in ipairs(queue) do
msg2(id, "Queue pos: "..pos)
end
end
if wrapper~=true then dofile("sys/lua/wrapper.lua") end
function initArray(m,v)
if v == null then v = 0 end
local array={}
for i=1, m do
array[i]=v
end
return array
end
function removeFirstElement(t)
for i =2, #t, 1 do
t[i-1] = t[i]
end
t[#t] = nil
end
queue = {}
addhook("kill", "_k")
function _k(kid, vid, weapon, x, y, kobj, assist)
tempteam = player(vid,"team")
makespec(vid)
queue[#queue + 1]=vid
if tempteam == 1 then
maket(queue[0])
else
makect(queue[0])
end
removeFirstElement(queue)
for pos, id in ipairs(queue) do
msg2(id, "Queue pos: "..pos)
end
end
loading...
@
Cebra:

Code:
1
2
3
4
2
3
4
LUA ERROR: sys/lua/wrapper.lua:182: attempt to concatenate local 'player' (a nil value)
-> sys/lua/wrapper.lua:182: in function 'makect'
-> sys/lua/autorun/1v1.lua:31: in function <sys/lua/autorun/1v1.lua:24>
-> in Lua hook 'kill', params: 1, 2, 50, 304, 592, 0, 0
-> sys/lua/wrapper.lua:182: in function 'makect'
-> sys/lua/autorun/1v1.lua:31: in function <sys/lua/autorun/1v1.lua:24>
-> in Lua hook 'kill', params: 1, 2, 50, 304, 592, 0, 0
CS2DBR @ Comunidade Brasileira de CS2D | https://cs2d.com.br
my fault
line 28 to 32 has to be replaced with

line 28 to 32 has to be replaced with
Code:
1
2
3
4
5
2
3
4
5
if tempteam == 1 then
maket(queue[1])
else
makect(queue[1])
end
maket(queue[1])
else
makect(queue[1])
end
loading...
@
Cebra:
now when killing the victim, he goes to spectators and come back to the team he was instead of joining the next spectator in the queue.
btw, people are added to the queue when joining the server? and removed when they leave? maybe the problem is there?
Ye, it seems nobody will fix the script. Dead.

now when killing the victim, he goes to spectators and come back to the team he was instead of joining the next spectator in the queue.
btw, people are added to the queue when joining the server? and removed when they leave? maybe the problem is there?
Ye, it seems nobody will fix the script. Dead.

edited 3×, last 03.07.21 06:04:16 pm
CS2DBR @ Comunidade Brasileira de CS2D | https://cs2d.com.br



