HeroEngine Developers > Developer Created Tutorials

Basic mob spawner

(1/2) > >>

Thazager:
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: ---// 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")
.


--- End code ---

_______________________________________________________________
In new (XML) script TMP_Mobs


--- Code: ---<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>

--- End code ---
_______________________________________________________________
In (server side) E_NPCClassMethods add:


--- Code: ---// 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())
  .
.

--- End code ---

_______________________________________________________________
In (client side) script E_PlayerAccountClassMethods under the chatwindow


--- Code: ---        TMP_MobsClassMethods:Start()

--- End code ---

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

Voarsh:

--- Quote from: Thazager 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.

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


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

--- End code ---


In server side E_NPCClassMethods add:


--- Code: ---// 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" )
.

--- End code ---

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

--- End quote ---

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

Thazager:
added MobButton in the above tutorial.

H3R013:
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 ?

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

how to fix it ?

Navigation

[0] Message Index

[#] Next page

Go to full version