HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: adding manaBar (with new DOM)  (Read 1798 times)

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
adding manaBar (with new DOM)
« on: Feb 01, 16, 09:55:52 PM »

Moderate tutorial (lots of parts)

This is an attempt to simplify adding manaBar to the player character (with the new DOM editors). It also adds in some max values to check against, rather than just a base value of 100. It also adds the bar to the GUIs. Compile/submit after each script.

Once the above is complete, the world will "need to reset" (for mobs) or "make new character" (for player/dev) to add the mana field.

The mana field will be used in some future tutorials, like making groups.
__________________________________________________________________
In the DOM, create a new (client side) field

name = E_manaPoints
description = mana
variable type = integer

create a new (client side) field
name = E_maxHP
description = max hit points
variable type = integer

create a new (client side) field
name = E_maxMP
description = max mana points
variable type = integer
__________________________________________________________________
In the DOM search area type points, this will show all fields with "points" as part of the data. Select E_hitPoints. In the references to the right, click E_CommonCharacter to highlight it, then click again to go to it. Pull the slider to the bottom to see the fields in the class. Pull the 2nd slider to the bottom to get to the bottom of list.

In the DOM, in E_CommonCharacter
add all 3 above fields to this class, then save
__________________________________________________________________
Now the sever side:

In the DOM, create a new (server side) field
name = E_manaPoints
description = mana
variable type = integer

click OK

Destination Field = E_manaPoints

create a new (server side) field
name = E_maxHP
description = max hit points
variable type = integer

click OK

Destination Field = E_maxHP

create a new (server side) field
name = E_maxMP
description = max mana points
variable type = integer

click OK

Destination Field = E_maxMP
__________________________________________________________________
In the DOM search area type points, this will show all fields with "points" as part of the data. Select E_hitPoints. In the references to the right, click E_CommonCharacter to highlight it, then click again to go to it. Pull the slider to the bottom to see the fields in the class. Pull the 2nd slider to the bottom to get to the bottom of list.

In the DOM, in E_CommonCharacter

add all 3 above fields to this class, click the Replicated checkBox on each, then save. The replicated checkbox sets the client side field when the server side field changes. __________________________________________________________________
Now to add the fields in the scripts.

In (client side) script E_nonplayerCharacterClassMethods

in function _OnReplicationFieldUpdated()

under - is "e_hitpoints"
add:

Code: [Select]
    is "e_manapoints"
      $LightweightEvents.raiseLightweightEvent(updateNode, "manaUpdated", None)
    .

In (client side) script E_playerCharacterClassMethods

under - is "e_hitpoints"
add:

Code: [Select]
    is "e_manapoints"
      $LightweightEvents.raiseLightweightEvent(updateNode, "manaUpdated", None)
    .
__________________________________________________________________

In (server side) script E_CharacterCreationSystemClassMethods

in method  HE_CCSCharacterActivated()

under - char.E_hitPoints = 100
add:

Code: [Select]
  char.E_manaPoints = 100
  char.E_MaxHP = 100
  char.E_MaxMP = 100

In (server side) script E_CommonCharacterClassMethods

in method  InitCommonCharacter()

under - me.E_hitPoints = 100
add:

Code: [Select]
  me.E_manaPoints = 100
  me.E_MaxHP = 100
  me.E_MaxMP = 100

in method  ApplyDeath()

under - me.E_hitPoints = 0
add:

Code: [Select]
  me.E_manaPoints = 0

in method  ApplyLife()

replace - me.E_hitPoints = 100
with:

Code: [Select]
  if me.E_MaxHP < 100
    me.E_MaxHP = 100
  .
  if me.E_MaxMP < 100
    me.E_MaxMP = 100
  .
  me.E_hitPoints = me.E_MaxHP     // set to max
  me.E_manaPoints = me.E_MaxMP    // set to max
__________________________________________________________________

Changes to original code to add in mana bar.

