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

Author Topic: online player search window  (Read 1267 times)

Thazager

  • General Accounts
  • *
  • Posts: 1155
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
online player search window
« on: Jul 04, 15, 08:46:38 PM »

Moderate tutorial

This will display a window showing which characters are online, with their name, area, and level of character. It's a basic script without sorting. It shows some client server communication.

__________________________________________________________________
Compile and submit the client code, then the server code. Then remove comments marked with //*** from 2 lines in client script, then compile and submit client script again.

__________________________________________________________________
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_SocialWindow
archtype = guicontrol

add a parent to the class, TMP_Window

click open script

In new (client side) script TMP_SocialWindow

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

// toggle Window on/off
public function windowToggle()
  var win = getSocialClass()
  if win <> None
    DestroyNode(win)    // remove large window if there
  else
    start()
  .
.

// when window is made, check server for players
method OnControlBuild()
//***  call server TMP_SocialServerClassMethods:getSearchInfo()
.

//=================================================================================================
// which button chosen
method onMouseClick(args references Class GUIMouseEvent)
  target as NodeRef of Class GUIControl = args.source
  when target.name
    is "update"
//***      call server TMP_SocialServerClassMethods:getSearchInfo()
    .
  .
.

// scroll for window, if we have that many in list
method onMouseWheel(args references Class GUIMouseEvent)
  var pannel = getSearch()
  if pannel <> None
    where pannel is kindof GUIScrollablePanel
      if args.wheelDelta > 0
        var newOffset = pannel.offset.y - 20    // 1 line
        if newOffset < 0
          newOffset = 0
        .
        if newOffset > (pannel.area.y - pannel.size.y)
          newOffset = pannel.area.y - pannel.size.y
        .
        pannel.offset.y = newOffset
      else
        var newOffset = pannel.offset.y + 20    // 1 line
        if newOffset < 0
          newOffset = 0
        .
        if newOffset > (pannel.area.y - pannel.size.y)
          newOffset = pannel.area.y - pannel.size.y
        .
        pannel.offset.y = newOffset
      .
    .
  .
.

//=================================================================================================
// display the info from server
// get main list of players
remote function ShowInfo(whoList as List of Class _whoData)
  panel as NodeRef of Class GUIPanel
  lbl as NodeRef of Class GUILabel
  var win = getSearch()

  // clear all names
  foreach child in win.children
    DestroyNode(child)
  .

  // create our list
  i as Integer = 1
  foreach who in whoList
    panel = CreateNodeFromPrototype("tmp_searchPanel")
    panel.build = true
    panel.name = "tmp_searchPanel"+i        // make sure names are diff
    lbl = FindGUIControlByName(panel, "name")
    lbl.text = who._whoCharacterName
    lbl = FindGUIControlByName(panel, "area")
    lbl.text = who._whoAreaName+"("+who._whoAreaInstanceID+")"
    add back panel to win.children
    i += 1
  .
  lbl = getAmount()
  lbl.text = "Players: " + whoList.length
.

// display the info from server
// update info for this player - name
remote function UpdateInfo(name as String, level as String)
  panel as NodeRef of Class GUIPanel
  lbl as NodeRef of Class GUILabel
  var win = getSearch()

  i as Integer = 1
  foreach child in win.children
    where child is kindof GUIPanel
      lbl = FindGUIControlByName(win, "tmp_searchPanel"+i+".name")
      if lbl.text = name
        lbl = FindGUIControlByName(win, "tmp_searchPanel"+i+".level")
        lbl.text = level+"    "
      .
      i += 1
    .
  .
.

//=================================================================================================
// get main class
function getSocialClass() as NodeRef of Class TMP_SocialWindow
  return FindGUIControlByName(None, "game.TMP_SocialWindow")
.

// pointers
function getSearch() as NodeRef of Class GUIControl
  return FindGUIControlByName(None, "game.TMP_SocialWindow.search.clientarea")
.

function getAmount() as NodeRef of Class GUILabel
  return FindGUIControlByName(None, "game.TMP_SocialWindow.amount")
.

__________________________________________________________________
In the DOM, create a new (server side) class
name = TMP_SocialServer
archtype = data

click open script

In new (server side) script TMP_SocialServer

Code: [Select]
// gather player info - name, level, area
untrusted remote function getSearchInfo()
  // asking player info
  acct as NodeRef of Class E_playerAccount = SYSTEM.REMOTE.client
  char as NodeRef of Class E_playerCharacter = acct.GetMyChar()
  call area 0 instance 0 getWorldList(acct)
.

// make sure on world server to gather info
remote function getWorldList(acct as ID)
  var whoList = World_GetListOfEveryoneOnline()                     // get main list of players
  call client acct TMP_SocialWindowClassMethods:ShowInfo(whoList)   // display it for client

  // get searching player info
  areaSend as ID
  instanceSend as ID
  WhereIsPlayer(acct, areaSend, instanceSend)

  // goto each area to get player data
  foreach who in whoList
    area as ID = who._whoAreaID
    instance as ID = who._whoAreaInstanceID
    findID as ID = who._whoAccountID
    findName as String = who._whoCharacterName
    call area area instance instance getPlayerData(findID, findName, acct, areaSend, instanceSend)
  .
