Author Topic: "/" command help  (Read 1975 times)

Hi, I'm new to scripting and I needed some help on simple forward slash commands. I just need to be able to set up an in game command to toggle on and off a line of code. If you could help it would be nice.

Code: [Select]
$GlobalVar = 1;

function serverCmdToggle(%client)
{
   $GlobalVar = !$GlobalVar; //Inverts the variable, IE 0->1 and 1->0
}

function someFunction(%arg)
{
   doStuff();
   if($GlobalVar)
   {
      toggledFunction();
   }
   doMoreStuff();
}

Not to bug you, but where would I put this in my script? I just need to be able to toggle which body parts it affects, thanks for the help.

Code: [Select]
//Colored Avatar
//by boomlinde
//Edited by Tylerman
//Re-edited by Erif/Baeshra/BL_ID 19049

if (!$RainbowAvatarBindings)
{
   $remapDivision[$remapCount] = "Rainbow Avatar";
   $remapName[$remapCount] = "Activate/Deactivate";
   $remapCmd[$remapCount] = "RainbowAvatarToggle";
   $remapCount++;
   $RainbowAvatarBindings=true;
}

$RainbowAvatarCount=0;
$RainbowAvatarFlag=0;
$RainbowAvatarTempPack=$pref::Avatar::PackColor;
$RainbowAvatarTempHat=$pref::Avatar::HatColor;
$RainbowAvatarTempLLeg=$pref::Avatar::LLegColor;
$RainbowAvatarTempRLeg=$pref::Avatar::RLegColor;
$RainbowAvatarTempAccent=$pref::Avatar::AccentColor;
$RainbowAvatarTempHead=$pref::Avatar::HeadColor;
$RainbowAvatarTempTorso=$pref::Avatar::TorsoColor;
$RainbowAvatarTempHip=$pref::Avatar::HipColor;
$RainbowAvatarTempLArm=$pref::Avatar::LArmColor;
$RainbowAvatarTempLHand=$pref::Avatar::LHandColor;
$RainbowAvatarTempRArm=$pref::Avatar::RArmColor;
$RainbowAvatarTempRHand=$pref::Avatar::RHandColor;
$RainbowAvatarTempSecondPack=$pref::Avatar::SecondPackColor;

