ID:272419
 
How would I make it so that when I press two keys at once it activates a special move. for example. If I press Up and 7 at the same time I would do a smash attack that hits up, and when I only use 7 it just does a normal attack that hits sideways.
By nature, a player can only send one command per tick. However, you can bypass this by using javascript to detect key presses and send an appropriate command or easily check for consequently-sent commands (which I think how some non-BYOND games that do this work anyway). You'd have pressed keys (sent commands in fact) expire after 1-3 ticks, so you the player would still need to time it within reason to achieve the special move. Example implementation:
client
var/list/pressed_buttons //list to keep track of buttons the player pressed that didn't expire yet
verb
keypress(keyname as text) //a verb to intercept all player-sent combo-able key commands
set name = ".key"
if(!keyname) return
if(!pressed_buttons) //if the list isn't initialized yet
pressed_buttons = new //then initialize it - create a new list!
pressed_buttons += keyname //keep track of the pressed key
spawn(4) //after this proc returns, and a delay
if(pressed_buttons) //if the list still exists
pressed_buttons -= keyname //remove it from the list, though, so Timing Is Key (excuse the pun)
if(!pressed_buttons.len) //if the list is no longer needed,
pressed_buttons = null //then get rid of it to save objects (the garbage collector will now delete it)
if(!src.checkCombos()) //call our custom proc and if returns false, then
//do your normal/usual key behaviors here:
switch(keyname)
if("punch") src.mob.Punch()
if("kick") src.mob.Kick()

proc/checkCombos() //a proc to check if the player scored any combos
//quick example implementation: combo of Punch-Kick-Punch
for(var/i=1,i+2 <= src.pressed_buttons.len) //loop through the list, manually
if(pressed_buttons[i] == "punch") //if the current element is a punch
if(pressed_buttons[i+1] == "kick") //and the one after it is a kick
if(pressed_buttons[i+2] == "punch") //and the one after the last one is a punch too
src << "COMBO SCORED"
src.mob.XYZCombo()
return 1 //indicate to the caller, the verb, that a combo was done, so it should not do the normal actions of punching, etc

Untested (and I'm tired), but that should work. Your macros' commands would be:
<code>.key "punch" .key "kick"</code>
For example. Note it'd be better to use number key IDs instead of strings! You can employ #defines to still be able to name them in your DM code. Other things the above code should have used but I have changed for clarity, is use the && operator, and ensure the list of keys is actually long (lenghty) enough to contain enough keys to possibly score a combo, before checking if any combo was scored.
Something different you also need to do is implement a flexible dynamic system for checking for scored combos instead of the messy example I did.
*: Also, it seems to me it would be highly convenient to use a string instead of a list here to store the pressed_buttons; you could automatically check for any given combo by a simple findtext() call. If you're not sure how to store this kind of data in a list, look up params2text() and list2params(), they should enlighten you.

EDIT: Tweaked code
In response to Kaioken
What's the XYZ combo supposed to be, I got an error, src.XYZCombo: undefined proc.
In response to Element Hero creator
Y'know, that kind of response makes me wonder, "why bother?".
It's supposed to be, DON'T DIRECTLY COPY MY CODE especially when you clearly have no idea how it's supposed to work. My code was not meant to be used, and parts were intentionally left unoptimized/incomplete on purpose because the purpose of posting it was to demonstrate how to do this, not for you to copy it and expect it to work in your game.

What's the XYZ combo supposed to be, I got an error, src.XYZCombo: undefined proc.

But gee, I don't know what it could possibly be. It especially can't be similar to the purpose of the Punch() and Kick() procs in my code that I wasn't even aware or cared that existed in your game, hmm...
In response to Kaioken
Sorry about that, I thought that it was listed somewhere in your code, then I posted about, like 2 minutes later I noticed that I had to program the XYZCombo to what I wanted it to do. That was my bad, sorry.

Anyways, I was wondering..

client
var/list/pressed_buttons //list to keep track of buttons the player pressed that didn't expire yet
verb
keypress(keyname as text) //a verb to intercept all player-sent combo-able key commands
set name = ".key"
if(!keyname) return
if(!pressed_buttons) //if the list isn't initialized yet
pressed_buttons = new //then initialize it - create a new list!
pressed_buttons += keyname //keep track of the pressed key
spawn(4) //after this proc returns, and a delay
if(pressed_buttons) //if the list still exists
pressed_buttons -= keyname //remove it from the list, though, so Timing Is Key (excuse the pun)
if(!pressed_buttons.len) //if the list is no longer needed,
pressed_buttons = null //then get rid of it to save objects (the garbage collector will now delete it)
if(!src.checkCombos()) //call our custom proc and if returns false, then
//do your normal/usual key behaviors here:
switch(keyname)
if("Normal-Attack") Shop_Me()
if("Special-Attack") Shop_Me()

proc/checkCombos() //a proc to check if the player scored any combos
//quick example implementation: combo of Punch-Kick-Punch
for(var/i=1,i+2 <= src.pressed_buttons.len) //loop through the list, manually
if(pressed_buttons[i] == "Normal-Attack") //if the current element is a punch
if(pressed_buttons[i+1] == "Special-Attack") //and the one after it is a kick
if(pressed_buttons[i+2] == "Normal-Attack") //and the one after the last one is a punch too
src << "COMBO SCORED"
//src.XYZCombo()
return 1 //indicate to the caller, the verb, that a combo was done, so it should not do the normal actions of punching, etc


Where it lists the Normal-Attack, and Special-Attack, is it right for me to name it as that, because that's the way I set up the macro's for it.
In response to Element Hero creator
No, it isn't. That would probably make the game, or possibly even the host's PC, freeze whenever a player completed a combo, and get stuck in an infinite loop.
In response to Kaioken
Then what do I list there?
In response to Element Hero creator
In response to Glarfugus
K, after I finish this quest on RuneScape.