In (client side) script E_PlayerAccountClassMethods

replace:

Code: [Select]
        statusbar as NodeRef of Class E_StatusBar = FindGUIControlByName(0, "game.E_StatusBar")
        if statusbar != None
          destroynode(statusbar)
        .
        statusbar = CreateNodeFromPrototype("E_StatusBar")
        statusbar.build = true
        statusBar.position.x = 0
        statusBar.position.y = 19
        statusBar.SetName(addedNode.name)
        $LightweightEvents.addLightweightEventListener(addedNode, "nameUpdated", statusBar)
        $LightweightEvents.addLightweightEventListener(addedNode, "hpUpdated", statusBar)

with:

Code: [Select]
        E_StatusBarClassMethods:Start(addedNode)
__________________________________________________________________

In (client side) script E_StatusBarClassMethods

new functions and some changes, here is full script: (can replace with this)

Code: [Select]

// create main window
public function Start(addedNode as NodeRef of Class E_playerCharacter)
  statusbar as NodeRef of Class E_StatusBar = FindGUIControlByName(0, "game.E_StatusBar")
  if statusbar != None
    destroynode(statusbar)
  .
  statusbar = CreateNodeFromPrototype("E_StatusBar")
  statusbar.build = true
  statusBar.position.x = 0
  statusBar.position.y = 19
  statusBar.SetName(addedNode.name)

  // connect the value to show on the Bar
  $LightweightEvents.addLightweightEventListener(addedNode, "nameUpdated", statusBar)
  $LightweightEvents.addLightweightEventListener(addedNode, "hpUpdated", statusBar)
  $LightweightEvents.addLightweightEventListener(addedNode, "manaUpdated", statusBar)
.

method lightweightEventRaised(subject as ID, eventType as String, data as NodeRef)
  char as NodeRef of Class E_CommonCharacter = subject

  when eventType
    is "nameUpdated"
      if char != None
        me.SetName(char.name)
      .     
    .
    is "hpUpdated"
      if char != None
        me.SetHP(char.E_hitPoints)
      . 
    .
    is "manaUpdated"
      if char != None
        me.SetMP(char.E_manaPoints)
      . 
    .
  .
.

method SetName(name as String)
  nameLabel as NodeRef of Class GUILabel = FindGUIControlByName(me,"nameLabel")
  nameLabel.text = name
.

// Animation String fields
//1 field(string), the field on the GUIControl to such as size.x or defaultStatePresentation.color.a
//2 min(float) (this is NOT the start value for the animation. That is the current value of the field to which you are applying the min/max values)
//3 max(float)
//4 duration in seconds(float)
//5 repeat count(integer) (0=repeat infinitely, 1-n do animation that number of times)
//6 reverse(boolean), forward and backward(true), or just forward(false)
//7 curve(Enum of type interpolation curve), LINEAR, HOLD, EASE_IN, EASE_OUT, SMOOTH
//8 restore(boolean), restores the orignal value after the animation is finished
//9 delay in seconds(float), the amount of time to wait before actually starting the animation
//10 id(string), the ID of the animation

method SetHP(hp copies Integer)
  if hp < 0
    hp = 0
  .
  healthSlider as NodeRef of Class GUIControl = FindGUIControlByName(me, "healthPanel.healthSlider")
  healthSlider.removeAnimations()
  var size = -1.0 * hp

  animationString as String = "size.x,"+healthSlider.size.x+","+size+",.1,1,false,LINEAR,false,0,slide"
  GUIAnimation:addAnimation(healthSlider, "Interpolate", animationString)
.

method SetMP(mp copies Integer)
  if mp < 0
    mp = 0
  .
  manaSlider as NodeRef of Class GUIControl = FindGUIControlByName(me, "manaPanel.manaSlider")
  manaSlider.removeAnimations()
  var size = -1.0 * mp

  animationString as String = "size.x,"+manaSlider.size.x+","+size+",.1,1,false,LINEAR,false,0,slide"
  GUIAnimation:addAnimation(manaSlider, "Interpolate", animationString)