function RainbowAvatarToggle(%val)
{
  if(%val) {
    if($RainbowAvatarFlag==0)
    {
        $RainbowAvatarFlag=1;
        $RainbowAvatarTempPack=$pref::Avatar::PackColor;
      $RainbowAvatarTempHat=$pref::Avatar::HatColor;
      $RainbowAvatarTempLLeg=$pref::Avatar::LLegColor;
      $RainbowAvatarTempRLeg=$pref::Avatar::RLegColor;
      $RainbowAvatarTempAccent=$pref::Avatar::AccentColor;
      $RainbowAvatarTempHead=$pref::Avatar::HeadColor;
      $RainbowAvatarTempTorso=$pref::Avatar::TorsoColor;
      $RainbowAvatarTempHip=$pref::Avatar::HipColor;
      $RainbowAvatarTempLArm=$pref::Avatar::LArmColor;
      $RainbowAvatarTempLHand=$pref::Avatar::LHandColor;
      $RainbowAvatarTempRArm=$pref::Avatar::RArmColor;
      $RainbowAvatarTempRHand=$pref::Avatar::RHandColor;
      $RainbowAvatarTempSecondPack=$pref::Avatar::SecondPackColor;
        RainbowAvatarLoop();
    }
   else if($RainbowAvatarFlag==1)
    {
        $RainbowAvatarFlag=0;
        cancel($RainbowAvatar);
        $pref::Avatar::PackColor=$RainbowAvatarTempPack;
      $pref::Avatar::HatColor=$RainbowAvatarTempHat;
      $pref::Avatar::LLegColor=$RainbowAvatarTempLLeg;
      $pref::Avatar::RLegColor=$RainbowAvatarTempRLeg;
      $pref::Avatar::AccentColor=$RainbowAvatarTempAccent;
      $pref::Avatar::HeadColor=$RainbowAvatarTempHead;
      $pref::Avatar::TorsoColor=$RainbowAvatarTempTorso;
      $pref::Avatar::HipColor=$RainbowAvatarTempHip;
      $pref::Avatar::LArmColor=$RainbowAvatarTempLArm;
      $pref::Avatar::LHandColor=$RainbowAvatarTempLHand;
      $pref::Avatar::RArmColor=$RainbowAvatarTempRArm;
      $pref::Avatar::RHandColor=$RainbowAvatarTempRHand;
      $pref::Avatar::SecondPackColor=$RainbowAvatarTempSecondPack;
        clientcmdupdateprefs();
    }
  }
}
function rainbowreset() {
cancel($RainbowAvatar);
$pref::Avatar::PackColor=$RainbowAvatarTempPack;
$pref::Avatar::HatColor=$RainbowAvatarTempHat;
$pref::Avatar::LLegColor=$RainbowAvatarTempLLeg;
$pref::Avatar::RLegColor=$RainbowAvatarTempRLeg;
$pref::Avatar::AccentColor=$RainbowAvatarTempAccent;
$pref::Avatar::HeadColor=$RainbowAvatarTempHead;
$pref::Avatar::TorsoColor=$RainbowAvatarTempTorso;
$pref::Avatar::HipColor=$RainbowAvatarTempHip;
$pref::Avatar::LArmColor=$RainbowAvatarTempLArm;
$pref::Avatar::LHandColor=$RainbowAvatarTempLHand;
$pref::Avatar::RArmColor=$RainbowAvatarTempRArm;
$pref::Avatar::RHandColor=$RainbowAvatarTempRHand;
$pref::Avatar::SecondPackColor=$RainbowAvatarTempSecondPack;
clientcmdupdateprefs();
}
function RainbowAvatarLoop()
{
        if($RainbowAvatarCount > 63) $RainbowAvatarCount=0;
        //Grejer
        $R=0.5+0.5*mSin($RainbowAvatarCount*3.14/16.0);
        //$G=0.5+0.5*mSin($RainbowAvatarCount*3.14/16.0);
$G=0.5+0.5*mSin($RainbowAvatarCount*3.14/16.0+21.0);
        //$B=0.5+0.5*mSin($RainbowAvatarCount*3.14/16.0);
      $pref::Avatar::PackColor=$R SPC $G SPC $B SPC "1";
      $pref::Avatar::HatColor=$R SPC $G SPC $B SPC "1";
      $pref::Avatar::LLegColor=$R SPC $G SPC $B SPC "1";
      $pref::Avatar::RLegColor=$R SPC $G SPC $B SPC "1";
      $pref::Avatar::AccentColor=$R SPC $G SPC $B SPC "1";
      $pref::Avatar::HeadColor=$R SPC $G SPC $B SPC "1";
      $pref::Avatar::TorsoColor=$R SPC $G SPC $B SPC "1";
      $pref::Avatar::HipColor=$R SPC $G SPC $B SPC "1";
      $pref::Avatar::LArmColor=$R SPC $G SPC $B SPC "1";
      $pref::Avatar::LHandColor=$R SPC $G SPC $B SPC "1";
      $pref::Avatar::RArmColor=$R SPC $G SPC $B SPC "1";
      $pref::Avatar::RHandColor=$R SPC $G SPC $B SPC "1";
      $pref::Avatar::SecondPackColor=$R SPC $G SPC $B SPC "1";
        clientcmdupdateprefs();
        $RainbowAvatarCount++;
        $RainbowAvatar=schedule(250,0,RainbowAvatarLoop);

Client scripts like that wont work with "/ commands", you'd have to keybind it.

Also, don't try to (re)make the rainbow player. It's a crap-on I believe.
« Last Edit: January 06, 2011, 11:34:05 AM by Miles Barlow »

I'm not "re-making" it, I'm not even going to release it, I just thought it was interesting and I wanted to learn a bit more about coding in general.

Code: [Select]
$GlobalVar = 1;

function serverCmdToggle(%client)
{
   $GlobalVar = !$GlobalVar; //Inverts the variable, IE 0->1 and 1->0
}

function someFunction(%arg)
{
   doStuff();
   if($GlobalVar)
   {
      toggledFunction();
   }
   doMoreStuff();
}

Holy forget, really? God damn it, I feel like the stupidest of the idiots for this code, then:

Quote
function toggleVariable(%var, %msg, %one, %zero, %type) {
   %s = %var @ " = (" @ %var @ " ? 0 : 1);";
   switch$(%type) {
      case "echo":   %s = %s SPC "echo(\"\c2";
      case "message":   %s = %s SPC "MCEResponder(\"";
      default:
         eval(%s);
         return;
   }
   %s = %s @ expandEscape(%msg) SPC "\" @ (" @ %var @ " ? \"" @ %one @ "\" : \"" @ %zero @ "\") @ \".\");";
   if($MCE::tV)
      echo(%s);
   eval(%s);
}

I was using that to toggle variables, with an optional call into chat or console about the event. I just noticed my echo thing wouldn't even work if I didn't put a responding message... meh...
« Last Edit: January 06, 2011, 01:14:20 PM by MegaScientifical »

While it's true that / commands are only for server sided functions, if you get Truce's Support_clCmd, you can execute / commands for client sided functions as well.

While it's true that / commands are only for server sided functions, if you get Truce's Support_clCmd, you can execute / commands for client sided functions as well.

The command your client uses to send messages looks for "/" in the front. If it's there, it takes the first word after the / as the command and every next word as a variable. That's all handled clientside. That's why people can send messages to chat with "/" in front. Truce's code likely just allows it to check if the commands are client sided first and do it that way instead.

It's not like it's banned code, it just was never publicly released.  If you want I can show you the code.

Edit: Here
Code: [Select]
package clCmd {
function NMH_Type::send(%chat) {
%msg=%chat.getValue();
%wrd=firstWord(%msg);
%cmd="clCmd"@getSubStr(%wrd,1,strLen(%wrd));
if(getSubStr(%msg,0,1)$="/"&&isFunction(%cmd)) {
call(%cmd,getWord(%msg,1),getWord(%msg,2),getWord(%msg,3),getWord(%msg,4),getWord(%msg,5));
commandToServer('stopTalking');
canvas.popdialog(newMessageHud);
%chat.setValue("");
}
Parent::send(%chat);
}
};
activatePackage(clCmd);

Just pop that into a client.cs, add a description and away you go.

It is possible to have client-sided /cmds. getHex is a good example.

Code: [Select]
package ClientGetHex
{
function NMH_Type::Send(%this)
{
if(%this.getValue() $= "/gethex")
{
%color = $Paint_Row[$CurrPaintRow].swatch[$CurrPaintSwatch].color;
%a = getWord(%color,3);
%r = mFloor(getWord(%color,0) - (255 - %a));
%g = mFloor(getWord(%color,1) - (255 - %a));
%b = mFloor(getWord(%color,2) - (255 - %a));
%hex = getHex(%r) @ getHex(%g) @ getHex(%b);
NewChatSO.addLine("\c6The hex for your selected color is <color:" @ %hex @ ">" @ %hex @ "\c6.");
canvas.popDialog(NewMessageHud);
return;
}
Parent::Send(%this);
}
};
ActivatePackage(ClientGetHex);

It's not like it's banned code, it just was never publicly released.  If you want I can show you the code.

-snip-

Just pop that into a client.cs, add a description and away you go.

Use this one, it supports a dynamic number of parameters (I think it works):

Code: [Select]
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);

Truce's would probably be best to use, ignore me, I haven't made a good script in ages.

Once again I'm sorry but I could really use some help, just tell me what I need to know to get this script working with "/ commands", thanks.

Once again I'm sorry but I could really use some help, just tell me what I need to know to get this script working with "/ commands", thanks.
You have the script, and you've been told how to make slash commands.
What part are you having trouble with?

This is how you do it
Code: [Select]
function serverCmdWhatEverYouWantHere
replace WhatEverYouWantHere with what you want people to say when they type the command using the slash