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

Author Topic: Distance to Target (displayed)  (Read 1701 times)

Thazager

  • General Accounts
  • *
  • Posts: 1155
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Distance to Target (displayed)
« on: Oct 28, 14, 10:37:32 PM »

Moderate scripting

This tutorial will pop a small window above the E_abilityBar showing the distance (D) and meters (M) to that current target. It will update as the target moves around. All client side script.


In the DOM, create a new (client side) field
name = myTarget
type = noderef

_______________________________________________________________
In the DOM, locate (client side) class E_AbilityBar
add a field to the class, myTarget

_______________________________________________________________
In the DOM, create a new (client side) class
name = TMP_Range
archtype = guicontrol

add a parent to the class, _GUIBaseWindow
add a field to the class, myTarget
add a field to the class, myTimer      // already in DOM

click open script

In new (client side) script TMP_Range

Code: [Select]
// create the dist GUI
shared function Start()
  var main = getMainWindowClass()
  if main <> None
    DestroyNode( main )
  .
  main = CreateNodeFromPrototype("TMP_Range")
  main.build = true
  MiscUtils:CenterWindow(main)

  var place = getAbilityBarClass()
  main.position.y = place.position.y - 40   // adjust posY
.

// get range value
public function getRangeDistance(target as NodeRef)
  where target is kindof HBNode
    var main = getAbilityBarClass()
    main.myTarget = target

    targetPos as Vector3
    getNodePosition(target, targetPos)

    var player = GetPlayerCharacterNode()
    ownerPos as Vector3
    getNodePosition(player, ownerPos)

    var win = getMainWindowClass()
    if win == None
      Start()   // make the window
      win = getMainWindowClass()
    .

    var range = VectorLength( targetPos - ownerPos )
    win.RangeFound(range)
  .
.

// remove the distance label
public function removeRangeDistance()
  var main = getMainWindowClass()
  if main <> None
    DestroyNode( main )
  .
.

// show range value
method RangeFound(range as Float)
  meters as Float = range * 10

  var lbl = me.getDistLabel()
  lbl.text = "D= "+FormatFloat(range,2)
  lbl = me.getMeterLabel()
  lbl.text = "M= "+FormatFloat(meters,1)

  if( me.myTimer.timerState == ON )
    me.myTimer.stop()
  .
  me.myTimer.fireRate = 00:00:00.5
  me.myTimer.start()
.

// timer to show updates - movement
method myTimer_tick()
  if( me.myTimer.timerState == ON )
    me.myTimer.stop()      // stop timer
  .
  var main = getAbilityBarClass()
  target as NodeRef of Class E_CommonCharacter = main.myTarget
  getRangeDistance(target)
.

//==================================================================================================================
// get main window class for variables
function getMainWindowClass() as NodeRef of Class tmp_range
  win as NodeRef of Class tmp_range = FindGuiControlByName(None,"game.TMP_Range")
  return win
.

// get ability window class for variables
function getAbilityBarClass() as NodeRef of Class E_AbilityBar
  win as NodeRef of Class E_AbilityBar = FindGuiControlByName(None,"game.E_AbilityBar")
  return win
.

// get label for showing value
method getDistLabel() as NodeRef of Class GUILabel
  return FindGuiControlByName(me, "dist")
.

// get label for showing value
method getMeterLabel() as NodeRef of Class GUILabel
  return FindGuiControlByName(me, "meter")
.


_______________________________________________________________
In new (XML) script TMP_Range

Code: [Select]
<createControlType class='tmp_range' type='TMP_Range' description='' treePath='' name="TMP_Range" owner="0" textureFilter="false" allowMove="false" layer="game" resizeable="ALL" scrollable="VERTICAL">
  <size x="50" y="40"/>
  <maximumSize x="2048" y="2048"/>
  <defaultStatePresentation>
    <color g="0" b="0"/>
  </defaultStatePresentation>
  <hoverStatePresentation>
    <color g="0" b="0"/>
  </hoverStatePresentation>
  <selectedHoverStatePresentation>
    <color r="0" g="0" b="0" a="0"/>
    <size x="0" y="0"/>
  </selectedHoverStatePresentation>
  <_label name="dist" dockMode="TOP" text="D=" displayfont="SMALLTEXT" justification="LEFT">
    <size x="50"/>
  </_label>
  <_label name="meter" dockMode="BOTTOM" text="M=" displayfont="SMALLTEXT" justification="LEFT">
    <size x="50"/>
  </_label>
</createControlType>

_______________________________________________________________
In (client side) script E_TargetCircleClassMethods

under  (around line 36)
       if realtarget != None

Code: [Select]
      TMP_RangeClassMethods:getRangeDistance(realtarget)

above
    else


in method E_StopTarget

Code: [Select]
  TMP_RangeClassMethods:removeRangeDistance()

« Last Edit: May 30, 15, 11:04:30 PM by Thazager »
Logged

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: Distance to Target (displayed)
« Reply #1 on: Nov 10, 14, 12:16:00 AM »

What is the reason for getting the distance from the server, and not using the data the client already has?
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1155
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Distance to Target (displayed)
« Reply #2 on: Dec 17, 14, 12:27:02 AM »

I tried a few things to try and get the client only side working without any luck.

I changed getRangeDistance() to this, and the timer stopped ticking. It works 1 time to get the value, then stops.

Code: [Select]
// get range value
public function getRangeDistance(target as NodeRef of Class HBnode)
  var main = getAbilityBarClass()
  main.myTarget = target

  targetPos as Vector3
  getNodePosition(target, targetPos)

  var player = GetPlayerCharacterNode()
  ownerPos as Vector3
  getNodePosition(player, ownerPos)

  var range = VectorLength( targetPos - ownerPos )
  RangeFound(range)
.



edit:
Just tried it again, and seems to be working.
« Last Edit: Dec 17, 14, 12:50:24 AM by Thazager »
Logged

Prometheus2012

  • General Accounts
  • *
  • Posts: 664
    • View Profile
    • Exile-Online
Re: Distance to Target (displayed)
« Reply #3 on: Dec 22, 14, 11:25:36 AM »

This is a nice feature and tracks distance accurately and well :)