ID:164683
 
Okay I need some helping on a looping effect for my game


Here is my code

mob
verb
attack(mob/M as mob in oview (1))
set category="Actions"
if(usr.action)
usr.action=1
usr<<"You can't do that!"
return
usr << "You attack [M]"
flick('Male.dmi',usr)
flick("Strike",usr)
oview() << "[usr] attacks [M]"
var/damage = usr.strength + 4
usr << "[damage] damage"
M:HP -= damage
M:Finish()


mob
proc
Finish()
if (HP <=0)
world << "[src] Dies"
del src



mob
var
action
strength
HP



What I want to do is make it. when the verb "Attack" is pressed the character will continue to strike untill the Mobs HP has reached "0". I wasn't sure how to loop the effect...


I know

mob
verb
attack(mob/M as mob in oview (1))
set category="Actions"
if(usr.action)
usr.action=1
usr<<"You can't do that!"
return
usr << "You attack [M]"
flick('Male.dmi',usr)
flick("Strike",usr) // This part has to be looped to show the user is constantly swinging his sword.
oview() << "[usr] attacks [M]"
var/damage = usr.strength + 4 // and the effect has to be looped to show everytime he swiped, he takes damage.
usr << "[damage] damage"
M:HP -= damage
M:Finish()


mob
proc
Finish()
if (HP <=0)
world << "[src] Dies"
del src



mob
var
action
strength
HP




Thanks for your help.
Easy:
while(usr.attacking)//while the stat is not zero
usr << "You attack [M]"
flick('Male.dmi',usr)
flick("Strike",usr)
oview() << "[usr] attacks [M]"
var/damage = usr.strength + 4
usr << "[damage] damage"
M:HP -= damage
if(M:HP <= 0)
usr.attacking = 0
del(M)
sleep(10)//wait 1 second..otherwise, it will loop repeatedly(in split seconds) and crash
In response to Mecha Destroyer JD
Thank you very much for your help.
  • If (usr.action) evaluates to true, then you don't need to set usr.action to 1, because then you'll never be able to attack after that.
  • When you output a mob like that ([M]), DS grammarizes it. This'll cause a problem for people with a lowercase letter at the start of the name, making it 'The [name]'.
  • The use of the ':' operator here is bogus. M is the proper type, so the '.' operator would work just fine, and it'd even be faster.
  • If you gave your argument to the attack verb the proper type, as you did, then the 'as' operator is useless, unless combining multiple types.
In response to Audeuro
Hello I am still having somem trouble with this.....

mob
verb
attack(mob/M as mob in oview (1))
set category="Actions"
while(usr.attacking)
usr << "You attack [M]"
flick('Male.dmi',usr)
flick("punch",usr)
oview() << "[usr] attacks [M]"
var/damage = usr.strength + 4
usr << "[damage] damage"
M:powerlevel -= damage
if(M:powerlevel <= 0)
usr.attacking = 0
del(M)
sleep(10)
I have written the code out in the following way, as I said I need it to Loop the battle system so the user attacks untill the oppenents health has reached 0?
In response to Nexus6669
*Bump Topic*

I left it a few days.... is there anyone who knows why this might be doing this?


Apon clicking attack verb there is no output on screen...?