.
__________________________________________________________________

In (GUI xml) script E_StatusBar.xml

adding a new mana bar: (can replace with this)

Code: [Select]
<createControlType class='E_StatusBar' type='e_StatusBar' description='' treePath='' name="e_StatusBar" texture="\GUI\inventory_v3.dds" textureFilter="false" layer="game">
  <position x="279" y="63"/>
  <size x="172" y="56"/>
  <maximumSize x="2048" y="2048"/>
  <defaultStatePresentation>
    <position x="574" y="730"/>
    <size x="212" y="57"/>
  </defaultStatePresentation>
  <disabledStatePresentation>
    <position x="574" y="730"/>
    <size x="212" y="57"/>
  </disabledStatePresentation>
  <hoverStatePresentation>
    <position x="574" y="730"/>
    <size x="212" y="57"/>
  </hoverStatePresentation>
  <selectedStatePresentation>
    <position x="574" y="730"/>
    <size x="212" y="57"/>
  </selectedStatePresentation>
  <selectedDisabledStatePresentation>
    <position x="574" y="730"/>
    <size x="212" y="57"/>
  </selectedDisabledStatePresentation>
  <selectedHoverStatePresentation>
    <position x="574" y="730"/>
    <size x="212" y="57"/>
  </selectedHoverStatePresentation>
  <_label name="nameLabel" scale="1.299999952" text="Aplayername" textPadding="4" displayfont="GAMETEXT">
    <position y="-3.076923132"/>
    <size x="132.307693481" y="22.307693481"/>
    <defaultStatePresentation>
      <color r="1" g="1" b="1"/>
    </defaultStatePresentation>
  </_label>
  <_panel name="healthPanel">
    <position x="6" y="25"/>
    <size x="160" y="7"/>
    <defaultStatePresentation>
      <color r="0" g="0" b="0"/>
    </defaultStatePresentation>
    <autoCenter horizontal="true"/>
    <_panel name="healthSlider" dockMode="LEFT" texture="\GUI\status_bar_v3.dds">
      <size x="80" y="7"/>
      <defaultStatePresentation>
        <color b="0"/>
        <position x="33" y="342"/>
        <size x="164" y="12"/>
      </defaultStatePresentation>
      <autoCenter horizontal="true"/>
    </_panel>
  </_panel>
  <_panel name="manaPanel">
    <position x="6" y="39"/>
    <size x="160" y="7"/>
    <defaultStatePresentation>
      <color r="0" g="0" b="0"/>
    </defaultStatePresentation>
    <_panel name="manaSlider" dockMode="LEFT" texture="\GUI\status_bar_v3.dds">
      <size x="80" y="7"/>
      <defaultStatePresentation>
        <position x="34" y="342"/>
        <size x="148" y="11"/>
      </defaultStatePresentation>
      <autoCenter horizontal="true"/>
    </_panel>
  </_panel>
</createControlType>
__________________________________________________________________

In (GUI xml) script E_TargetStatusBar.xml

adding a new mana bar: (can replace with this)

