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

Author Topic: Some commonly requested chat command functions  (Read 2430 times)

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Some commonly requested chat command functions
« on: Nov 28, 15, 10:50:15 PM »

*EDIT*
Removed the travelTo() method call and replaced it with code that should work
universally.
Edited the invalid Vector3 reference.
Thanks guys for pointing those out.
*****


The following is a list of commonly requested functions that can be called from the chat panel/window.
First, think of a name for your new Command script.  The name will reflect what you type to call these functions.
for example, if you wanted to have the command be "/char" you should name it CMDChar.  This is NOT a requirement, but it should be =) as its easier for you to track what script controls what commands.



To use, create a new EMPTY server script, and name it something proper, such as CMDWhatever.
Next, copy this code and paste it into your new script.




Code: [Select]
shared function HE_ProcessCommandInput( account as NodeRef, input as String )
  // The Command Handler calls this shared function based on a mapping stored on the COMMANDHANDLER prototype
  //   which maps a /command to a script to call
  //
  char as NodeRef of Class E_playerCharacter = account.GetMyChar()
  args as List of String
  Tokenize( input, args )
  if args.length < 2
    HE_CommandUsage( account, input )
    return
  .
  target as NodeRef
  where account is kindof E_playerAccount
    target = account.GetClickTarget()
  .
  //using When rather than Partial as with so many commands
  //you'll wind up calling the wrong one with partials at some point.
  when toLower( args[2] )
    //will place the player at 0,0,0 world coords
    is "gozero"
      char._TeleportCharacter( (0,0,0), (0,0,0))
    .   
   //changes your characters Visible character appearance model to that of the specified character spec
    is "change"
      if args.length > 2 and args[3] > ""
       char.GetMyVisibleCharacter()._characterSpecification = args[3]
      .
    .
    //prints your accountID in the chat panel and chat window if you have one
    is "myaccountid"
      println(account)
      $CHAT.ChatPlayer( account, "game", account )
    .
    //summons character by name to your area
    is "getchar"
      //requires that you add the summomCharacter() remote method to E_WorldClassMethods
      call area 0 instance 0 $WORLD.SummonCharacter(args[3], GetAreaNumber(), GetInstanceNumber(), char.GetPosition())
     
    .
    //will transport player to specific vector3
    is "gopoint"
      println("attempting to go is " + args[3])
      char._TeleportCharacter( args[3], (0,0,0) )
    .
    //prints out every Class on the player node
    is "class"
      clist as List of String = GetClassesOnNode(char)
      foreach c in clist
        println(c)
      .
    .
    //transports player to areas "Arrival" path waypoint or 0,0,0 if none
    is "stuck"
      Stuck(args, account, char)
    .
    //shuts down the current area / disconnecting the player in the process
    is "shutdown"
     
      $WORLD._stopAreaServer(GetAreaNumber(), GetInstanceNumber(), me)
     
      return
     
    .
    default
      HE_CommandUsage( account, input )
      return
    .
  .
.

shared function HE_CommandUsage( account as NodeRef, input as String )
  // NOTE, this style is much more efficient on the client than doing a seperate Msg() for each line.
  // This is because only a single label gets created in chat, rather than one per line.
  msg as String = "/char KEYWORD <parameter>$R"
  msg = msg + " - /char - gives the area youre in$R"
  msg = msg + " - /char stuck - teleports your char to the arival pos of area$R"
 
  Msg( account, msg )
.

function Msg( account as NodeRef, msg as String )
  $CHAT.CHATPLAYER( account, "game", msg )
  println(msg)
.



function Stuck(args as List of String, account as NodeRef of Class E_playerAccount, char as NodeRef of Class E_playerCharacter)
  println(char.name + " is stuck, trying to unStuck")
  //positionCharacter( char, (0,0,0), (0,0,0) )
  var path = PathUtils:GetPathByName( "1" )
  pos as Vector3
  rot as Vector3
  if path != None
    pos = path._getFirstPathPoint().GetPosition()
    rot = path._getFirstPathPoint().GetRotation()
  else
    path = PathUtils:GetPathByName( "Arrival" )
    if path = None
      return
    .
    pos = path._getFirstPathPoint().GetPosition()
    rot = path._getFirstPathPoint().GetRotation()
  .
  char._TeleportCharacter( pos, rot )
 
.


This will NOT compile YET...
within this code is a function that calls a game specific remote method in E_WorldClassMethods script, also on the server side.   You'll need to add this remote method to E_WorldClassMethods script.
To do so, open it up in the script editor, and copy/paste the code below at the bottom of your existing code in E_WorldClassMethods script.


Code: [Select]
remote method SummonCharacter(charName as String, areaID as ID, instanceID as ID, pos as Vector3)
  account as ID = $WORLD._FindPlayerByName(charName)
  if account != 0
    println("found player on world server")
    var info = $WORLD._WhereIsPlayer(account)
    call area info._currentArea instance info._currentAreaInstance $AREA.YankPlayer(account, areaID, instanceID, pos)
  else
    println("player not found on world server")
  . 
.


got it?  NOT DONE YET!
you've just added another remote method call to E_AreaClassMethods that you probably don't have.
So, don't try to compile E_WorldClassMethods just yet.

Instead, open server script E_AReaClassMethods in the script editor, and scroll to the bottom somewhere, and copy/paste the following remote method into the E_AreaClassMethods script:


Code: [Select]
remote method YankPlayer(accountID as ID, areaID as ID, instanceID as ID, pos as Vector3)
  account as NodeRef of Class E_playerAccount = accountID
  if account != None
    player as NodeRef of Class E_playerCharacter = account.GetMyChar()
    instance as String = instanceID
    println("calling change area")
    $Travel._ChangeAreaRequest( account, areaID, instance )
  else
    player as NodeRef of Class E_playerCharacter = accountID
    if player != None
      println("Player found!")
      return
    .
    println(accountID + " account not found in area server")
  .
