Problem description: My problem is that I don't know how to use this library. I am also opened to other ways to implement macros.
Link to Library: http://www.byond.com/developer/Kaiochao/AnyMacro
Code:
////////////////////////////BUTTON TRACKER - KAIOCHAO/////////////////////////////////////////////
button_tracker
var
/*
Keeps track of what buttons are pressed.
You shouldn't ever need to use this in your own code.
*/
list/is_pressed
proc
/*
Press a button.
Until the button is released, IsButtonPressed returns TRUE.
Calls ButtonPressed if the button wasn't already pressed.
*/
Press(button)
if(IsReleased(button))
if(!is_pressed)
is_pressed = list()
is_pressed[button] = TRUE
Pressed(button)
/*
Release a button.
Until the button is pressed, IsButtonPressed returns FALSE.
Calls ButtonReleased if the button wasn't already released.
*/
Release(button)
if(IsPressed(button))
is_pressed -= button
Released(button)
if(!length(is_pressed))
is_pressed = null
/*
Is the button currently pressed?
Returns TRUE or FALSE.
*/
IsPressed(button)
/*
This should return TRUE or FALSE.
This seemingly overcomplicated expression
guarantees that it results in TRUE or FALSE
and not, like, null, or something.
*/
return is_pressed && is_pressed[button] || FALSE
/*
Is the button currently released (not pressed)?
Returns TRUE or FALSE.
*/
IsReleased(button)
return !IsPressed(button)
/*
Called when a button is pressed.
Does nothing by default, but handy for overriding.
*/
Pressed(button)
/*
Called when abutton is released.
Does nothing by default, but handy for overriding.
*/
Released(button)
////////////////////////////////////ANY MACRO//////////////////////////////////////////////////////////////////////////////////////
/*
This library adds button tracking for clients,
for all macros caught by the Any macro, including:
* All keyboard keys
* All gamepad face buttons, stick buttons, shoulder buttons, and triggers
Buttons are tracked using the Button Tracker from that library.
By default, the Any macro is bound for the client in /client/proc/BindAnyMacro()
using a couple calls to winset() (one for the press, one for the release).
This allows for plug-and-playability, but those calls have overhead that you can avoid
by defining those macros as .dmf or .dms macros.
If you do define the macros elsewhere, include this in your code:
client/bind_any_macro = FALSE
*/
///////////////////////////////////////////////////////////////////////////////////////////////////
button_tracker/echo
var
// The output target receives messages about changes in button states.
output_target
// The output target is received by the constructor.
New(output_target)
src.output_target = output_target
// When a button is pressed, send a message to the output target.
Pressed(button)
if(!(button in usr.hotkeys)){
return
}
//Made my abilities into verbs so I can call them here.
//My gut tells me that this is a poor attempt and needs to be
//burned
call(usr.hotkeys["[button]"])(usr)
// When a button is released, send a message to the output target.
Released(button)
if(!(button in usr.hotkeys)){
return
}
//My attempt to simulate that a player is holding down a button
if(usr.hotkeys["[button]"] == /mob/verb/Basic_Guard){
call(usr.hotkeys["[button]"])(usr)
}
client
var
tmp
/* This is a reference to the Button Tracker that keeps track of macros
caught by the Any macro. */
button_tracker/macros
/* Set this to FALSE in your code to avoid calling winset() to bind the Any macro
if you have the Any macro defined in your interface already.
Alternatively, you could override BindAnyMacro() to do nothing. */
bind_any_macro = TRUE
New()
. = ..()
macros = new
if(bind_any_macro){
BindAnyMacro()
}
macros = new/button_tracker/echo(src)
proc
BindAnyMacro(){
winset(src, "AnyMacro","parent=macro; name=Any; command=\"press-button \\\"\[\[*]]\\\"\"")
winset(src, "AnyUpMacro","parent=macro; name=Any+Up; command=\"release-button \\\"\[\[*]]\\\"\"")
}
verb
/* Call this with any button you want to track.
By default, this is called by all keyboard keys and gamepad buttons. */
press_button(button as text){
set hidden = TRUE
set instant = TRUE
if(macros){
macros.Press(button)
}
}
/* Call this with any button you want to track.
By default, this is called by all keyboard keys and gamepad buttons. */
release_button(button as text){
set hidden = TRUE
set instant = TRUE
if(macros){
macros.Release(button)
}
}
-How I am map buttons to skills
mob/proc/basicHotkeys(){
if(!hotkeys){
hotkeys = new
}
hotkeys["F"] = new/mob/verb/Primary_Attack
hotkeys["G"] = new/mob/verb/Basic_Guard
}
but if you mean about custom macro, you can add some list with actions
have you any questions, call for more.