ID:142607
 
Code:
mob
verb
A()
set category= "Fighting"
set hidden=1
flick('basepunch.dmi',usr)
if(usr.pk==0)
usr<<"your in a non pk place"
return
for(var/mob/M in get_step(usr,usr.dir))
var/damage = usr.Str/3
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()


Problem description:

can someone please edit my code so that the mob(usr) attacks with the attack verb then has to wait a couple of seconds to use it again.i know it has to get to do with delay, but can someone show me how.
Give mobs a nextattack variable. Remember to make it tmp so it's not saved. When you attack, make sure world.time >= nextattack. If so, set nextattack to world.time + some amount.
In response to Garthor
Garthor wrote:
Give mobs a nextattack variable. Remember to make it tmp so it's not saved. When you attack, make sure world.time >= nextattack. If so, set nextattack to world.time + some amount.


im not really good at directions, please post code
In response to Agrey123
Code is directions. No, I won't do your work for you.
In response to Garthor
well u told me the answer in a confusing way you might aswell put it together for me cuz the way ur telling me to do it is really confusing and makes no sence. it really doesnt help.
In response to Agrey123
I explained things in the most straightforward way possible. If you're having trouble understanding it, then you need to go back and read some tutorials. Carefully.
In response to Garthor
hmm, 1 question tho, about the world.time , could i just put like if usr.nextattack=1, then return, then put like sleep(10) // so it waits 1 second, then usr.nextattack=0
so that it doesnt allow the next attack u use to hit right away? or would it not work?
In response to Agrey123
You could do that, but it's generally not a great idea, because it will break if multiple things are trying to interact with the nextattack variable, or if an object which is scheduled to reset it gets deleted before it can.
In response to Garthor
ok so im trying to use that nextattack var u told me about, but im probebly getting what ur trying to say in a wrong way, here is where i got, can u point out what im doin wrong

mob
verb
A()
set category= "Fighting"
set hidden=1
flick('basepunch.dmi',usr)
if(usr.pk==0)
usr<<"your in a non pk place"
return
if(world.time >= nextattack)
sleep(20)
usr<<"delay"
for(var/mob/M in get_step(usr,usr.dir))
var/damage = usr.Str/3
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()

mob/tmp/nextattack=0
mob/var/nextattack=0
In response to Agrey123
Don't use the colon operator, you declared the next attack var twice
mob/var/tmp/nextattack=0