Page 1 of 1

Forcing a map restart - (c) Rookie One :P

Posted: Sun Apr 10, 2005 7:06 pm
by Rookie One.pl
Hi,

I needed this done for a mod of mine. Figured it out, so I thought I can share it. ;)

Code: Select all

// blah blah blah whatever stuff you've got here
thread force_map_restart

force_map_restart:
	// first, cancel all votes that might be in progress
	for (local.i = 1; local.i <= $player.size; local.i++)
		$player[local.i] vote no
	// now, pick the last player to call a vote (just in case it's a dedicated server, as $player[1] cannot call a vote in such situation)
	for (local.i = $player.size; local.i > 0; local.i--)
	{
		if ($player[local.i] != NIL && $player[local.i] != NULL)
			break
	}
	// g_allowvote workaround
	local.allowvote = int(getcvar(g_allowvote))
	setcvar "g_allowvote" 1
	// call the restart map vote
	$player[local.i] callvote restart map
	setcvar "g_allowvote" local.allowvote
	// force all players to vote for yes
	for (local.i = 1; local.i <= $player.size; local.i++)
		$player[local.i] vote yes
end
The only flaw is that it sometimes will leave g_allowvote set to 1 if the map restarts immediately after calling the vote, but that can be fixed by using a game variable and checking it at the beginning of the round. ;) I'm too lazy to post that code, too, though, so you'll have to do that on your own, I'm afraid. :P

Hope it's of any use for someone... ;)

Rookie One

Posted: Sun Apr 10, 2005 8:11 pm
by jv_map
Not bad :)

Posted: Sun Apr 10, 2005 8:48 pm
by Bjarne BZR
Nice one. Looks pretty stable.

Posted: Tue Apr 12, 2005 12:49 am
by mefy
Another way to force a restart is to do this:

Code: Select all

	local.manager = spawn DM_Manager
	local.manager doroundtransition
This will reset the team scores and the map time just as if you typed "restart" in the console.

Posted: Tue Apr 12, 2005 6:40 am
by Bjarne BZR
Well I must say mefy's way looks a little simpler and cleaner :)

Posted: Tue Apr 12, 2005 12:42 pm
by Rookie One.pl
But it's a bit less reliable. ;)

Posted: Tue Apr 12, 2005 3:01 pm
by Bjarne BZR
Rookie One.pl {sfx} wrote:But it's a bit less reliable. ;)
How so?

Posted: Tue Apr 12, 2005 6:28 pm
by Rookie One.pl
Well, I tried this method, and sometimes it just wouldn't do the restart, sometimes it wouldn't reset the team scores etc.

Come on, do you think I'd make an effort and write this script if I could just do it like that? ;)

Posted: Tue Apr 12, 2005 6:43 pm
by Bjarne BZR
Rookie One.pl {sfx} wrote:Come on, do you think I'd make an effort and write this script if I could just do it like that? ;)
Well I can only speak for myself, and I didnt know any of the 2 methods before this thread :)

Posted: Wed Apr 13, 2005 3:00 am
by mefy
You can verify it's working by checking the value of these cvars:

g_tempmaptime
g_tempalliesscore
g_tempaxisscore

I remember the score shown on the hud wouldn't be reset to 0 but the actual score and time as shown by these cvars would be reset. That's also why a team's score could go over the fraglimit (on the hud) without the map ending because their true score was less.