Add in a Release box in the UI that shows up upon Death

From Multiverse

Jump to: navigation, search

The following tutorial explains how to make a release box in the User Interface pop up upon death. The box contains a button that sends the /release command when clicked. I have also added in a small extra piece that causes the player to get half of their health back upon releasing (after clicking on the button).

Contents

Constructing the user interface

Firstly, you will want to get the box working. There are two files which make up the interface part. You will need to make a xml file called Deathbox.xml and a python script file called Deathbox.py. These files should be in the folder where the rest of the .xml and .py file are located for the interface (often in the interface/FrameXML folder in the asset repository).

Note: if you are using the --default_repository flag for your client then the Deathbox.xml and .py files will need to be placed inside the asset repository you are using for your Multiverse Tools.

FrameXML file

In the Deathbox.xml file you want the following code:

<Ui>
  <Script file="Deathbox.py"/>
      <Frame name="DeathFrame" 
             inherits="MvBasicFrame" 
             frameStrata="HIGH" 
             toplevel="true" 
             movable="true" 
             enableMouse="true" 
             hidden="true">
	<Size>
	    <AbsDimension x="250" y="80"/>
	</Size>
        <Anchors>
	    <Anchor point="CENTER">
              <Offset>
                <AbsDimension x="0" y="158"/>
              </Offset>
            </Anchor>
	</Anchors>
	<Layers>
	    <Layer level="ARTWORK">
        	<Texture name="$parentTexture" file="Interface\MvChat\Mv-ChatFrame-Interior">
		    <Anchors>
			<Anchor point="TOPLEFT" relativeTo="$parent">
			    <Offset>
				<AbsDimension x="5" y="-5"/>
			    </Offset>
			</Anchor>
			<Anchor point="BOTTOMRIGHT" relativeTo="$parent">
			    <Offset>
				<AbsDimension x="-5" y="5"/>
			    </Offset>
			</Anchor>
		    </Anchors>
		</Texture>
		<FontString name="DeathText" inherits="NormalFont" justifyH="CENTER" hidden="true">
		   <Size>
		      <AbsDimension x="230" y="32"/>
		   </Size>
	           <Anchors>
	              <Anchor point="CENTER" relativeTo="$parent">
	                 <Offset>
		            <AbsDimension x="0" y="10"/>
	                 </Offset>
	              </Anchor>
	           </Anchors>
               </FontString>
	    </Layer>
	 </Layers>
      <Frames>
         <Button name="ReleaseButton" text="Release">
            <size>
	       <AbsDimension x="120" y="25"/>
	    </size>
	    <Anchors>
	       <Anchor point="TOPLEFT" relativeTo="$parent">
 	          <Offset>
		     <AbsDimension x="65" y="-50"/>
		  </Offset>
	       </Anchor>			
               <Anchor point="BOTTOMRIGHT" relativeTo="$parent"> 
	           <Offset>
		      <AbsDimension x="-65" y="15"/>
		   </Offset>
	       </Anchor>		
	    </Anchors>
	   <NormalText inherits="NormalFont" justifyH="CENTER" justifyV="BOTTOM"/>
	      <Layers>
                 <Layer>
                    <Texture file="Interface\MvButtons\Mv-Panel-Button-Up">
                       <HighlightTexture alphaMode="ADD" 
                                         file="Interface\MvButtons\Mv-Panel-Button-Highlight"/>
                       <PushedTexture file="Interface\MvButtons\Mv-Panel-Button-Down"/>
                       <Size><AbsDimension x="120" y="25"/></Size>
                       <Anchors>
                          <Anchor point="TOPRIGHT">    
                             <Offset><AbsDimension x="0" y="0"/></Offset> 
                          </Anchor>
                       </Anchors>
                    </Texture>
                 </Layer>
             </Layers>
             <Scripts language="python">
	        <OnClick> ReleaseButton_OnClick(this) </OnClick>
             </Scripts>
	   </Button>
       </Frames>
    <Scripts language="python">
      <OnLoad>
    DeathFrame_OnLoad(this)      
      </OnLoad>
      <OnEvent>
    DeathFrame_OnEvent(this, args)      
      </OnEvent>
    </Scripts>
  </Frame>
</Ui>

Script

Then in the Deathbox.py file, add the following code:

def DeathFrame_OnLoad(frame):
    frame.RegisterEvent("PROPERTY_deadstate")
    if MarsUnit.UnitIsDead("player") == True:
        DeathFrame.Show()
    DeathFrame_OnShow(frame)
    
def ReleaseButton_OnEnter(name, button):
    MenuBarTooltip.SetPoint("BOTTOMRIGHT", button.Name, "TOPLEFT")
    MenuBarTooltipTextLeft1.SetText(name)
    MenuBarTooltip.Show()

def ReleaseButton_OnLeave(button):
    MenuBarTooltip.Hide()
    
def ReleaseButton_OnClick(button):
    targetOid = ClientAPI.GetPlayerObject().OID
    ClientAPI.Network.SendTargetedCommand(targetOid, "/release")
    ClientAPI.Network.SendTargetedCommand(targetOid, "/ability deathHeal")
    
def DeathFrame_OnShow(frame):
    DeathText.SetText("You have died. Click release to come back alive.")
    DeathText.Show()

def DeathFrame_Update(frame):
    if MarsUnit.UnitIsDead("player") == True:
        if DeathFrame.IsVisible():
            pass
        else:
            DeathFrame.Show()
    else:
        if DeathFrame.IsVisible():
            DeathFrame.Hide()
        
def DeathFrame_OnEvent(frame, args):
    DeathFrame_Update(frame)
        
def ToggleDeathFrame():
    if DeathFrame.IsVisible():
        DeathFrame.Hide()
    else:
        DeathFrame.Show()

Then add the following line to the bottom of the toc file being used (by default this is mars.toc):

Deathbox.xml

Now login to the game and see that first the user interface is showing up, then try to die and see if the box comes up. Then click on the release button and see what happens. If it doesn't work then check over the code and make sure it's all in right. If you can't seem to get it working at all, email andrew@doomsberg.com (at this stage it wont restore HP, just bring you back).

Making it restore health upon releasing

Now add the code to make the restore health ability work. This part is more of a hack and later on it may not be needed as MV will add in a better method of restoring health upon releasing. The following code goes into the mv-home/config/common/ability_db.py file:

effect = HealEffect("heal half effect")
effect.setMinInstantHeal(50)
effect.setMaxInstantHeal(50)
Mars.EffectManager.register(effect.getName(), effect)

ability = EffectAbility("deathHeal")
ability.setTargetType(MarsAbility.TargetType.SELF)
ability.setActivationEffect(Mars.EffectManager.get("heal half effect"))
Mars.AbilityManager.register(ability.getName(), ability)

You can pretty much put that code anywhere in the file (after line 15). If you want it to heal more (say full) then adjust the setMin and setMax heal values.

Personal tools