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

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

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

Post 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
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Not bad :)
Image
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Post by Bjarne BZR »

Nice one. Looks pretty stable.
Admin .MAP Forums
Image
Head above heels.
mefy
Corporal
Posts: 33
Joined: Tue Oct 21, 2003 2:57 am

Post 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.
New Gametypes for Medal of Honor
Capture-The-Flag | Freeze-Tag | Demolition
www.planetmedalofhonor.com/mefy
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Post by Bjarne BZR »

Well I must say mefy's way looks a little simpler and cleaner :)
Admin .MAP Forums
Image
Head above heels.
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

But it's a bit less reliable. ;)
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Post by Bjarne BZR »

Rookie One.pl {sfx} wrote:But it's a bit less reliable. ;)
How so?
Admin .MAP Forums
Image
Head above heels.
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post 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? ;)
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Post 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 :)
Admin .MAP Forums
Image
Head above heels.
mefy
Corporal
Posts: 33
Joined: Tue Oct 21, 2003 2:57 am

Post 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.
New Gametypes for Medal of Honor
Capture-The-Flag | Freeze-Tag | Demolition
www.planetmedalofhonor.com/mefy
Post Reply