Code: [Select]
<createControlType inheritFrom='e_StatusBar' class='E_targetStatusBar' type='E_targetStatusBar' description='' treePath='' name="E_targetStatusBar" inheritDisabledState="false" inheritSelectedState="false" inheritHoveringState="false">
  <position x="227" y="62"/>
  <defaultStatePresentation>
    <position x="560.952331543" y="710.476135254"/>
    <size x="225" y="78.809524536"/>
  </defaultStatePresentation>
  <disabledStatePresentation>
    <position x="561" y="711"/>
    <size x="225" y="76"/>
  </disabledStatePresentation>
  <hoverStatePresentation>
    <position x="561" y="711"/>
    <size x="225" y="76"/>
  </hoverStatePresentation>
  <selectedStatePresentation>
    <position x="561" y="711"/>
    <size x="225" y="76"/>
  </selectedStatePresentation>
  <selectedDisabledStatePresentation>
    <position x="561" y="711"/>
    <size x="225" y="76"/>
  </selectedDisabledStatePresentation>
  <selectedHoverStatePresentation>
    <position x="561" y="711"/>
    <size x="225" y="76"/>
  </selectedHoverStatePresentation>
  <set name="E_targetStatusBar.healthPanel.healthSlider">
    <defaultStatePresentation>
      <position x="33" y="342"/>
      <size x="147" y="11"/>
    </defaultStatePresentation>
  </set>
  <set name="E_targetStatusBar.manaPanel.manaSlider">
    <defaultStatePresentation>
      <color r="0"/>
      <position y="345"/>
      <size x="155" y="8"/>
    </defaultStatePresentation>
  </set>
</createControlType>
__________________________________________________________________

In (client side) script E_TargetCircleClassMethods

in Method E_UpdateTargetCircle
(adding code for a new mana bar) add 2 new lines where arrows are

Code: [Select]
    if realtarget != None
      AddAssociation(realtarget,"base_hard_association", statusbar)
      $LightweightEvents.addLightweightEventListener(realtarget, "nameUpdated", statusbar)
      $LightweightEvents.addLightweightEventListener(realtarget, "hpUpdated", statusbar)
      $LightweightEvents.addLightweightEventListener(realtarget, "manaUpdated", statusbar)    //<-- new line
      statusbar.SetHP(realtarget.E_hitPoints)
      statusbar.SetMP(realtarget.E_manaPoints)    //<-- new line
      statusbar.SetName(realtarget.name)
    else
__________________________________________________________________

Adding function to the mana bar. We will make the Heal use mana.

In (client side) script abHeal

add function

Code: [Select]
shared function GetManaUsed() as Integer
  return 12
.

In (server side) script abHeal

add function

Code: [Select]
shared function GetManaUsed() as Integer
  return 12
.

Replace function ApplyEffects() with:

Code: [Select]
shared function ApplyEffects( owner as NodeRef of Class E_CommonCharacter, target as NodeRef, ability as NodeRef of Class E_Ability )
  if target <> None
    where target is kindof E_CommonCharacter

      mana as Integer = GetManaUsed()
      owner.AdjustMana(-mana, ability)

      if target == None
        healthDelta as Integer = ( owner.E_MaxHP - owner.E_hitPoints )      // calculate base damage
        target.AdjustHealth( healthDelta, owner, ability, false )             // apply damage
      else
        healthDelta as Integer = ( target.E_MaxHP - target.E_hitPoints )      // calculate base damage
        target.AdjustHealth( healthDelta, owner, ability, false )             // apply damage
      .
    .
  .
.
__________________________________________________________________

In (server side) script E_CommonCharacterClassMethods

in function E_regenTimer_tick()

under  HPAmount as Integer = 1
add these 2 lines:

Code: [Select]
  MPAmount as Integer = 1

  me.E_manaPoints = MiscUtils:Min( me.E_manaPoints + MPAmount, me.E_MaxMP )

under method AdjustHealth()
add:

Code: [Select]
// apply mana used
method AdjustMana( manaDelta as Integer, ability as NodeRef of Class E_Ability )
  me.E_manaPoints = MiscUtils:Min( me.E_manaPoints + manaDelta, me.E_MaxMP )
.
__________________________________________________________________

In (server side) script E_nonPlayerCharacterClassMethods

under method AdjustHealth()
add:

Code: [Select]
method AdjustMana( manaDelta as Integer, ability as NodeRef of Class E_Ability )
  parentClass::AdjustMana( manaDelta, ability )    //  Let the parent class handle the actual Adjust amount.
.
« Last Edit: Feb 01, 16, 10:01:36 PM by Thazager »
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685