ID:1164762
 
I made this for a friend, I wanted to keep it simple so I made it using this method. Anyone can use it, if you so happen to need it. Hope this helps someone out, {:

EDIT: I didn't check to see if this works, but I'm pretty sure it does work fine.

mob/var/Charging = 0
mob/verb
Charge_Punch()
var/Damage = 5
src.Charging = 1
while(src)
if(!src.Charging || Damage >= 30) //user isn't charging || Damage is greater or equal to 30.
src.Charging = 0
for(var/atom/A in get_step(src, src.dir))
src.Deal_Damage(A, Damage)
break
Damage += rand(3, 6)
sleep(10) //Don't want it to raise too fast.

mob/proc
Deal_Damage(mob/Enemy, Damage)
Enemy.dir = get_dir(Enemy, src)
src.dir = get_dir(src, Enemy)
Enemy.Health = round(Enemy.Health - Damage)
src.Death(Enemy)

Death(mob/Enemy)
if(Enemy.Health <= 0)
if(Enemy.client)
world << text("[] has died to [].", src, Enemy)
// Enemy is a player
else
del(Enemy)
// Enemy is a NPC
I think you'd want to use a while() loop how it was intended.
src.Charging = 1
while(src.Charging && Damage < 30)
Damage += rand(3, 6)
sleep 10

// This happens when the while() has broken.
src.Charging = 0
for(var/atom/A in get_step(src, src.dir))
src.Deal_Damage(A, Damage)

// When src is deleted, the entire verb will die,
// so there's nothing to worry about there.
What happens if I click the Charge_Punch() verb twice? Or three times? Or ten times? ;)

I assume you meant to set Charging to zero on the second use, but be aware there's a race condition there where you can "end" the charge and start another one during the sleep(10), allowing you to charge several punches at once.

Also, why are you using text()? Wouldn't it be easier to embed the values directly than to have to count out the arguments to match up the brackets with the values?
@Kaiochao: Thanks for making it shorter {: I wasn't even thinking about doing that.


@DarkCampainger: I wasn't worried about making the checks, I thought my friend could handle that.

I don't see what you're talking about which changing the var to zero?

I think it just looks a little neater, I just recently started using text(). I was so used to doing usr << "", I just wanted to do something new.
I came up with something a bit simpler when I was doing something like this:

verb
Charge()//set to call when the attack button is raised.
if(attack_time>=world.time+30)//if a minimum secs have passed for a charge strike.
//do charge attack, otherwise- don't do anything.

Could be improved a bit by doing something like this:
var/dmg=100//the base dmg.
time_passed=world.time-attack_wait//difference of the amount of ticks waited.
var/mod=round(time_passed/5)/100+1.0//i prefer percentage damage.
dmg*=mod//boost the damage by the mod which is atleast 1 so that damage doesn't decrease. Since it's a charge you might want to use 2.0 or 3.0 instead.

//then deal damage however you like


I only came up with this way because I prefer to avoid loops and sleeping as often as possible when I code since I work on mostly action/combat type games that use a lot of spawning and sleeping to determine various things(personal preference).