ID:173259
 
I asked this question earlier, and I could not figure this out on my own. I have an attack code that attacks way too quickly for its own good, and I want to know how to slow it down. I've messed and messed and I just can't figure it out. Here it is (Sorry for being a nuisance to you LJR and garthor)

mob
verb
Attack()
set category="Combat"
for(var/mob/E in get_step(usr,usr.dir))
if(E.NPC==0)
E.HP-=usr.Str
view()<<"[usr] attacks [E] for [usr.Str] HP!"
if(E.player==1)
if(E.HP<=0)
E<<"<I>You died!</I>"
E.HP=E.MHP
E.MP=E.MMP
E.loc=locate(4,36,1)
E.gold+=E.gold
E.gold=0
usr.Exp+=E.Expg
E.PK=0
LvlCheck(usr)
..()
return
else
if(E.HP<=0)
usr<<"<I>You killed [E]!</I>"
usr.Exp+=E.Expg
LvlCheck(usr)
del E
return

else
usr<<"You can't attack an NPC!"
return
Woo, you're my hero. Why? Because, you give me the chance to plug my library!

Action Control

It's a great library to control any sort of delays like this. It has an included demo and all the necessary code, simply include it in your game and follow the demo instructions. Page me if you have problems.


~Polatrite~
In response to Polatrite
under your if(E.NPC == 0) part put sleep(30)
My suggestion to you, unless you are making an "action" game, or want the game's feel to be more like Diablo, is to make your attack verb simply target a mob, and then let a check handle the "swinging". The kind of verb you have there is just asking to be macroed and exploited. It also caters more to people with high connection speeds than people who may be connected via a modem. I would recommend round-based combat, for the most part, here on BYOND.
In response to DerDragon
Aye, my game is an action game, just look at Mystic Journey, it's what inspired me to do this game like this.
In response to Chance777
That doesn't work, because when you kill the monster you get a stack error or something, like I asked about in a previous post, which means you are still attacking really fast.
In response to Polatrite
I've looked your lib over, but I'm too stupid to figure out how to use it with this code:
mob
verb
Attack()
set category="Combat"
for(var/mob/E in get_step(usr,usr.dir))
if(E.NPC==0)
E.HP-=usr.Str
view()<<"[usr] attacks [E] for [usr.Str] HP!"
if(E.player==1)
if(E.HP<=0)
E<<"<I>You died!</I>"
E.HP=E.MHP
E.MP=E.MMP
E.loc=locate(4,36,1)
E.gold+=E.gold
E.gold=0
usr.Exp+=E.Expg
E.PK=0
LvlCheck(usr)
..()
return
else
if(E.HP<=0)
usr<<"<I>You killed [E]!</I>"
usr.Exp+=E.Expg
LvlCheck(usr)
del E
return

else
usr<<"You can't attack an NPC!"
return

Help! lol