gametechmods

Robot Arena => General Support => Topic started by: Clickbeetle on August 23, 2011, 11:13:07 PM

Title: Change arenas mid-battle
Post by: Clickbeetle on August 23, 2011, 11:13:07 PM
Advanced Python question for Trovaner or Mad here.
 
I need to make an arena that changes into another arena at the start of the match (right after the countdown).  I know it's possible because I remember Mad (at least I think it was Mad) making an arena that cycles through all the stock arenas mid-battle.  However, I cannot find this arena anywhere.
 
I'm fairly certain the command used for this is Arenas.createArenaByName("Arena name").  That's what I used for the special SFTW AI to make it switch to the Epic Showdown arena automatically.  However, when I put that command in an arena, it crashes as soon as it's called.  I've tried Arenas.createArenaByName, self.createArenaByName, self.Arenas.createArenaByName, and even Arenas.SuperArena.createArenaByName.  Same result.
 
Here's my full .py in context:
 
Code: [Select]
from __future__ import generators
import plus
import Arenas
import random
import Hazards
import math
class Box(Arenas.SuperArena):
    "In space, no one can hear you scream... as your bot's components are brutally torn off with magic Python powers."
    name = "Ironbot Space"
    preview = "cube/cube_preview.bmp"
    game_types = ['DEATHMATCH', 'BATTLE ROYAL', 'TEAM MATCH']
    extent = (-16, 16, 16, -16)
    def __init__(self):
        Arenas.SuperArena.__init__(self, "Arenas/cube/ironbotspace.gmf")
        #plus.Arena.__init__(self, "")
        plus.setBackColor(0, 0, 0)
       
        degrad = 0.01745
        self.AddStaticCamera("Battle Veiw", (19.5, 15, 19.5), (50*degrad,225*degrad), 55*degrad)
        self.AddStaticCamera("High Flipper View", (-19.5, 45, -19.5), (48*degrad,45*degrad), 84*degrad)
        self.AddStaticCamera("Birds Eye View", (0, 45, 0), (90*degrad,0), 75*degrad)
        self.AddWatchCamera("Combat Cam", (-12, 8, 12), (16, 36, 65*degrad, 30*degrad))
        self.AddWatchCamera("Aerial Cam", (-19.5, 35, -19.5), (50, 60, 45*degrad, 60*degrad))
        self.AddWatchCamera("Ground Cam", (8, -5, -8), (15, 40, 75*degrad, 35*degrad))
        self.AddWatchCamera("Spectator Cam", (13, 15, 13), (6, 18, 45*degrad, 45*degrad))
 
        self.players = ()
       
    def Introduction(self): 
        self.LostComps0 = eval(open("Bot0_comps.txt").read())
        for id in self.LostComps0:
            plus.damage(0, id, 1000, plus.getLocation(0))
            plus.damage(0, id, 1000, plus.getLocation(0))
        self.LostComps1 = eval(open("Bot1_comps.txt").read())
        for id in self.LostComps1:
            plus.damage(1, id, 1000, plus.getLocation(1))
            plus.damage(1, id, 1000, plus.getLocation(1))
        yield 0
       
    def Activate(self, on):
        if on:
            self.players = plus.getPlayers()
            Arenas.createArenaByName("Containment Cube")
       
        Arenas.SuperArena.Activate(self, on)
       
Arenas.register(Box)

The arena itself is just empty space with a single grape crate in the middle (just so there is some object).  I'm using it for Ironbot so I can break off all the bots' components that were broken in previous fights via a list imported from txt files (this part works fine), have the broken parts fall into empty space during the countdown so they don't interfere with the fight, and then change the arena to the Containment Cube for the actual fight (this part doesn't work fine).
 
If anyone knows what I'm doing wrong, or if you know where to find that arena that switches arenas mid-battle, help is appreciated.
Title: Re: Change arenas mid-battle
Post by: Urjak on August 23, 2011, 11:25:55 PM
Did some searching and found this: https://gametechmods.com/forums/index.php/topic,2191.0.html (https://gametechmods.com/forums/index.php/topic,2191.0.html)

Is that what you were looking for?
Title: Re: Change arenas mid-battle
Post by: nightcracker on August 24, 2011, 08:29:01 AM
Now while I'm not aware of how Python in RA2 works, but my guess is that it crashes because you are causing an exception (by calling a non-existing function). This exception is unhandled so it will pass through and crash the application ultimately (this is bad coding on RA2's part).

