ID:1981218
 
(See the best response by Lummox JR.)
Problem description: I really didn't know where this was so pose to go so if this is the wrong spot let me know but, i'm wanting to do have it so people have to hit like ( A,A,A(Action-Key) ) for one move then another example ( A,S,D,Q,E(Action-Key) ) so on so fourth what would be the best way for me to do this. and if you could maybe give a tiny example to give me the right path



I made a demo for this awhile back, but I can't promice you'll find it useful.


http://www.byond.com/developer/Ss4toby/ButtonCombos
You should check findtext() and copytext() procs. You can make var - Combo, and when you press any button you add some symbols to this var. and after every think you need is check this var by findtext and copytext.

Sorry for my poor english.
Marek, I don't think he meant typing in a string then parsing it into commands, but rather direct commands being strung together and accomplishing a different task than individual button presses. In which case, I haven't checked out Ss4's library, but I'd just handle it something like.

list/buttonpresses = new/list()
on <key> <time> = what <time> was
after <time> buttonpresses = new/list()
on <key> add <key> to buttonpresses
depending on what's in buttonpresses, do different things.


so a, would call attack(basic)
a,a, would call attack(strong)

etc.
Best response
I've made posts on combo systems before, but here's the gist of what you need:

1) Each key you might use in a combo system should call a master routine that adds it to a combo.

2) In the master routine, you'll have a timeout. It resets every time a new command is added, but if it ever expires, the combo fires. If there's no complete combo, you simply fire the partials, always taking the longest possible sequence starting from the beginning.

3) The master routine keeps track of the current chain of un-fired commands. If the new key creates a chain that can't exist in any combo, (e.g., you have A-A and Q-W but no A-A-Q), then you take the longest combo you can starting at the beginning, fire that and remove it from the chain, and use what's left to start building a new combo. So in my example A-A-Q, the A-A would be fired and Q would be left. If you hit W right after that, you'd have the Q-W combo.

Roughly it looks like this:

// Use one of these for each player mob
// Technically you can fold this into the code for the mob itself, but if so
// consider changing var names, like prefixing them all with combo_
combomaster
var/list/combos // fill this with all the possible combos
var/chain = ""
var/spawnid = 0
var/timeout = 2.5 // 1/4 s delay

proc/AddCombo(mob/M, code)
spawnid = (spawnid+1) & 0xFFFF
var/id = spawnid
chain += code
spawn(timeout)
if(chain && id == spawnid) // if the timer wasn't reset
FireFirst(M)
return
var/matches = 0
var/exact
/*
Look for any valid combo that can begin with the current chain.
Possible outcomes:

1) Multiple combos can start with this chain. Wait for more keys.
2) Only one combo can start with this chain, but it isn't finished. Wait.
3) Only one combo starts with this chain, and it's finished. Fire it.
4) No combos start with this chain. Break the chain.
*/

for(var/c in combos)
if(findtextEx(c, chain) == 1)
// if multiple matches exist, wait for more keys
if(++matches > 1) return
if(c == chain) exact = 1
if(exact || !matches) FireFirst(M)

// fire any combos in the current chain
proc/FireFirst(mob/M)
var/c,best,l,bl=0
do
while(chain)
bl = 0
// find the longest possible combo that can start this chain
for(c in combos)
// see if chain starts with c
if(findtextEx(chain, c, 1, 1))
l = length(c)
if(l > bl)
best = c; bl = l
if(!bl) break
. = 1
chain = copytext(chain, bl+1)
M.DoCombo(best)
// failsafe: if no combos found at all, drop the first key and try again
if(!. && chain)
chain = copytext(chain, 2)
while(!.)

That's a fairly simple setup, but the gist should be clear. I added in some failsafes for situations like if you defined A-A and Q-W but forgot to do A, Q, or W on their own.