ID:261390
 
I need to know where to put a sleep in my attack code or what I have to do to it. I want it so that you can't attack many times in a row.
mob
var
attacked = 0


mob/verb/Attack()
if(usr.attacked)
usr<<"You attacked!"
usr.attacked = 1
sleep(20)
usr.attacked = 0
else
usr<<"You cannot attack!"
I have this problem too in Kemet as you've noticed..
If you look at the controler for slowing down your walking speed, it should be able to work for attacking as well, I just haven't gone in and lookse at my code since my attack is based off of bump'ing, and if bump'ing is controlled by movement that should be all the code I need. But apparently its not, looks like I'm going to have to do something for attacking as well.

LJR
In response to Nadrew
Thanks m8, I'll revisit my attack code again ;)
With speed being such an issue it'd be nice if BYOND offered some kind of incoded process to control the number of times and item can be clicked or used before its allowed again.

As I'm finding errors in anything you do in a game if you try to do it too fast.

LJR
In response to LordJR
No errors but it doesn't sleep

code:
____________________________________________________________

mob
verb
Attack(mob/M as mob in oview(1))
var/damage = rand(1,5)
if(damage <= 0)
usr << "[M] easily dodges your attack!"
M << "You easily dodge [usr]'s attack."
else
M.HP -= damage
view() << "[usr] attacks [M] for [damage] HP!"
M:deathcheck()
if(usr.attacked)
usr.attacked = 1
sleep(20)
usr.attacked = 0
In response to Little Sally
Not positive but I think I see the problem. Try this but dont rely on it, I'm not as good as some others that could help you.

mob
verb
Attack(mob/M as mob in oview(1))
if(usr.attacked == 1)
sleep(20)
usr.attacked = 0
else
usr.attacked = 1
var/damage = rand(1,5)
if(damage <= 0)
usr << "[M] easily dodges your attack!"
M << "You easily dodge [usr]'s attack."
else
M.HP -= damage
view() << "[usr] attacks [M] for [damage] HP!"
M:deathcheck()
In response to Raven01
Err I found an error in that... Gimme a few minutes to fix it...
In response to Raven01
Ok I think this should work... I've been working with some complex procs for a game and my heads all messed up. But I'm pretty sure this will work.

---------------------

mob
verb
Attack(mob/M as mob in oview(1))
if(usr.attacked == 1)
usr << "You can't attack again"
else
usr.attacked = 1
var/damage = rand(1,5)
if(damage <= 0)
usr << "[M] easily dodges your attack!"
M << "You easily dodge [usr]'s attack."
else
M.HP -= damage
view() << "[usr] attacks [M] for [damage] HP!"
M:deathcheck()
sleep(20)
usr.attacked = 0




---------------------


-Raven-
In response to Raven01
Ok
In response to Raven01
I error....

        Attack(mob/M as mob in oview(1))
if(usr.attacked == 1)
usr << "You can't attack again"
else
usr.attacked = 1
var/damage = rand(1,5)
if(damage <= 0)
usr << "[M] easily dodges your attack!"
M << "You easily dodge [usr]'s attack."
else
M.HP -= damage
view() << "[usr] attacks [M] for [damage] HP!"
M:deathcheck()
sleep(20)
usr.attacked = 0


Mobs.dm:60:error:else :'else' clause without preceding 'if' statement
In response to Little Sally
Tab that else in 1 more time and it should be fixed, it musta happened when you copy/pasted it, because I have the code right here and it didnt have the else there. So just tab it once and it should be fixed




[edit] Actually I see a few indentation errors in the code you just showed me, but they aren't like that here. I have an idea, I'll show ya how it should look. If your game is run-able, then add this verb:


mob
verb
Code(message and message)
world << "[usr] says, [Message]"


Then run your game.
In response to Little Sally
In response to LordJR
No it does, LordJR, but that else statement is not indented correctly...
In response to Raven01
    Attack(mob/M as mob in oview(1))
if(usr.attacked == 1)
usr << "You can't attack again"
else
usr.attacked = 1
var/damage = rand(1,5)
if(damage <= 0)
usr << "[M] easily dodges your attack!"
M << "You easily dodge [usr]'s attack."
else
M.HP -= damage
view() << "[usr] attacks [M] for [damage] HP!"
M:deathcheck()
sleep(20)
usr.attacked = 0


Mobs.dm:60:error:else :'else' clause without preceding 'if' statement
Mobs.dm:60:error::missing expression
In response to Nadrew
Hmm. Wouldn't that just make it sleep for a while, then execute all of the attacks? Like if i held down a macro, it would sleep 20, then start spamming the attacks? I havn't tested it out, but thats what it looks like.

-Rcet
In response to Rcet
I know what he was getting at, I didn't use his excate code, just reminded me of some previous code I've used recently for movement, and appiled that to my Attack system, not home yet so don't know how it works, but it should be fine.

LJR