.

Now, compile E_AReaClassMethods script and submit it.

Next compile E_WorldClassMethods script and submit it.

Next compile your CMDWhatever script and submit it.

Next, go to the chat panel OR chat window and type the following:
/REGISTER add /whatEverYouWantYourCommandToBeCalled script="CMDWhatever"
and hit enter.
NOTE: DONT LEAVE OUT THE "/" in the command name!

You've now registered your new command to the system.
Now, typing /whatEverYouWantYourCommandToBeCalled  will access any functions defined inside the new CMDWhatever script you just created.  You can add more by simply adding them to the WHEN code block with the others. 

Example:(if i named the command /char)
/char stuck (would call the stuck function within the script registered to the command /char.  make sense?

I think I covered any methods/functions that you would have to create on your end, but if NOT, just let me know and i'll help you set it up.

We make use of tons of commands such as these and most of them are game specific (requiring additional classes/code) however if there is something you'd like to add as a chat command, post a comment here and I'll try to either copy it for you or help you set it up.

These are very basic, but should help give you an idea of how to setup a command script, as well as some of the things you can accomplish with one.   

NOTE: Be cautious of how "open" you leave your command scripts.  If the functions involve things which would NOT be allowed to players, make sure you include a GM or ADMIN check at the very top, and return if the account does not meet required parameters.

such as:
if not account.isGM
  return
.
You can also check for Admin status, or even whether GMMode is active or not on the account.
This is very important when making use of Untrusted Functions of ANY kind on the server.

Final NOTE:
you'll notice that I left a pointer to "target".
I've not included any functions which use it, as they require more code / classes to implement,
but you can easily add your own.  Target points to the players currently clicked/selected target.


Hope it helps
« Last Edit: Dec 06, 15, 02:24:41 PM by ToY-Krun »
Logged

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Re: Some commonly requested chat command functions
« Reply #1 on: Nov 28, 15, 10:57:56 PM »

The list of functions and what they do:

(replace "/char" with whatever slash command you registered)

/char gozero - Teleports the player to the 0,0,0 vector3 position in the current area.
/char change - changes your characters Visible character appearance model to that of the specified character spec
        to locate the valid "spec" to enter, hit F5 , Tools tab, then click character registry.
        must use a registered character spec.
/char myaccountid - prints out the players account/client ID
/char getchar <name> - summons a player character by name from anywhere in the game world to the
        players current area.
/char gopoint <vector3> - teleports the player to the specified vector3 position in the current area.
/char class - prints out ever class on the players E_playerCharacter Node
/char stuck - will teleport the player to  the current area's "Arrival" pathpoint OR 0,0,0 if one doesnt exist.
/char shutdown - will imediately shutdown the current area/Instance and disconnect player.  Without NOTICE.
        this can be handy when used from the PlayerClient when something has gone wrong and the blade is
        frozen.(IF you have a chat window for the client to use)


EDIT #1:
Once you have some chat commands setup, You can also call these from other scripts, not JUST chat window/panel.
For example, from the client, you might want to set up a button that will automatically call the "stuck" function.
To do so, from your button's script you would do the following:
Assuming you have already set up a function/method handling button clicks,
when your button is clicked call:
SendCommand("/char stuck")
this will call the server with your command and access your script as if you had typed it into the chat window.

You can also call it from other server side scripts like this:
CMDWhatever:HE_ProcessCommandInput( account, "/char stuck" )

« Last Edit: Nov 28, 15, 11:13:56 PM by ToY-Krun »
Logged

Mr_Conflicts

  • General Accounts
  • *
  • Posts: 39
  • HSL Programmer
    • View Profile
    • Daniel J. Burkhart
Re: Some commonly requested chat command functions
« Reply #2 on: Dec 06, 15, 10:07:25 AM »

Hey, I thought I might point out two errors I got when I tried to follow this tutorial.

I ran into the compiler error message:
Quote
value of type integer is doesn't match type of Vector3.
which I realized was because the code:
Code: [Select]
char._TeleportCharacter( args[3], 0,0,0 ) needs a slight change with the zeros:
Code: [Select]
char._TeleportCharacter( args[3], (0,0,0) ) this will fix the problem.

The next error I have no idea what to do about it as the method referenced was not found by the compiler.

Error message:
Quote
Method 'TravelTo' not found!

Other than those two errors I found the tutorial to be quite informative, Thanks!
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: Some commonly requested chat command functions
« Reply #3 on: Dec 06, 15, 01:53:11 PM »

I looks like the method was not added for the tutorial, as its called from this line:
Code: [Select]
char.TravelTo( GetAreaNumber(), GetInstanceNumber(), pos, rot)

easy to forget with so many parts/methods
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Re: Some commonly requested chat command functions
« Reply #4 on: Dec 06, 15, 02:16:50 PM »

ahhh yeah... sorry about that guys.


I went through and retyped this script removing or trying to remove, the custom things.
Theres alot of custom functions and methods involved with most of these we use, but anyway...
Appreciate you pointing out the issues.

I will put together an "extended" version and post it as well, which will include some of the custom
classes IF anyone wants to bother adding them.

oh and I'll add the TravelTo() method in for anyone that wants.

*EDIT*
for now I just removed the travelTo() method call and replaced it with:
Code: [Select]
char._TeleportCharacter( pos, rot )
« Last Edit: Dec 06, 15, 02:25:54 PM by ToY-Krun »
Logged