Author Topic: Keybind help  (Read 722 times)

I looked into the command GUI's client.cs script. I found that this is how it does a keybind:

Code: [Select]
$remapDivision[$remapCount] = "Electrk's GUIs";
$remapName[$remapCount] = "Commands GUI";
$remapCmd[$remapCount] = "cmdsGUIOpen";
$remapCount++;
$CmdsBinds = 1;
And the keybinding for the commands GUI works perfectly. It appears in the Options>>Controls window.
I tried copying and pasting that code into my add-on. I changed the names of the variables, so it looked like this:
Code: [Select]
$srpremapDivision[$srpremapCount] = "Space RP by Hammereditor";
$srpremapName[$srpremapCount] = "Space rp GUI";
$srpremapCmd[$srpremapCount] = "srpGUIOpen";
$srpremapCount++;
$srpCmdsBinds = 1;

function srpGUIOpen()
{
canvas.pushDialog(spacerpmain);
}
That didn't work so I tried this:
Code: [Select]
$remapDivision[$remapCount] = "Space RP by Hammereditor";
$remapName[$remapCount] = "Space rp GUI";
$remapCmd[$remapCount] = "srpGUIOpen";
$remapCount++;
$CmdsBinds = 1;

function srpGUIOpen()
{
canvas.pushDialog(spacerpmain);
}
And it still doesn't show up in the Controls GUI like the Commands GUI did.

So, how do I fix the key binding?

Code: [Select]
$remapDivision[$remapCount] = "Space RP by Hammereditor";
$remapName[$remapCount] = "Space rp GUI";
$remapCmd[$remapCount] = "srpGUIOpen";
$remapCount++;

function srpGUIOpen(%x)
{
if(%x)
canvas.pushdialog(spacerpmain);
}
That will work, the only reason it wouldn't is a forgetup with your gui. Be sure that you have executed the gui.
« Last Edit: August 13, 2012, 05:49:32 PM by Danny Boy »

Wtf is $Cmdsbinds = 1;?

Ontopic : It works, execute the gui like danny said.

This is what I use for keybinds. It looks huge but it's good for adding keybinds to existing categories.

Code: [Select]
function SlayerClient_Support::addKeyBind(%div,%name,%cmd,%device,%action,%overWrite)
{
%divIndex = -1;
for(%i = 0; %i < $RemapCount; %i ++)
{
if($RemapDivision[%i] $= %div)
{
for(%e = %i; %e < $RemapCount; %e ++)
{
if($RemapDivision[%e] !$= $RemapDivision[%i] && $RemapDivision[%e] !$= "")
{
break;
}

if($RemapName[%e] $= %name)
{
warn("Blocking duplicate keybind:" SPC %div TAB %name);
return;
}
}
%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 ++;
}

if(%device !$= "" && %action !$= "")
{
if(moveMap.getCommand(%device,%action) $= "" || %overWrite)
moveMap.bind(%device,%action,%cmd);
}
}


This is what I use for keybinds. It looks huge but it's good for adding keybinds to existing categories.
I just use an addbinds function that was stolen from randy. It's a little bit smaller.

Code: [Select]
//Stolen from Randy
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++;
}

Code: [Select]
$remapDivision[$remapCount] = "Space RP by Hammereditor";
$remapName[$remapCount] = "Space rp GUI";
$remapCmd[$remapCount] = "srpGUIOpen";
$remapCount++;

function srpGUIOpen(%x)
{
if(%x)
canvas.pushdialog(spacerpmain);
}
That will work, the only reason it wouldn't is a forgetup with your gui. Be sure that you have executed the gui.
Yes, all 5 GUI's are executed OUTSIDE the package. But what is the %x argument for?
« Last Edit: August 13, 2012, 08:47:51 PM by hammereditor² »

But what is the %x argument for?
It tells whether the button is being pressed or released. Pressed is true, released is false.

Yes, the keybind works! Thank you!