ID:160239
 
So I use a lot of macros for my game that are predefined, but Im adding in an option for players to redefine the verbs to the keys they want. I dont want them to use the regular options to do this I wanted to create an option system similar to most games where you have a choice of actions and can define those to any key. However I cant find a way to use code to define macros in game. I know about the script file but I only how to use that to predefine.
My K_KeyHandling library is perfect for that. The documentation should be sufficient for you to understand how to use it. You simple have to reset the value of the Macro datum's <code>key</code> var and everything will work that way it's supposed to.
You can't redefine BYOND macros at runtime. Of course, there is nothing stopping you from modifying the actual functions called by the macros. Here's an example: you set the A button macro-d to the ".a_key" command at compile time, and your verb looks like this:
client/var
a_button_function = "attack"
client/verb/key_A()
set name = ".a_key" //so it's hidden from command expansion (optional)
switch(src.a_button_function)
if("attack") src.mob.Attack(...)
if("jump") src.mob.Jump()
//...

Note this is a very crude example intended purely to demonstrate how it's done. You can go ahead and use some of the libraries made for this; just so you know the principle behind how they work.
In response to Kaioken
Skin Reference:
Macros

Macros can also be changed at runtime. If a macro does not have an ID, you can refer to it by its key combination. If you have a macro set named macro1 and have a Ctrl+E macro for instance, you could use winset() with "macro1.Ctrl+E". These are the parameters that can be changed using winset():

name
command
is-disabled
The name is actually the full key combination as it would appear in the macro editor, like CTRL+E, Space+REP, or Alt+Shift+F1. This is not case-specific and it doesn't matter where you put modifiers like CTRL+, SHIFT+, etc.

A new macro can be added to a macro set at runtime by including a parent parameter, which points to the ID of an existing macro set. Using the example above, Ctrl+E could be added as a macro at runtime like so:

winset(usr, "myCtrlEmacro", "parent=macro1;name=Ctrl+E;command=exit")
Macros that were added this way can also be deleted again by setting their parent to a blank value.

winset(usr, "macro1.myCtrlEmacro", "parent=")


I've never tried it, just saying it could be possible.
In response to Kaiochao
Oh, right, that's good to know. Never thought much of macros as actual "controls" you could mess around with!
In response to Kaioken
Actually that isnt exactly what I meant. What im trying to do is I have 4 attack keys so they can assign one of their skills to one of the 4 attack keys. so they can only use 4 skills quickly at a time. Those 4 attack verbs are changed by the player during game play, but they are set to macro key a,s,d,f. What im trying to do is make it so they can assign attack1-4 to say j,k,l,; if they wanted or what ever they choose. Or another way is instead of having the default arrow keys to move they can change them to w,a,s,d to move. Like a regular game where you can assign the verbs to whatever macros you want. Hope that explains it better