| Blockland Forums > Modification Help |
| [Resource] Keybind Functions - AddKeyBind, RemoveKeyBind |
| (1/2) > >> |
| Greek2me:
I always thought that there needed to be a default function to do this, but there isn't, so here you go: --- Code: (addKeyBind) ---function addKeyBind(%div,%name,%cmd,%device,%action,%overWrite) { if(%device !$= "" && %action !$= "") { if(moveMap.getCommand(%device,%action) $= "" || %overWrite) moveMap.bind(%device,%action,%cmd); } %divIndex = -1; for(%i=0; %i < $RemapCount; %i++) { if($RemapDivision[%i] $= %div) { %divIndex = %i; break; } } if(%divIndex >= 0) { for(%i=$RemapCount-1; %i > %divIndex; %i--) { $RemapDivision[%i+1] = $RemapDivision[%i]; $RemapName[%i+1] = $RemapName[%i]; $RemapCmd[%i+1] = $RemapCmd[%i]; } $RemapDivision[%divIndex+1] = ""; $RemapName[%divIndex+1] = %name; $RemapCmd[%divIndex+1] = %cmd; $RemapCount ++; } else { $RemapDivision[$RemapCount] = %div; $RemapName[$RemapCount] = %name; $RemapCmd[$RemapCount] = %cmd; $RemapCount ++; } } --- End code --- This adds a keybind, and if desired can forcibly or non-forcibly bind it to a key. --- Code: (EXAMPLE) ---addKeyBind("Division","Name","command","keyboard","alt f",0); --- End code --- Division - If the division used already exists, the bind will be added under the existing division. Name - The name of the bind. Command - The command called when this bind is used. The function called has one variable for the state of the bound key (bool up/down). Device - This is not needed for normal use! This is used when setting the bind to a key. (keyboard/mouse) Action - This is not needed for normal use! This is used when setting the bind to a key. Set this to an action such as "shift G" or "alt v". Overwrite - This is not needed for normal use! This is used when setting the bind to a key. If this is true, any existing binding using the specified device/action will be overwritten. (bool) --- Code: (removeKeyBind) ---function removeKeyBind(%div,%name,%cmd) { %binding = moveMap.getBinding(%cmd); %device = getField(%binding,0); %action = getField(%binding,1); if(%device !$= "" && %action !$= "") moveMap.unBind(%device,%action); for(%i=0; %i < $RemapCount; %i++) { %d = $RemapDivision[%i]; %n = $RemapName[%i]; %c = $RemapCmd[%i]; %start = 0; if(%n $= %name && %c $= %cmd && (%d $= %div || %lastDiv $= %div)) { %start = %i + 1; break; } if(%d !$= "") %lastDiv = %d; } if(%start > 0) { for(%i=%start; %i < $RemapCount; %i++) { $RemapDivision[%i-1] = $RemapDivision[%i]; $RemapName[%i-1] = $RemapName[%i]; $RemapCmd[%i-1] = $RemapCmd[%i]; } %d = $RemapDivision[%start-1]; if(%d $= "") $RemapDivision[%start-1] = %div; $RemapDivision[$RemapCount-1] = ""; $RemapName[$RemapCount-1] = ""; $RemapCmd[$RemapCount-1] = ""; $RemapCount --; } } --- End code --- This removes an existing keybind properly. --- Code: (EXAMPLE) ---removeKeyBind("Division","Name","command"); --- End code --- Division - This division will remain if there are still other binds under it. Name - The name of the bind. Command - The command called when this bind is used. Hope this helps people! |
| jes00:
Why not just do this? --- Code: ---$remapDivision[$remapCount] = "Devision"; $remapName[$remapCount] = "Name"; $remapCmd[$remapCount] = "Function Called"; $remapCount++; --- End code --- |
| Swollow:
--- Quote from: jes00 on January 15, 2012, 07:25:50 AM ---Why not just do this? --- Code: ---$remapDivision[$remapCount] = "Devision"; $remapName[$remapCount] = "Name"; $remapCmd[$remapCount] = "Function Called"; $remapCount++; --- End code --- --- End quote --- because with his code you can just do this: --- Code: ---addKeyBind("Division","Name","command","keyboard","alt f",0); --- End code --- |
| Nexus:
--- Quote from: jes00 on January 15, 2012, 07:25:50 AM ---Why not just do this? --- Code: ---$remapDivision[$remapCount] = "Devision"; $remapName[$remapCount] = "Name"; $remapCmd[$remapCount] = "Function Called"; $remapCount++; --- End code --- --- End quote --- So you can place a keybind in an already existing division Also this method screws up servercommandgui, which to be honest could be a heck of a lot more flexible. I dunno if I can be bothered to fix it, but I might find myself with a whole bunch of free time and revamp some of my old stuff |
| Greek2me:
Which method? |
| Navigation |
| Message Index |
| Next page |