Forum

> > CS2D > Scripts > How can I restart round if only 1 Enemy is left?
Forums overviewCS2D overview Scripts overviewLog in to reply

English How can I restart round if only 1 Enemy is left?

18 replies
To the start Previous 1 Next To the start

old Re: How can I restart round if only 1 Enemy is left?

ohaz
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
addhook("die", "checkAlive")
addhook("leave", "checkAlive")

function checkAlive()
	count = #player(0,"team1living") + #player(0,"team2living");
	if (count == 1) do
		parse("sv_restartround 0")
	end
end

old Re: How can I restart round if only 1 Enemy is left?

Bowlinghead
User Off Offline

Quote
Thanks for your answer.
But why it doesn't work for me? (No Error)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("die", "checkAlive")
addhook("leave", "checkAlive")
function checkAlive()
	count = #player(0,"tableliving")
	for id=1,32-count do
		if kill[id]==3 then
			spec[id]=0
			kill[id]=0
			if count == 1 then
				parse("restart")
			end
		end
	end
end

The "kill[id]" is a countup for every dead.
If you die your "kill[id]" is set +1.
If your "kill[id]" is 3 then the "spec[id]" goes 1. If spec[id] is 1 then you can't join a team.

old Re: How can I restart round if only 1 Enemy is left?

Kel9290
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
addhook("die", "checkAlive")
addhook("leave", "checkAlive")
function checkAlive()
     count = #player(0,"tableliving")
	local ii = 32 - count
     for id=1,ii do
          if kill[id]==3 then
               spec[id]=0
               kill[id]=0
               if count == 1 then
                    parse("restart")
               end
          end
     end
end
maybe this

old Re: How can I restart round if only 1 Enemy is left?

Bowlinghead
User Off Offline

Quote
user Banaan has written
1
2
3
4
5
addhook("die", "RestartRoundOnDie")

function RestartRoundOnDie()
	if #player(0, "tableliving") == 1 then parse("restart") end
end


The Killed Death did a Script with the same action like yours.
But what I search is a script, if everyone player dies 3 times and only 1 is alive then the round will be restart!
I tried soo much things

old Re: How can I restart round if only 1 Enemy is left?

Loooser
User Off Offline

Quote
here is the answer:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
addhook("die", "die")

function die()
count=#player(0,"team1")+#player(0,"team2")
if count== 1 then
	for i = 1,32 do
	if player(i,"exists") and player(i,"team")==0 then
	if math.random(1,2)==1 then --every spectator gets a random team
		parse("maket "..i)
	else
		parse("makect "..i)
	end
	 parse("restart") --instead of restart i would reset other stuff like it was before starting the game
	 
end
end
btw you forgot to tell that everyone who dies 3 times gets spectator

old Re: How can I restart round if only 1 Enemy is left?

Banaan
User Off Offline

Quote
Oh sorry I was too lazy to read the entire topic

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
addhook("die", "RestartRoundOnDie")
addhook("join", "ResetDeaths")
addhook("leave", "WasILiving")
addhook("startround", "ResetDeaths")

local d = {}

function ResetDeaths(id) d[id] = 0 end

function WasILiving(id)
	if #player(0, "tableliving") == 1 then
		for _, p in pairs(player(0, "table")) do
			if d[p] ~= 3 then return 0 end
		end
		parse("restart")
	end
end

function RestartRoundOnDie(id)
	d[id] = d[id] + 1
	if d[id] == 3 then
		if #player(0, "tableliving") == 1 then
			for _, p in pairs(player(0, "table")) do
				if d[p] ~= 3 then return 0 end
			end
			parse("restart")
		end
	end
end

What this does is exactly what you asked (at least how I understood it), but I doubt it's what you want:

If every player has died exactly three times, and only 1 player is still alive, restart the round.

Note that the death count is reset on round start.

old Re: How can I restart round if only 1 Enemy is left?

Bowlinghead
User Off Offline

Quote
More >


I want to do exactly what you say! But it doesnt work But there is no Error or something like that.
I think, its not possible to do what I try to do ...

old Re: How can I restart round if only 1 Enemy is left?

Banaan
User Off Offline

Quote
How about this?

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
addhook("die", "RestartRoundOnDie")
addhook("join", "ResetDeaths")
addhook("leave", "WasILiving")
addhook("startround", "ResetAllDeaths")

local d = {}

function ResetDeaths(id) d[id] = 0 end
function ResetAllDeaths() for _, p in pairs(player(0, "table")) do d[p] = 0 end end

function WasILiving(id)
	if #player(0, "tableliving") == 1 then
		for _, p in pairs(player(0, "table")) do
			if d[p] ~= 3 then return 0 end
		end
		parse("restart")
	end
end

function RestartRoundOnDie(id)
	d[id] = d[id] + 1
	if d[id] == 3 then
		if #player(0, "tableliving") == 1 then
			for _, p in pairs(player(0, "table")) do
				if not player(p, "exists") and d[p] ~= 3 then return 0 end
			end
			parse("restart")
		end
	end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview