| Blockland Forums > Modification Help |
| Creating Keybinds that activate console codes? |
| << < (2/2) |
| Chrono:
As for keybinds: first make this into AddBind.cs. Use this exact file for any other keybind mods you make. --- Code: ---function AddBind(%division, %name, %command) { for(%i=0;%i<$remapCount;%i++) { if($remapDivision[%i] $= %division) { %foundDiv = 1; continue; } if(%foundDiv && $remapDivision[%i] !$= "") { %position = %i; break; } } if(!%foundDiv) { error("Division not found: " @ %division); return; } if(!%position) { $remapName[$remapCount] = %name; $remapCmd[$remapCount] = %command; $remapCount++; return; } for(%i=$remapCount;%i>%position;%i--) { $remapDivision[%i] = $remapDivision[%i - 1]; $remapName[%i] = $remapName[%i - 1]; $remapCmd[%i] = $remapCmd[%i - 1]; } $remapDivision[%position] = ""; $remapName[%position] = %name; $remapCmd[%position] = %command; $remapCount++; } --- End code --- Then in your client.cs --- Code: ---exec("./AddBind.cs"); function holdMouseFire(%val) //Each keybind needs it's own function { //%val is to check if the button was pressed or released if(%val) //Only do the following code if the button was pressed { $holdFire = $holdFire ? 0:1; //This will swap $holdFire between 0 and 1 every time this line happens. Very quick toggle. mousefire($holdFire); } } package holdFire { function mouseFire(%val) //We need this package so you can't normally click to interupt the holdfire. { if($holdFire && !%val) // If holdfire is on, and you are releasing the button, don't do anything return; else Parent::mouseFire(%val); } }; activatePackage(holdFire); //This is the part where you add the keybind //You'll need a different $global variable for different add-ons. such as $addedHoldCrouchKeyBinds if(!$addedHoldFireKeyBinds) { AddBind("ToggleKeys","Hold MouseFire","holdMouseFire"); $addedHoldFireKeyBinds = true; } --- End code --- This is untested though. It might give a syntax error. Comments about the code are after //s, you can leave them in or take them out. Be sure to read them. |
| FrozenEye:
I really appreciate all the help you've given me, Chrono. But sense i'm trying to learn, could you help me with a few things? --- Quote from: Chrono on March 24, 2011, 07:10:03 PM ---As for keybinds: first make this into AddBind.cs. Use this exact file for any other keybind mods you make. function AddBind(%division, %name, %command) Now, here would I change these to what I want them to be? { for(%i=0;%i<$remapCount;%i++) { if($remapDivision[%i] $= %division) { %foundDiv = 1; continue; } if(%foundDiv && $remapDivision[%i] !$= "") { %position = %i; break; } } if(!%foundDiv) { error("Division not found: " @ %division); return; } if(!%position) { $remapName[$remapCount] = %name; $remapCmd[$remapCount] = %command; $remapCount++; return; } for(%i=$remapCount;%i>%position;%i--) { $remapDivision[%i] = $remapDivision[%i - 1]; $remapName[%i] = $remapName[%i - 1]; $remapCmd[%i] = $remapCmd[%i - 1]; } $remapDivision[%position] = ""; $remapName[%position] = %name; $remapCmd[%position] = %command; $remapCount++; } Then in your client.cs exec("./AddBind.cs"); function holdMouseFire(%val) //Each keybind needs it's own function { //%val is to check if the button was pressed or released if(%val) //Only do the following code if the button was pressed - What exactly do you mean here? { $holdFire = $holdFire ? 0:1; //This will swap $holdFire between 0 and 1 every time this line happens. Very quick toggle. mousefire($holdFire); } } package holdFire { function mouseFire(%val) //We need this package so you can't normally click to interupt the holdfire. { if($holdFire && !%val) // If holdfire is on, and you are releasing the button, don't do anything return; else Parent::mouseFire(%val); } }; activatePackage(holdFire); //This is the part where you add the keybind //You'll need a different $global variable for different add-ons. such as $addedHoldCrouchKeyBinds if(!$addedHoldFireKeyBinds) { AddBind("ToggleKeys","Hold MouseFire","holdMouseFire"); -Would I choose one of these, or could I add a Activate/Deactivate? $addedHoldFireKeyBinds = true; } This is untested though. It might give a syntax error. Comments about the code are after //s, you can leave them in or take them out. Be sure to read them. --- End quote --- That is it for now. And I tried to make the questions clear, but you might have to think about what im saying. Also, sorry for it being hard to find the questions, I didnt know you couldnt Bold code |
| MegaScientifical:
I do not advise using this command solely, without all the extra settings like Chrono gave, but this is what I use for one of my commands I use in my server: --- Code: ---GlobalActionMap.bindCmd(keyboard, "F6", "", "commandToServer('radiusimpulse');"); --- End code --- |
| FrozenEye:
Chrono, the code that you gave me doesnt work, ive tried fiddling with it, but it still dosnt work |
| Navigation |
| Message Index |
| Previous page |