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

Author Topic: Basic mob spawner  (Read 1823 times)

Thazager

  • General Accounts
  • *
  • Posts: 1129
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Basic mob spawner
« on: Jul 20, 13, 11:48:05 PM »

This tutorial uses a button to add mobs to the area. It spawns 4 monkeytoks at the character position. We had 300 mobs spawned in a minute to test features. You can easily change the spawn rate.

From the basic window tutorial
Make basic window here. This is a base window and will be used in many of my Tutorials. It uses the GUI pics from textures that all engines have. This can be skipped if you have the basic window already from another tutorial.

Make basic button here. This will also be used in many of my tutorials.

_______________________________________________________________
In the DOM, create a new (client side) class
name = TMP_Mobs
archtype = guicontrol
add a parent to the class, TMP_Window

click open script

In new (client side) script TMP_Mobs

Code: [Select]
// create mob window
shared function Start()
  var win = getMobsClass()
  if win <> None
    DestroyNode( win )
  .
  win = CreateNodeFromPrototype("TMP_Mobs")
  win.build = true
  MiscUtils:centerWindow(win)
.

// which button chosen
method onMouseClick(args references Class GUIMouseEvent)
  target as NodeRef of Class GUIControl = args.source
  when target.name
    is "mobButton"
//      call server E_NPCClassMethods:CreateMobs()   // after server script is made, uncomment this line
    .
  .
.

//=================================================================================================
function getMobsClass() as NodeRef of Class TMP_Mobs
  return FindGUIControlByName(None, "game.TMP_Mobs")
.


_______________________________________________________________
In new (XML) script TMP_Mobs

Code: [Select]
<createControlType inheritFrom='TMP_Window' class='TMP_Mobs' type='TMP_Mobs' description='' treePath='' name="TMP_Mobs">
  <size x="150" y="50"/>
  <set name="TMP_Mobs.BGpanel">
    <size x="142" y="42"/>
  </set>
  <_label name="title" text="Monkeytoks" dropShadowAlpha="1" justification="CENTER">
    <defaultStatePresentation>
      <color r="1" g="0" b="0"/>
    </defaultStatePresentation>
    <autoCenter horizontal="true"/>
  </_label>
  <tmp_button name="mobButton">
    <position x="45" y="25"/>
    <size x="60"/>
    <autoCenter horizontal="true"/>
    <set name='TMP_Mobs.mobButton.text' attribute='text' value="Make 4"/>
  </tmp_button>
</createControlType>
_______________________________________________________________
In (server side) E_NPCClassMethods add:

Code: [Select]
// player called - make mobs
untrusted function CreateMobs()
  acct as NodeRef of Class E_playerAccount = SYSTEM.REMOTE.client
  char as NodeRef of Class E_playerCharacter = acct.GetMyChar()
  $CHAT.ChatWorld( "game", char.name+" is making Mobs" )

  loop i from 1 to 4
    var npc = $NPC._CreateSimpleHECharacter( "monkeytok", false )
    npc._UpdatePosition(char.GetPosition())
  .
.

_______________________________________________________________
In (client side) script E_PlayerAccountClassMethods under the chatwindow

Code: [Select]
        TMP_MobsClassMethods:Start()

Created using info from $NPC in the wiki   (link wont function properly with $ in it)
« Last Edit: Jun 04, 18, 02:48:58 PM by Thazager »
Logged

Voarsh

  • General Accounts
  • *
  • Posts: 56
    • View Profile
Re: Basic mob spawner
« Reply #1 on: Nov 20, 13, 02:06:02 PM »

This tutorial uses a button to add mobs to the area. It spawns 4 monkeytoks at the character position. We had 300 mobs spawned in a minute to test features. You can easily change the spawn rate.

In your client side button script, in your method onMouseClick() add:

Code: [Select]
      is "MobButton"
        acct as NodeRef of Class E_playerAccount = GetAccountID()
        call server E_NPCClassMethods:CreateMobs(acct)
      .


In server side E_NPCClassMethods add:

Code: [Select]
// test function
untrusted function CreateMobs( accountID as ID )
  acct as NodeRef of Class E_playerAccount = accountID
  char as NodeRef of Class E_playerCharacter = acct.GetMyChar()

  loop i from 1 to 4
    var npc = $NPC._CreateSimpleHECharacter( "monkeytok", false )
    npc._UpdatePosition(char.GetPosition())
  .
  $CHAT.ChatPlayer( acct, "", "making Mobs" )
.

Created using info from $NPC in the wiki   (link wont function properly with $ in it)

Hi, I wasn't able to find onMouseClick().
Can you be more specific? What Client script?
Thanks
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1129
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Basic mob spawner
« Reply #2 on: Nov 20, 13, 03:59:14 PM »

added MobButton in the above tutorial.
« Last Edit: May 30, 15, 09:28:40 PM by Thazager »
Logged

H3R013

  • General Accounts
  • *
  • Posts: 13
    • View Profile
Re: Basic mob spawner
« Reply #3 on: May 31, 18, 05:36:58 AM »

i got up to the part where u make the TMP_Mobs and it gives errors when i try to compile it >>

how do i fix it ?
« Last Edit: May 31, 18, 05:38:34 AM by H3R013 »
Logged

H3R013

  • General Accounts
  • *
  • Posts: 13
    • View Profile
Re: Basic mob spawner
« Reply #4 on: May 31, 18, 06:15:55 AM »

ok so i ignored those errors and did the rest and tried to compile them but it gave this >>

how to fix it ?
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1129
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Basic mob spawner
« Reply #5 on: May 31, 18, 10:04:39 AM »

Ok, each error is depending on the other section of code to be working.

To start, in TMP_Mobs client side script, comment out the "call server" line using //

Code: [Select]
//      call server E_NPCClassMethods:CreateMobs()

this will allow the client side script to compile, which in turn will allow the server side script to compile.

Then remove the comments for the line above.

Code: [Select]
      call server E_NPCClassMethods:CreateMobs()

and compile the client side code again.


Adding the parent TMP_Window to the class TMP_Mobs, will allow the use of win.build to work.  (as long as you have already made the TMP_Window)
Logged

H3R013

  • General Accounts
  • *
  • Posts: 13
    • View Profile
Re: Basic mob spawner
« Reply #6 on: May 31, 18, 07:32:15 PM »

i tried doing that both ways with or without that line and it keeps giving these errors either way >>

How do i fix it ?
Logged