Have you ever tried wrapping your code in a try-except block?

Code: [Select]
try:
    Arenas.createArenaByName("Containment Cube")
except: pass

And can you tell me, is it possible to get output from your Python scripts in RA2 in a console, like as in print("Hello world!") or something?
Title: Re: Change arenas mid-battle
Post by: Sage on August 24, 2011, 11:38:37 AM
NC, have you tried pressing F9 in game?
Title: Re: Change arenas mid-battle
Post by: nightcracker on August 24, 2011, 12:03:45 PM
I have, and I only get a blue box, with a number in it, I'm not sure whether you can print out to this box, and a textbox which is completely useless.
Title: Re: Change arenas mid-battle
Post by: Trovaner on August 24, 2011, 08:11:39 PM
Though I suspect that apanx used the same technique as me, I must say that my way is extremely sloppy and would require quite a few tweaks to the main arena PY and possibly GMF. I've also yet to figure out a way of getting the hammer's zone to work after the change. I would strongly suggest using Madiaba's method instead...

Similar to how Mad did the Matrix Arena, you can add the walls, floor, and ceiling separately (using self.AddXtra or self.AddXtraSound). All that needs to be loaded at the beginning are the startpoints, zones, and hinges. As long as you use some fancy camera work during the introduction, people won't even notice the difference between this method and the use of Arenas.createArenaByName. I suppose if you have your heart set on using Arenas.createArenaByName, I'll post the full instructions on how to mod everything (hopefully I'll know how to get the hammer working by then).

@nightcracker: You can either use a Gooey window or the FPS window (https://gametechmods.com/forums/index.php/topic,4694.msg200380.html#msg200380). They are both referred to as Debug Windows by the game but I personally prefer to use the FPS window.
Title: Re: Change arenas mid-battle
Post by: MassimoV on August 24, 2011, 08:23:39 PM
Not to get off topic but that arena posted Mad in the same topic is also pretty impressive.
Title: Re: Change arenas mid-battle
Post by: nightcracker on August 24, 2011, 09:02:51 PM
If I type in this in the debug window it will change arenas just fine:

Code: [Select]
Arenas.createArenaByName("Combat Arena")
Perhaps you don't need to call Activate by hand?

EDIT:

And if you do need to call Activate  by hand, try this instead:

Code: [Select]
Arenas.currentArena.Activate(self, on)
Title: Re: Change arenas mid-battle
Post by: nightcracker on August 24, 2011, 10:27:26 PM
For the lulz I wrote a little function that switches between arenas, just like in the video, including the temporary gravity lift.

Code: [Select]
import Arenas
import plus
import time

def switch_to_arena(arenaname, on):
plus.gravity(0, 10, 0)
origtick = Arenas.currentArena.Tick
start = time.clock()

def hooktick(*args):
now = time.clock()
if ((now-start) > 1):
switch_to_arena2(arenaname, on)
return origtick()

Arenas.currentArena.Tick = hooktick

def switch_to_arena2(arenaname, on):
Arenas.createArenaByName(arenaname)
Arenas.currentArena.Activate(on)
plus.gravity(0, -10, 0)
Title: Re: Change arenas mid-battle
Post by: Clickbeetle on August 27, 2011, 07:08:15 PM
All right I got it to work!  ...kind of sort of not really.  It switches arenas without crashing, but none of the hazards work and the bots start out inside the floor.  :(
 
I suspected this might happen if I used createArenaByName, but it was worth a try.  Fortunately, I have a backup plan.
 
Though I suspect that apanx used the same technique as me, I must say that my way is extremely sloppy and would require quite a few tweaks to the main arena PY and possibly GMF. I've also yet to figure out a way of getting the hammer's zone to work after the change. I would strongly suggest using Madiaba's method instead...

Similar to how Mad did the Matrix Arena, you can add the walls, floor, and ceiling separately (using self.AddXtra or self.AddXtraSound). All that needs to be loaded at the beginning are the startpoints, zones, and hinges. As long as you use some fancy camera work during the introduction, people won't even notice the difference between this method and the use of Arenas.createArenaByName.

I'll have to do that, which will mean some more .gmf editing, but at least I'm sure it will work.