Keybinds

Author Topic: Keybinds  (Read 8463 times)

How to I script a keybind?

        $remapDivision[$remapCount] = "Division Name";
   $remapName[$remapCount] = "Command Name";
   $remapCmd[$remapCount] = "Name_Of_Function";
   $remapCount++;


function Name_Of_Function(%...)
{
All Coding here...
}

        $remapDivision[$remapCount] = "Division Name";
   $remapName[$remapCount] = "Command Name";
   $remapCmd[$remapCount] = "Name_Of_Function";
   $remapCount++;


function Name_Of_Function(%...)
{
All Coding here...
}

Like this?
Code: [Select]
$remapDivision[$remapCount] = "Hi And Bye Mod";
   $remapName[$remapCount] = "Turn On";
   $remapCmd[$remapCount] = "Client_HiAndByeMod";
   $remapCount++;

Like this?
Code: [Select]
$remapDivision[$remapCount] = "Hi And Bye Mod";
   $remapName[$remapCount] = "Turn On";
   $remapCmd[$remapCount] = "Client_HiAndByeMod";
   $remapCount++;
that would execute function Client_HiAndByeMod whenever you press the key bound to it.
what you want to do is make a function in the file and then when you press the keybind it will do that function.
i.e.
Code: [Select]
$remapDivision[$remapCount] = "Client Kill Mod";
$remapName[$remapCount] = "Self Delete";
$remapCmd[$remapCount] = "loool";
$remapCount++;

function lool() {
    commandtoserver('Self Delete');
}

if i pressed the key it would Self Delete me.

edit: some people also like to add an if statement:
Code: [Select]
if(!$ClientKill::Binds) {
    $remapDivision[$remapCount] = "Client Kill Mod";
    $remapName[$remapCount] = "Self Delete";
    $remapCmd[$remapCount] = "loool";
    $remapCount++;
    $ClientKill::Binds=1;
}

function lool() {
    commandtoserver('Self Delete');
}
« Last Edit: July 21, 2011, 08:56:35 AM by Placid »

One more thing to note, is that keys call the command both when they are pressed, and when they are released.

say key "K" is bound to command "cake"

Code: [Select]
function cake(%x)
{
   if(%x)
      echo("You pressed the key");
   else
      echo("You released the key");
}

I tried the following and the keybinds did not show up in the options menu.
Code: [Select]
$remapDivision[$remapCount] = "Hi And Bye Mod";
   $remapName[$remapCount] = "Turn Off";
   $remapCmd[$remapCount] = "Client_HiAndByeMod";
   $remapCount++;


function Client_HiAndByeMod(%…)
{

   {
      package Greet
{
function newChatHud_addLine(%text)
{
//Called when any line of text is added to the chat box
Parent::newChatHud_addLine(%text);
//This will turn the "jes00 connected." into "jes00"
%nameToGreet = strReplace(%text," connected.","");
//If the %nameToGreet variable is different to the original line greet them,
//otherwise it's something else
if(%nameToGreet !$= %text)
{
//Send a chat message saying hi to the player who joined (%nameToGreet)
commandtoserver('messagesent',"Hello " @ %nameToGreet);
}
}
};
activatePackage(Greet);

   {
package Bye
{
function newChatHud_addLine(%text)
{
//Called when any line of text is added to the chat box
Parent::newChatHud_addLine(%text);
//This will turn the "jes00 has left the game." into "jes00"
%nameToFarewell = strReplace(%text," has left the game.","");
//If the %nameToFarewell variable is different to the original line greet them,
//otherwise it's something else
if(%nameToFarewell !$= %text)
{
//Send a chat message saying goodbye to the player who joined (%nameToFarewell)
commandtoserver('messagesent',"Goodbye " @ %nameToFarewell);
}
}
};
activatePackage(Bye);
}

        $remapDivision[$remapCount] = "Hi And Bye Mod";
   $remapName[$remapCount] = "Turn On";
   $remapCmd[$remapCount] = "Client_HiAndByeModOff";
   $remapCount++;


function Client_HiAndByeModOff(%…)
{
deactivatePackage(Greet);
deactivatePackage(Bye);
}

Because you have massive syntax errors.

Because you have massive syntax errors.
This is all the console has to say about it.

This is all the console has to say about it.

Durr - then either name it back or delete the namecheck.txt inside.

Also you have many syntax mistakes.

(%...) was obviously just to show you that some random variable goes there.  Don't actually put that.

Watch how your curley brackets line up too.

You need to actually finish declaring a function before you start declaring something else.
« Last Edit: July 21, 2011, 08:16:41 PM by Nexus »

I can see nothing wrong with this so you will need to help me here(please)
Code: [Select]
$remapDivision[$remapCount] = "Hi And Bye Mod";
   $remapName[$remapCount] = "Turn Off";
   $remapCmd[$remapCount] = "Client_HiAndByeMod";
   $remapCount++;


function Client_HiAndByeMod(%NoIdeaWhatToPutHere)
{

   {
      package Greet
{
function newChatHud_addLine(%text)
{
//Called when any line of text is added to the chat box
Parent::newChatHud_addLine(%text);
//This will turn the "jes00 connected." into "jes00"
%nameToGreet = strReplace(%text," connected.","");
//If the %nameToGreet variable is different to the original line greet them,
//otherwise it's something else
if(%nameToGreet !$= %text)
{
//Send a chat message saying hi to the player who joined (%nameToGreet)
commandtoserver('messagesent',"Hello " @ %nameToGreet);
}
}
};
activatePackage(Greet);

   {
package Bye
{
function newChatHud_addLine(%text)
{
//Called when any line of text is added to the chat box
Parent::newChatHud_addLine(%text);
//This will turn the "jes00 has left the game." into "jes00"
%nameToFarewell = strReplace(%text," has left the game.","");
//If the %nameToFarewell variable is different to the original line greet them,
//otherwise it's something else
if(%nameToFarewell !$= %text)
{
//Send a chat message saying goodbye to the player who joined (%nameToFarewell)
commandtoserver('messagesent',"Goodbye " @ %nameToFarewell);
}
}
};
activatePackage(Bye);
}

        $remapDivision[$remapCount] = "Hi And Bye Mod";
   $remapName[$remapCount] = "Turn On";
   $remapCmd[$remapCount] = "Client_HiAndByeModOff";
   $remapCount++;


function Client_HiAndByeModOff(%IdkWhatToPutHere)
{
deactivatePackage(Greet);
deactivatePackage(Bye);
}

you declare a function, then declare a package, then declare a function all inside of each other.

You don't seem to know how to use curley brackets, I just see them flung all over the place.

The name of the variable %whatever does not matter as long as you use the same name whenever you want to use that variable in the function.

Redefining the same function in two different packages is a waste.

You really should be reading through some more scripts made by other people before attempting your own.  At least get an idea for how the syntax is supposed to go.

I think what you want is for someone to just go ahead and fix this for you, but that isn't a good part of the learning experience.

I think what you want is for someone to just go ahead and fix this for you, but that isn't a good part of the learning experience.
Please :panda:

I tried the following and the keybinds did not show up in the options menu.
I don't suggest you use this mod, but oh well, your choice.
Code: [Select]
if(!$Greet::Binds) {
    $remapDivision[$remapCount] = "Hi and Bye Mod";
    $remapName[$remapCount] = "Toggle";
    $remapCmd[$remapCount] = "client_hiandbye";
    $remapCount++;
    $Greet::Binds = 1;
}

//you had a function before the packages;
//i don't even think that works
//also your brackets were a bit confusing in
//the functions/packages area, you want to make it easy on the eye

package greet { //this i know you just copied from something
    function newChatHud_addLine(%text) {
        Parent::newChatHud_addLine(%text);
        %nameToGreet = strReplace(%text," connected.","");
        if(%nameToGreet !$= %text) {
             commandtoserver('messagesent',"Hello " @ %nameToGreet @ ".");
        }
    }
};

package bye { //with minor changes, same as above
    function newChatHud_addLine(%text) {
        Parent::newChatHud_addLine(%text);
        %nameToBye = strReplace(%text," has left the game","");
        if(%nameToBye !$= %text) {
            commandToServer('messagesent',"Bye, " @ %nameToBye @ ".");
        }
    }
};

function client_hiandbye() { //your on and off functions were never being called. this is called by keybind.
    if($Greet::On) {
        deactivatepackage(greet);
        deactivatepackage(greet);
        $Greet::On = 0;
        return;
     }
     if(!$Greet::On) {
        activatePackage(greet);
        activatePackage(bye);
        $Greet::On = 1;
        return;
    }
}
added comments with (some of) what you did wrong.

but yeah i'd mostly work on your spacing for right now, when you can look at it easier it makes it easier to edit and easier for others to see what's wrong, as well as help you (that is, without rewriting your whole script)

this isn't guaranteed to work, i'm not about to go test an autogreet mod and make myself look like a handicapped little forget

I think what you want is for someone to just go ahead and fix this for you, but that isn't a good part of the learning experience.
eh, i just gave a shot at it


ninja, also please know that i'm not always going to be here to make your scripts for you. get independent.
« Last Edit: July 22, 2011, 08:49:17 AM by Placid »

Placid.

You should combine the two packages, there is no reason to not have just one.

If you test for a variable to be true, change it to false, then test for it being false, that will not work.

Edit in bold

Oh and I forgot to mention the %x test for if it is being pressed or released.
« Last Edit: July 23, 2011, 12:03:47 PM by Nexus »

You should combine the two packages, there is no reason to have just one.

If you test for a variable to be true, change it to false, then test for it being false, that will not work.
1. eh, true, i was basing it off his.. if it was my project i would.
2. ah forget forgot the return, thank you