ID:890458
 
(See the best response by DarkCampainger.)
Code:
mob
Login()
world << "[src] has logged in!"

var
inAction = 0
actionCount = 0
fakeAttack = 0
damage = 100

verb
Punch_Left()
set name = "Left Punch"

if(usr.inAction)
usr.fakeAttack = 1
usr.actionCount++
usr.damage++

usr.inAction = 1
usr.actionCount++

view(0) << "[usr] retracts their left arms..."

spawn(23)
damage(damage, "left punch")

proc
damage(damage, attackname)

if(fakeAttack)
fakeAttack = 0
return

if(!inAction) return

usr.inAction = 0
usr.fakeAttack = 0

view(0) << "[src] left punch does [round(src.damage)] damage. | [src.actionCount]"


Problem description:
Basically my melee system checks if you execute the attack again to cancel the previous one but if you spam it they will stack and rapidly execute one after another...
using variable like punching then check if player can use Attack
huh..? why would it matter what the variable is called i already check it see if inaction variable is already being 1 to set faking to 1 and if faking is 1 by the time the previous attack is spawned to return the attack and not finish it..?

but if i spam it fast enough all of them will stack and inaction will be 1 i cant think of a way to prevent it.
basically it should look like this..

Gokussj99 retracts their left arm...
(wait if cast another attack with less then the spawn timer then cancel the previous action)
Gokussj99 retracts their left arm...

then if not called again the last attack lands and the first one doesn't

Gokussj99 left punch does x damage.(2)

but if used again..

Gokussj99 retracts their left arm...

Gokussj99 retracts their left arm...

Gokussj99 retracts their left arm...

Gokussj99 left punch does x damage.(3)

the last one lands and the two above dont this is what im trying to do..

But my code is wrong so if you spam the attack fast enough the attacks already sent will land because by the time they are landing InAction is set to 1 again and im not sure how to prevent that.
I understood none of that.
basically.. once you cast an attack... if you cast it again it is called faking the previous attack should not land but the second one.

and etc if more are casted say you cast 6 only the 6th one should land the others should not.
No that code just breaks the whole thing because it returns before the inaction can be reset.

the returns need to be called in the end not at the start.
The issue is no matter how many times you spam the attack will eventually land.

Gokussj99 retracts their left arms...
Gokussj99 retracts their left arms...
Gokussj99 retracts their left arms...
Gokussj99 retracts their left arms...
Gokussj99 retracts their left arms...
Gokussj99 retracts their left arms...
Gokussj99 left punch does 105 damage. | 6


It should never land if you keep casting it is pretty much the objective.
update above.
I have been on this stupid issue for longer than I want to admit.

D:

Basically

Gokussj99 Attacks (CANCELLED)

Gokussj99 Attacks (NOT CANCELLED)

Basically just cut off the first attack period and make sure the delay is the full length.

I'm sorry if I can't properly explain what the issue is it seems no one understands me :(

I appreciate you taking your time to try to help me.
Best response
You've got the right idea with the actionCount variable, but you're way overcomplicating it:
mob
Login()
world << "[src] has logged in!"

var
actionCount = 0
actionStarted = 0
damage = 100

verb
Punch_Left()
set name = "Left Punch"

view(0) << "[src] retracts their left arms..."

// Increment and store the current actionCount
var/actionId = ++src.actionCount

spawn(23)
// If actionCount hasn't changed, then no new attacks have been called
if(src.actionCount == actionId)
// Factor the count into the damage
var/dam = src.damage + (src.actionCount - src.actionStarted)
// Reset the damage bonus
src.actionStarted = actionCount
// Do the damage
damage(dam, "left punch")

proc
damage(dam, attackname)
view(0) << "[src] left punch does [round(dam)] damage."


Basically, you use the current count as an "ID" for each action. If the actionCount changes before an attack executes, that means another attack has been run and this one should cancel. If the actionCount hasn't changed, then the attack is uninterrupted and should execute.
Omg.. i love you DarkCampainger you're a life saver..
In response to Gokussj99
Glad to help. I made a small tweak to it by adding actionStarted, to prevent a race condition. Make sure you grab the current version.