Author Topic: "Unable to Find Object"  (Read 913 times)

Code: [Select]
function serverCMDfindit(%client, %target)
{
%noodles = findclientbyname(%target);
%location = %noodles.player.getPosition();
talk(%location);
}

The code is supposed to find a client from the argument, store it in a local variable named noodles.
Then get the position of the "noodles" client and store it in location.
Then display globally in console chat where Mr.Noodles is.

Also, can someone port this to client sided please?  I don't know the client equivalent to serverCMD.

Code: [Select]
function serverCMDfindit(%client, %target)
{
%noodles = findclientbyname(%target);
%location = %noodles.player.getPosition();
talk(%location);
}
Well, that by the looks of it should work. Clientside stuff doesn't work quite the same though. I'm going to go ahead and tell you that getting positions clientside is impossible, there are hacky ways but those are reserved for mods that sink below the popular use line, if you get what I mean. Aside from that, a findPlayerByName function could be created using the following, and I believe Truce has some addon out that supports clientside /commands.
Code: [Select]
function findPlayerByName(%name)
{
      for(%i=0; %i<serverConnection.getCount();%i++)
      {
            if(serverConnection.getObject(%i).getClassname() !$= "Player")
                  continue;
            if(striPos(serverConnection.getObject(%i).getShapeName(),%name) >= 0)
                  return serverConnection.getObject(%i);
      }
      return 0;
}

1. The function "getClientByName" does not exist client-side. And, to my knowledge, there is no way to tie a Player object to a client in the NewPlayerListGUI. forget you slick lol
2. There's no built-in way to capture slash commands with the client. You have to hack up the send chat message function.

2. There's no built-in way to capture slash commands with the client. You have to hack up the send chat message function.
True, but there is an easy way to do it.
Code: [Select]
package myPackage
{
function NMH_Type::Send(%this)
{
%firstWord = getWord(%this.getValue(), 0);

if(%firstWord $= "/findIt")
{
//Do whatever
}

Parent::Send(%this);
}
};
activatePackage(myPackage);

Hell, if you're going to do ^ at least make it adaptable.
Code: [Select]
package clCmd
{
function NMH_Type::Send(%this)
{
%value = %this.getValue();
%firstLetter = getSubStr(%value, 0,1);

if(%firstLetter $= "/")
{
%firstWord = getWord(%value,0);
%func = getSubStr(%firstWord,1,strLen(%firstWord)-2);
if(!isFunction(("clCmd" @ %func)))
{
Parent::Send(%this);
return;
}
%start = "call((\"clCmd\" @ \"" @ %func @ "\")";
%varcount = getWordCount(%value)-1;
for(%i = 0; %i < %varcount; %i++)
{
%string = %string @ ", \"" @ getWord(%value,%i+1) @ "\"";
}
eval(%start @ %string @ ");");
%this.setValue("");
}

Parent::Send(%this);
}
};
activatePackage(clCmd);

Note: untested
« Last Edit: February 01, 2012, 12:46:50 AM by Slicksilver »