Author Topic: Default key (rebindable)?  (Read 3780 times)

Would it be possible to have a key, that is rebindable, that isn't blank by default?
Code: [Select]
function ToggleGUI(%a)
{
if(!%a)
return;
if(MyAdd-OnGUI.isAwake())
canvas.popdialog(MyAdd-OnGUI);
else
canvas.pushdialog(MyAdd-OnGUI);
}

$remapDivision[$remapCount] = "My Add-On";
$remapName[$remapCount] = "Toggle GUI";
$remapCmd[$remapCount] = "ToggleGUI";
$remapCount++;

movemap.bind(device, button/action, function);
example:
movemap.bind(keyboard, W, moveForward);
movemap.bind(keyboard, f3, ToggleGUI);


This will overwrite a control, so be thoughtful about it.
Edit: If you want to check if a control is already bound to a button:
movemap.getCommand(device, button);
example:
Code: [Select]
if(movemap.getCommand(keyboard,f3) $= "")
movemap.bind(keyboard,f3,ToggleGUI);
else
doSomethingElse???
« Last Edit: June 21, 2014, 11:23:44 PM by Chrono »

movemap.bind(device, button/action, function);
example:
movemap.bind(keyboard, W, moveForward);
movemap.bind(keyboard, f3, ToggleGUI);


This will overwrite a control, so be thoughtful about it.
Edit: If you want to check if a control is already bound to a button:
movemap.getCommand(device, button);
example:
Code: [Select]
if(movemap.getCommand(keyboard,f3) $= "")
movemap.bind(keyboard,f3,ToggleGUI);
else
doSomethingElse???
I made a little gui to say it couldn't bind, but now it wont show up.
when I type canvas.pushdialog(RebindGUI); it comes up
but it doesnt come up by default.
EDIT: Nevermind, typo in code
EDIT 2: Never-Nevermind, didnt fix it.
« Last Edit: June 22, 2014, 12:09:10 AM by AWESOME :D »

You're executing the gui at the start of client.cs, right?

Yes, I am.
Code: [Select]
exec("./RebindGUI.gui");As I said earlier, typing canvas.pushdialog(RebindGUI); into console launches it.

Could you show me your code?

http://www.mediafire.com/download/157yykl3bo4qmxu/Client_RapidClickDev.zip

client.cs
Code: [Select]
//You only need to change this to change speed.
exec("./AutoClickGUI.gui");
exec("./RebindGUI.gui");
function rapid(){commandtoserver('Activatestuff'); $Click = schedule(32,0,rapid);}
function ToggleAutoClick(%a)
{
if(!%a)
return;
if(AutoClickGUI.isAwake())
canvas.popdialog(AutoClickGUI);
else
canvas.pushdialog(AutoClickGUI);
}
$remapDivision[$remapCount] = "Auto-Clicker";
$remapName[$remapCount] = "Toggle GUI";
$remapCmd[$remapCount] = "ToggleAutoClick";
$remapCount++;
if(movemap.getCommand(keyboard,f11) $= "")
movemap.bind(keyboard,f11,ToggleAutoClick);
else
canvas.pushdialog(RebindGUI);

« Last Edit: June 22, 2014, 12:55:19 AM by AWESOME :D »

Maybe because the game is doing canvas.setCanvas("MainMenuGUI"); after the RebindGUI pops up.

Try putting it on a schedule, you might also want to change that checking a little. Sorry.

Code: [Select]
if(movemap.getCommand(keyboard,f11) $= "")
movemap.bind(keyboard,f11,ToggleAutoClick);
else
canvas.pushdialog(RebindGUI);
Will cause the popup to come up even if it's ToggleAutoClick that's bound to f11, or even rebind ToggleAutoClick back to f11 if you change it and restart.
This can be fixed with a canvas.getBinding(command) check.
Code: [Select]
if(movemap.getBinding(ToggleAutoClick) $= "")
{
if(movemap.getCommand(keyboard,f11) $= "")
movemap.bind(keyboard,f11,ToggleAutoClick);
else
canvas.schedule(33,pushdialog,RebindGUI);
}
It checks if the command isn't bound yet, then tries to bind it to f11, and then calls the rebindgui if that fails on a delay so that it's not immediately closed.

Thanks! That fixed it.
Off topic: how do i center a gui?
EDIT: Specifically the RebindGUI.gui
« Last Edit: June 22, 2014, 12:49:20 PM by AWESOME :D »

Thanks! That fixed it.
Off topic: how do i center a gui?
Had this same problem, lol.
On your pop-up function throw something like
Code: [Select]
%x=getword(getres(),0)/2-(half of your gui length);
%y=getword(getres(),1)/2-(half of GUI heigth);
GUINAME.position = %x@" "@%y;

Had this same problem, lol.
On your pop-up function throw something like
Code: [Select]
%x=getword(getres(),0)/2-(half of your gui length);
%y=getword(getres(),1)/2-(half of GUI heigth);
GUINAME.position = %x@" "@%y;

so, like in the client.cs?
could you put it in context?

so, like in the client.cs?
could you put it in context?
Yes, as for context this is some of what I'm using:
Code: [Select]
function SAN_PushGui()
{
    canvas.pushDialog(SAN_Gui);

    %x = getWord(getRes(), 0);
    %y = getWord(getRes(), 1);
    %x = %x/2-235;
    %y = %y/2-180;
    SAN_Window.position = %x@" "@%y;
}

Yes, as for context this is some of what I'm using:
Code: [Select]
function SAN_PushGui()
{
    canvas.pushDialog(SAN_Gui);

    %x = getWord(getRes(), 0);
    %y = getWord(getRes(), 1);
    %x = %x/2-235;
    %y = %y/2-180;
    SAN_Window.position = %x@" "@%y;
}
Code: [Select]
//You probably shouldn't ever have to change this.
exec("./AutoClickGUI.gui");
exec("./RebindGUI.gui");
function rapid(){commandtoserver('Activatestuff'); $Click = schedule(32,0,rapid);}
function ToggleAutoClick(%a)
{
if(!%a)
return;
if(AutoClickGUI.isAwake())
canvas.popdialog(AutoClickGUI);
else
canvas.pushdialog(AutoClickGUI);
}
$remapDivision[$remapCount] = "Auto-Clicker";
$remapName[$remapCount] = "Toggle GUI";
$remapCmd[$remapCount] = "ToggleAutoClick";
$remapCount++;
function PushRebindGUI()
{
canvas.schedule(33,pushdialog,RebindGUI);

%x = getWord(getRes(), 0);
%y = getWord(getRes(), 1);
%x = %x/2-112;
%y = %y/2-79;
}
if(movemap.getBinding(ToggleAutoClick) $= "")
{
if(movemap.getCommand(keyboard,f11) $= "")
movemap.bind(keyboard,f11,ToggleAutoClick);
else
PushRebindGUI();
}
it's not working

You can automatically have the engine center the GUI. While in the GUI editor (I'm assuming this is what you used), put "center" for horizSizing and vertSizing. There's no need for using the getWord(getRes() blah blah blah thing.

You can automatically have the engine center the GUI. While in the GUI editor (I'm assuming this is what you used), put "center" for horizSizing and vertSizing. There's no need for using the getWord(getRes() blah blah blah thing.
Yeah there's this.
Also:
RebindGUI.position=%x@" "@%y;