.

// Return basic whodata for everyone online
function World_GetListOfEveryoneOnline() as List of Class _WhoData

  whoList as List of Class _WhoData
  who as Class _WhoData
  areaID as ID
  instanceID as ID
 
  var everyone = OnlinePlayers()
  foreach one in everyone
    WhereIsPlayer(one, areaID, instanceID)
    who._whoAccountID = one
    who._whoAreaID = areaID
    who._whoAreaInstanceID = instanceID
    who._whoAreaName = GetAreaName(areaID)
    who._whoCharacterName = GetCharacterName(one)
    who._whoAccountName = $WORLD._GetAccountName(one)
   
    add back who to whoList
  .
  return whoList
.

// get level of player (and other info)
// send back to searching player
remote function getPlayerData(PlayerID as ID, name as String, acct as ID, areaSend as ID, instanceSend as ID)

  playerAcct as NodeRef of Class E_playerAccount = PlayerID
  if playerAcct <> None
    playerNode as NodeRef of Class E_playerCharacter = playerAcct.GetMyChar()
    if playerNode <> None
      level as String = playerNode.E_level

      call area areaSend instance instanceSend SendPlayerData(acct, name, level)
    .
  .
.

// send data back to area of the searcher
remote function SendPlayerData(acct as ID, name as String, level as String)
  call client acct TMP_SocialWindowClassMethods:UpdateInfo(name, level)     // update player with new info
.

__________________________________________________________________
In new (XML) script TMP_SocialWindow

Code: [Select]
<createControlType inheritFrom='TMP_Window' class='TMP_SocialWindow' type='TMP_SocialWindow' description='' treePath='' name="TMP_SocialWindow">
  <size x="300"/>
  <set name="TMP_SocialWindow.BGpanel">
    <size x="292"/>
  </set>
  <TMP_Scrollable name="search" dockMode="NONE">
    <position x="10" y="30"/>
    <size x="280" y="190"/>
    <anchor bottom="true" right="true"/>
  </TMP_Scrollable>
  <tmp_button name="update">
    <position x="220" y="224"/>
    <size x="60"/>
    <anchor top="false" bottom="true" left="false" right="true"/>
    <set name='TMP_SocialWindow.update.text' attribute='text' value="update"/>
  </tmp_button>
  <_panel name="title">
    <position x="10" y="5"/>
    <size x="280" y="20"/>
    <defaultStatePresentation>
      <color a="0"/>
    </defaultStatePresentation>
    <_label name="name" dockMode="LEFT" text="Name" dropShadowAlpha="1">
      <defaultStatePresentation>
        <color r="0" g="0.5" b="1"/>
      </defaultStatePresentation>
    </_label>
    <_label name="area" dockMode="LEFT" text="Location" dropShadowAlpha="1">
      <size x="130"/>
      <defaultStatePresentation>
        <color r="0" g="0.5" b="1"/>
      </defaultStatePresentation>
    </_label>
    <_label name="level" dockMode="FILL" text="Level" dropShadowAlpha="1">
      <size x="50"/>
      <defaultStatePresentation>
        <color r="0" g="0.5" b="1"/>
      </defaultStatePresentation>
    </_label>
  </_panel>
  <_label name="amount" text="Players:" dropShadowAlpha="1">
    <position x="20" y="224"/>
    <size x="260"/>
    <anchor top="false" bottom="true"/>
    <defaultStatePresentation>
      <color r="0" g="1" b="1"/>
    </defaultStatePresentation>
  </_label>
</createControlType>

__________________________________________________________________
In new (XML) script TMP_SearchPanel

Code: [Select]
<createControlType inheritFrom='_panel' type='tmp_searchPanel' description='' treePath='CleanEngine' name="tmp_searchPanel" dockMode="TOP">
  <size x="1035" y="20"/>
  <defaultStatePresentation>
    <color a="0"/>
  </defaultStatePresentation>
  <TMP_ChatLabel name="name" dockMode="LEFT" text="name">
    <size x="100" y="20"/>
    <defaultStatePresentation>
      <color r="0" b="1"/>
    </defaultStatePresentation>
  </TMP_ChatLabel>
  <_label name="area" dockMode="LEFT" text="loc" dropShadowAlpha="1">
    <size x="140"/>
    <defaultStatePresentation>
      <color r="0" g="1" b="1"/>
    </defaultStatePresentation>
  </_label>
  <_label name="level" dockMode="FILL" text="1    " dropShadowAlpha="1" justification="TOPRIGHT">
    <size x="795"/>
    <defaultStatePresentation>
      <color r="0" g="1" b="1"/>
    </defaultStatePresentation>
  </_label>
</createControlType>

__________________________________________________________________
In (clientside) script E_PlayerAccountClassMethods under the chatwindow

Code: [Select]
        TMP_SocialWindowClassMethods:Start() // Create search window
« Last Edit: Jul 08, 15, 08:42:08 PM by Thazager »
Logged