ID:155636
 
hi i would like to know what tyhe proper formula is to have a mob attack my avatar and vice versa. i need to be able to calculate damage attack and defence thank you
Be more specific, do you want an attack verb that deals damage or a formula?
In response to Neimo
well im kinda new so i guesse it would be the formula since i want the npc mob to use an attack verb that deals damage to a player avatar when in a distance and if possible also how do i set a certain delay between the time they can attack ( sort of like in world of warcraft with the cooldown)
thanks a bunch in advance
In response to Natasdrol
A verb is the code that makes it happen.

A formula is the mathematics used inside the verb to calculate damage.

In any case, If you are unable to code this on your own i suggest you read the DM Guide and also view some demos. There is a large amount of demos in the resource section (located at the top of the site under developers menu).

Usually a good place to start
In response to Midgetbuster
ok i understand the principle but what i mean is how do i make the npc use his attack verb on his own when i get to lets say an inview (3) or something every like 3 seconds. if anyone could help with the formula to make that happen it would be of much help thanks.
In response to Natasdrol
I think he wants to say he wants a proc that makes a monster attacks player if he walks near it and deals damage with 3 seconds delay.
I tried to make that code for you, but failed. I will leave it to professionals.
In response to Martys1103
mob/verb/Attack()
if(src.can_attack) // If users can attack var is 1 then they will proceed with attacking
src.can_attack=0
flick("punch",usr) // Punch in the icon_state
for(var/mob/M in get_step(src,src.dir)) // For anybody in front of the attacker
var/damage= src.str - M.def // Attackers strength - the attackees defense.
if(damage<=0) // If the damage is less than zero then it will be zero. So the attackee doesn't GAIN health.
damage=0 // Will set it to zero.
M.health-=damage // deals zero damage
src.AttackDelay() // Runs the proc to let them be able to attack again.
else
M.health-=damage // deals damage.
src.AttackDelay()
else
src << "You must wait before attacking again!" // Message given when user cannot attack

mob/proc/AttackDelay()
sleep(10) // makes the player way 1 second before attacking again. sleep(10) = 1 second; sleep(20) = 2 seconds; sleep(5) = 0.5 seconds sleep(100) = 10 seconds. Chose anytime you want. even sleep(123)
src.can_attack=1

mob/var
can_attack=0
str=10
def=5
health= 100


Tell me if it works.
In response to Xirre
If it's npc AI you want, there are plenty of demo's and libs available on the resources for this.
In response to Xirre
thanks a bunch ill try that out and btw this is the best answer iv got up to now ( structured and well explained with examples) and ya ill tell you if it work out good
In response to Xirre
im kinda new to proggraming altogether and this is my first challenge.

this is what ive got up to now.


mob
icon = 'warrior.dmi'
var/life=100
var/def=0.50 // i actually want this to be put into percentage
proc/Attack(Att)
life=life-Att*def /* life=100 - (att=50 - def=25%) life=87.5 is what i want it to give but since percentage is off it gives me weird numerical outcomes*/

if(life <0)
view() <<"[src] dies!"
del src
if(life >0)
view()<< "ennemy has [life] hp left"
verb/attack()
set src in oview()
src.Attack(50)

mob/monster/rat
icon = 'rat.dmi'
life=100
def=0.25 /*id like for the rat to use an attack verb on its own every 5 secs.

obj/sword
icon = 'sword.dmi'
verb
get()
set src in usr.loc
loc = usr
drop()
set src in usr
loc = usr.loc //add Att to mob!!!

if anyone could help me out would be great thanks
In response to Natasdrol
Try this(?. I might be a bit rusty but it will be simpler code)
mob
icon = 'warrior.dmi'
var/life=100
var/def=(usr.def/2)//This will make it half of the users defence


The rest of this code i will have to look at in more depth but scince 100% = the base defence of the mob that means 50% = half of the mobs defence. /2 = devide by 2 so the math up there say user's defence equals half of its base defence or soemthing to that effect. Of course it could just poop out and end up chaning the default defence var into half of the warriors defence meaning the rat might have the full 100% defence of a warrior.. Uber rat much