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

Author Topic: Fixing mob agro  (Read 62 times)

Thazager

  • General Accounts
  • *
  • Posts: 1109
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Fixing mob agro
« on: Apr 10, 18, 07:23:58 AM »

Easy tutorial (fix for current code).

I noticed when a player moves by any of the mobs, that they don't attack the player. So, I tried a few things including checking the server side classes on the Node that the mob has as a target. What it does is simply check for either player account or player character. (it doesn't hurt to check both)

In server side script E_AiAgentClassMethods:

In method _AgentBrainTick()


change this:

Code: [Select]
    foreach target in targets
      //  GetTargetsInSphere hands back _playerAccount nodes, but we want the character node
      where target is kindof _PlayerAccount
        pc = target.GetMyChar()
        if pc != None and pc.IsAttackable()
          add back pc to pcTargets
        .
      .
    .

to this:

Code: [Select]
    foreach target in targets
      //  GetTargetsInSphere hands back _playerAccount nodes, but we want the character node
      where target is kindof _PlayerAccount
        pc = target.GetMyChar()
        if pc != None and pc.IsAttackable()
          add back pc to pcTargets
        .
      .
      where target is kindof E_playerCharacter
        if target.IsAttackable()
          add back target to pcTargets
        .
      .
    .

by adding these lines:

Code: [Select]
      where target is kindof E_playerCharacter
        if target.IsAttackable()
          add back target to pcTargets
        .
      .


Here is the server side function for checking classes on the "target" node that the above target is pointing to. It prints the classes in the chat window at bottom of editor.

In server side script MiscUtils:

add:

Code: [Select]
untrusted function getClasses(target as NodeRef)
  GetNodeClasses(target)
.
public function GetNodeClasses(target as NodeRef)
  println("** Server classes on target **")
  if target <> None
    values as List of String = GetClassesOnNode(target)
    foreach val in values
      println("S class on targ "+val)
    .
  .
.

 This can be called from client using:

Code: [Select]
   call server MiscUtils:getClasses(target)

 or from the server using:  (after the 1st line in foreach loop)

Code: [Select]
  MiscUtils:GetNodeClasses(target)
Logged
Heroes and Villains Lead programmer/scripter
Exile Online Lead programmer/scriptor

Thazager

  • General Accounts
  • *
  • Posts: 1109
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Fixing mob agro
« Reply #1 on: Apr 17, 18, 11:02:28 PM »

In the same area of AI work, I found the E_AiStateWander to have some errors also. I made changes to one method that was sending bad Y positions for the character to try and reach (flying or tunneling?).

In server script E_AiStateWanderClassMethods:

change method GotRandomPoint() from:

Code: [Select]
method GotRandomPoint(point as Vector3)
  me.PathToPoint(point, me._GetAiAgent())
.

to this:

Code: [Select]
method GotRandomPoint(point as Vector3)
  char as NodeRef = me._GetAiAgent()
  where char is kindof E_AiAgent
    var origin = char.E_StartPosition
    origin.x = point.x
    origin.z = point.z
    me.PathToPoint(origin, char)
  .
.

add: If the last line in method DoWander() is commented out, uncomment it, as this is the line to move the npcs.

  me.PathToPoint( point, char )


Also with the Skippydebug, this might help stop the freeze. Place it where you print out values with $Chat or println().

Code: [Select]
  $skippy.skippyInteger += 1       // debug to keep from Spam freeze
  if $skippy.skippyInteger > 20
    return
  .

and in method _EnterAiState() add:

Code: [Select]
  $skippy.skippyInteger = 0       // init to start again

« Last Edit: Apr 18, 18, 11:26:49 AM by Thazager »
Logged
Heroes and Villains Lead programmer/scripter
Exile Online Lead programmer/scriptor