Blockland Forums > Modification Help
"/" command help
MegaScientifical:
--- Quote from: Amade on January 06, 2011, 01:00:16 AM ---
--- Code: ---$GlobalVar = 1;
function serverCmdToggle(%client)
{
$GlobalVar = !$GlobalVar; //Inverts the variable, IE 0->1 and 1->0
}
function someFunction(%arg)
{
doStuff();
if($GlobalVar)
{
toggledFunction();
}
doMoreStuff();
}
--- End code ---
--- End quote ---
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);
}
--- End quote ---
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...
Gadgethm:
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.
MegaScientifical:
--- Quote from: Gadgethm on January 06, 2011, 04:14:37 PM ---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.
--- End quote ---
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.
Gadgethm:
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: ---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);
--- End code ---
Just pop that into a client.cs, add a description and away you go.
otto-san:
It is possible to have client-sided /cmds. getHex is a good example.
--- Code: ---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);
--- End code ---