Author Topic: Client Sided Slash Command  (Read 2005 times)

to make @hi toggle something, try
function clCmdhi()
{
        $toggled = !$toggled;
}

edit: and truce, is there a way to get it to not send the message to the server?


to make @hi toggle something, try

edit: and truce, is there a way to get it to not send the message to the server?

The code I posted uses /, not @, and it does not send the message to the server either.

The code I posted uses /, not @, and it does not send the message to the server either.
But where do I tell it what slash command it is and what it does?

I don't know which way you are trying to do this but look below:

You type /j and it'll perform a jump for you, I could get more complex with it but I'm just keeping it simple.

package clCmd
{
   function NMH_Type::send(%this)
   {
      %msg = %this.getValue();
      
      %fw = getWord(%msg,0);

      if(%fw $= "/j")
      {
         jump(1);

         schedule(100,0,jump,0);

         canvas.popDialog(newMessageHud);

         return true;
      }
      
      Parent::send(%this);
   }
};
activatePackage(clCmd);



This way evaluates code so like if you typed, /moveForward(1); in the chat, it'll move forward for you.

package clCmd
{
   function NMH_Type::send(%this)
   {
      %msg = %this.getValue();

      if(getSubstr(%msg,0,1) $= "/")
      {
         %f = getSubStr(%msg,1,strLen(%msg));

         %if = getSubStr(%msg,1,strStr(%msg,"(")-1);

         if(isFunction(%if))
         {
            eval(%f);

            canvas.popdialog(newmessagehud);

            return true;
         }
      }
      Parent::send(%this);
   }
};
activatePackage(clCmd);
« Last Edit: September 14, 2011, 07:43:30 AM by infiniteLoop »

I don't know which way you are trying to do this but look below:

You type /j and it'll perform a jump for you, I could get more complex with it but I'm just keeping it simple.

This way evaluates code so like if you typed, /moveForward(1); in the chat, it'll move forward for you.

Can we not overwrite packages for support code?

The way the code I posted works is that it allows scripters to implement functions beginning with "clCmd" that are triggered when the user types in their chat. So for example, if I created the function clCmdQuit, it would activate when I typed /quit on any server. Arguments are passed as you would expect if you have created "serverCmd" functions before.

Code: [Select]
// Called when I type /randomnum 1 6
// Above example shows a random number between 1 and 6

function clCmdRandomNum(%min,%max)
{
    commandToServer('messageSent',"Random number: " @ getRandom(%min,%max));
}

// Paste the clCmd package below here

Can we not overwrite packages for support code?

The way the code I posted works is that it allows scripters to implement functions beginning with "clCmd" that are triggered when the user types in their chat. So for example, if I created the function clCmdQuit, it would activate when I typed /quit on any server. Arguments are passed as you would expect if you have created "serverCmd" functions before.

Code: [Select]
// Called when I type /randomnum 1 6
// Above example shows a random number between 1 and 6

function clCmdRandomNum(%min,%max)
{
    commandToServer('messageSent',"Random number: " @ getRandom(%min,%max));
}

// Paste the clCmd package below here

Oh, thought that it was just his package name, not something of yours.

The code I posted uses /, not @, and it does not send the message to the server either.
oh, nice :D!

Can we not overwrite packages for support code?

The way the code I posted works is that it allows scripters to implement functions beginning with "clCmd" that are triggered when the user types in their chat. So for example, if I created the function clCmdQuit, it would activate when I typed /quit on any server. Arguments are passed as you would expect if you have created "serverCmd" functions before.

Code: [Select]
// Called when I type /randomnum 1 6
// Above example shows a random number between 1 and 6

function clCmdRandomNum(%min,%max)
{
    commandToServer('messageSent',"Random number: " @ getRandom(%min,%max));
}

// Paste the clCmd package below here
Like this?
Code: [Select]
function clCmdToggleMod(%client)
{
          if($Toggle == On) {
    $Toggle = Off;
    clientCmdMessageBoxOK("jes00's Mod","Mod is now:" @ $isOn");

    } else if($Toggle == Off) {
      $Toggle = On;
    clientCmdMessageBoxOK("jes00's Mod","Mod is now:" @ $isOn");
}

package clCmd
{
function NMH_Type::send(%this)
{
%msg = %this.getValue();
%wrd = firstWord(%msg);
%cmd = "clCmd" @ getSubStr(%wrd,1,strLen(%wrd));

if(getSubStr(%msg,0,1) $= "/" && isFunction(%cmd))
{
%eval = "call(%cmd,";
%cnt  = getWordCount(%msg);

for(%i = 1; %i < %cnt; %i++)
%eval = %eval @ "\"" @ getWord(%msg,%i) @ "\",";

eval(getSubStr(%eval,0,strLen(%eval) - 1) @ ");");
%this.setValue("");
}

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

function clCmdToggleMod(%client)
{
   if($Toggle == true)
   {
      $Toggle = false;
      clientCmdMessageBoxOK("jes00's Mod","Mod is now off");
   }
   else
   {
      $Toggle = true;
      clientCmdMessageBoxOK("jes00's Mod","Mod is now on");
   }
}
Bolded what I fixed.

And god damn man, work on your formatting before you make much else
« Last Edit: September 19, 2011, 02:45:02 AM by Headcrab Zombie »

you could just toggle it with
$Toggle = !$Toggle;