Author Topic: Change arenas mid-battle  (Read 1846 times)

Offline Clickbeetle

  • *
  • Posts: 3375
  • Rep: 21
  • In Soviet Russia, bugs stomp YOU!
  • Awards BOTM Winner
    • View Profile
    • Beetle Bros site
    • Awards
Change arenas mid-battle
« 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.

To lack feeling is to be dead, but to act on every feeling is to be a child.
-Brandon Sanderson, The Way of Kings

Offline Urjak

  • *
  • Posts: 2753
  • Rep: 6
  • Shell Spinner King
    • http://www.youtube.com/wa
    • View Profile
    • Awards
Re: Change arenas mid-battle
« Reply #1 on: August 23, 2011, 11:25:55 PM »
Did some searching and found this: https://gametechmods.com/forums/index.php/topic,2191.0.html

Is that what you were looking for?
Any comments would be appreciated. :D

Offline nightcracker

  • *
  • Posts: 505
  • Rep: 7
  • Script kiddo
    • View Profile
    • NC Labs
    • Awards
  • Skype: orsonpeters
Re: Change arenas mid-battle
« Reply #2 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?

Offline Sage

  • *
  • Posts: 6182
  • Rep: 11
  • RA2 Wizard & GTM's Favorite Stock Builder 2015
  • Awards Sage's Favorite BOTM Winner
    • View Profile
    • Awards
Re: Change arenas mid-battle
« Reply #3 on: August 24, 2011, 11:38:37 AM »
NC, have you tried pressing F9 in game?
You got my vote for RA2 Wizard. Always and forever.

Offline nightcracker

  • *
  • Posts: 505
  • Rep: 7
  • Script kiddo
    • View Profile
    • NC Labs
    • Awards
  • Skype: orsonpeters
Re: Change arenas mid-battle
« Reply #4 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.

Offline Trovaner

  • *
  • Posts: 1222
  • Rep: 32
    • View Profile
    • Awards
Re: Change arenas mid-battle
« Reply #5 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. They are both referred to as Debug Windows by the game but I personally prefer to use the FPS window.

Offline MassimoV

  • I Move Weight
  • *
  • Posts: 8929
  • Rep: 24
  • I make rap for people of Serbia
    • MassimoVTV
  • Awards BOTM Winner
    • View Profile
    • Mourning Glory
    • Awards
  • See profile for gamer tags: Yes
  • Skype: myhandsarefood
Re: Change arenas mid-battle
« Reply #6 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.

Offline nightcracker

  • *
  • Posts: 505
  • Rep: 7
  • Script kiddo
    • View Profile
    • NC Labs
    • Awards
  • Skype: orsonpeters
Re: Change arenas mid-battle
« Reply #7 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)

Offline nightcracker

  • *
  • Posts: 505
  • Rep: 7
  • Script kiddo
    • View Profile
    • NC Labs
    • Awards
  • Skype: orsonpeters
Re: Change arenas mid-battle
« Reply #8 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)

Offline Clickbeetle

  • *
  • Posts: 3375
  • Rep: 21
  • In Soviet Russia, bugs stomp YOU!
  • Awards BOTM Winner
    • View Profile
    • Beetle Bros site
    • Awards
Re: Change arenas mid-battle
« Reply #9 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.

To lack feeling is to be dead, but to act on every feeling is to be a child.
-Brandon Sanderson, The Way of Kings