ID:845626
 
(See the best response by Boubi.)
    punch
format = "$'punch', $'p'; $anything; ~$mob(oview, user, 0)"
Process(mob/user, T, mob/M)
var/dmgreduc = 25 - M.DamageReduction
var/damage = round((dmgreduc/100)*user.PowerLevel)

// BATTLE CHECKS //
user.CheckInView(M)
//////////////////

if(M.Unconcious == 1)
user << "You can't attack someone who is unconcious you must finish them!"
return

if(T == "right" || T == "r")

// Var Changes //
user.InAction = 1
user.inFight = 1
user.fighting += M
user.Energy -= 3
M.inFight = 1
M.fighting += user
////////////////

// Messages //
user << "<font color=blue><b>You retract your right arm...</b></font>"
user.inview << "[user.name] retracts their right arm..."
M << "<font color=red><b>[user.name] retracts their right arm...</b></font> [M.CheckPowerTips(M.MaxPowerLevel, 1)]"
/////////////

// Execute Attack //
// I want this proc to be cancelled if starting another action such as another punch or kick or something it doesnt matter im confused on how to do it currently ;/
user.Attack(user, M, damage, 1)
///////////////////


proc
mob
proc
Attack(mob/user, mob/M, damage, attacktype)
if(attacktype == 1)
while(user.InAction == 1)
spawn(25 - user.Speed)
M.PowerLevel -= damage
M.Energy -= 3
user << "[damage]"
M << 2
user.inview << 3
user.InAction = 0
M.CheckPower()
break


Problem description:
Trying to figure a good way to cancel an attack to make a attack faking system say you start an attack and it takes a moment to take effect but then you do the same attack again you want the last one to cancel out and the new one proceed.
bump i tried changing the inaction to 0 to see if it would stop it and it didnt T.T any ideas?
I would advise to refrain from bumping your posts after 6 hours as you're just as important as other users using this forum. You're only bumping them down.

You could simply have a few if() checks to check if you're still able to do something throughout the proc. Your while() proc is rather redundant here, as it doesn't loop more than once.

// at the top of Process() cancel your previous action
if(user.InAction) user.InAction = 0
// execute your spawn() and have a check after
spawn(25 - user.Speed)
// make your check, break if all fails
if(!user.InAction) return
// now continue on with the proc
In response to Boubi
Boubi wrote:
I would advise to refrain from bumping your posts after 6 hours as you're just as important as other users using this forum. You're only bumping them down.

You could simply have a few if() checks to check if you're still able to do something throughout the proc. Your while() proc is rather redundant here, as it doesn't loop more than once.

// at the top of Process() cancel your previous action
> if(user.InAction) user.InAction = 0
> // execute your spawn() and have a check after
> spawn(25 - user.Speed)
> // make your check, break if all fails
> if(!user.InAction) return
> // now continue on with the proc


Sorry about the bump anyways it didn't work.

it cancelled the second command instead of the first one.
In response to Gokussj99
Best response
My testing may be inaccurate, but this might help you. I have setup a little demo and tried it. It worked for me, or I believe it worked.

// create a temporary doingsomething variable
mob/var/tmp/DoingSomething = 0

// start some action
mob/verb/SomeAction()
// check if you're on stage 1 of doing something
if(usr.DoingSomething == 1)
// if you're doing something stop doing it
usr.DoingSomething = 0
// now wait a breif moment to allow the previous action to cancel
sleep(2)

// start doing something
usr.DoingSomething = 1
// wait out the time with a for() loop
for(var/a = 1 to 15)
// keep sure that you're still doing something
if(!usr.DoingSomething)
// stop the action and continue the new one
world << "You have stopped doing something."
return
// wait one millisecond and continue with the time
sleep(1)

// do whatever you were doing (stage 2: unstoppable)
usr.DoingSomething = 2
world << "You have done something."
// stop doing your action
usr.DoingSomething = 0
I think a more robust solution may be to use an incrementing ID to mark each action. Basically, you give your mob a tmp "ActionId" variable that starts at zero. Whenever you want an action to interrupt/be interrupted, increment the mob's ActionId and copy the new current value into a local variable of that action's process/verb. After any sleep()s, spawn()s, or other delays, check if the action is still active by comparing the local ActionId to the mob's ActionId. If they're no longer the same, another action has interrupted it.