Blockland Forums > Modification Help
Creating Keybinds that activate console codes?
(1/2) > >>
FrozenEye:
Hello, earlier I was messing around with scripts and I started thinking if there was anyway to type a slash command and activate a console code?
For example: Lets say I type "/Fire", is there anyway to make it so "/Fire" will activate mousefire(1); in the console? Thanks.
SpreadsPlague:
you should stay away from making client-sided commands (for this purpose). keybinds would be better for this.
FrozenEye:

--- Quote from: SpreadsPlague on March 24, 2011, 06:16:55 PM ---you should stay away from making client-sided commands (for this purpose). keybinds would be better for this.

--- End quote ---
Well, that was my original idea, but when I studied other addons with keybinds I couldnt get anything out of them. Well, I was able to bind a key to it, but the key was virtually worthless. If anyone could help me with that I would be thankful.
Chrono:
It would have to be client sided, and I personally am against using slash commands for client sided code.

You could however, use another symbol, like ^fire, where ^ calls client sided commands.


--- Code: ---
package ClientCmds
{
function NMH_Type::Send(%this)
{
if(getSubStr(%this.getValue(),0,1) $= "^")
{
%this.setValue(getSubStr(%this.getValue(),1,strLen(%this.getValue())-1));
%str = %this.getValue();
%cmd = getWord(%str,0);
for(%x=1;%x<getWordCount(%str);%x++)
{
%args = %args @ getWord(%str,%x);
if(%x+1 != getWordCount(%str))
%args = %args @ ",";
}
%this.setValue("");
if(%args !$= "")
echo("call(ClientChatCmd" @ %cmd @ "," @ %args @ ");");
else
call("ClientChatCmd" @ %cmd);
}
Parent::send(%this);
}
};
activatePackage(ClientCmds);
--- End code ---

Put this into a separate script file. Call it ClientChatCmds.cs
Now in your client.cs, at the first line, put exec("./ClientChatCmds.cs");

And to make your command, fire, you would do this:


--- Code: ---function ClientChatCmdFire(%val)
{
mousefire(%val);
}
--- End code ---

And then type ^fire 1 in game to start mousefire, ^fire 0 to stop it.

--- Quote from: SpreadsPlague on March 24, 2011, 06:16:55 PM ---you should stay away from making client-sided commands (for this purpose). keybinds would be better for this.

--- End quote ---
But with this way you could add args, like so:


--- Code: ---function ClientChatCmdHelloWorld(%arg1, %arg2)
{
echo("Hello world!");
if(%arg1 !$= "")
echo(%arg1);
if(%arg2 !$= "")
echo(%arg2);
}
--- End code ---
FrozenEye:
Thanks, that helped a lot. I didnt expect something like this so quickly!
But anyway, sense i'm still trying to figure things like this out, how would you do a keybind that would do the same exact thing? Thanks :D
Navigation
Message Index
Next page

Go to full version