ID:262257
 
Code:
mob/Pet
verb
Pet_Attack(mob/Monster in oview(5))
set category = "Pet"
for(var/mob/M in oview(5))
if(M.owner == "[usr]")
if(M.pet == 1)
walk_to(M, Monster, 1, 1)
if(!M.attack)
M.attack = 1
var/damage = M.str - Monster.def
var/num = damage
M.hp -= damage
s_damage(M, num, "#FF0000")
usr << "[M] attacks [Monster]!"
if(Monster.hp <= 0)
Monster.Death()
sleep(10)
M.attack = 0


Problem description: My pet attacks once, but I'm tryin to get it to attack until the monster is dead.

That should be a proc I think, and then use while(), you will have to edit that so it would work for a proc (ex: the usr in it.)
In response to N1ghtW1ng
Ummm..Ok..Sorry, but I dont really understand what you mean..
There are a couple things about this that could be done differently and would make it easier to do other things.

Rather than using a bitflag to tell if someone has a pet (if(M.pet) or if(!M.pet) set M.pet equal to the pet itself. By doing this you avoid having to find the pet via looping through mobs within view. You would also want to do the same thing with the pet's owner, setting it to the mob itself rather than the mob's name. All that you would do is define the pet variable as /mob/pet rather than just /pet.

Doing that you cut out a bit of code and make it easier to keep track of the person's pet.

mob/Pet
verb
Pet_Attack(mob/Monster in oview(5))
set category = "Pet"
while(Monster)
walk_to(usr.pet, Monster, 1, 1)
if(!usr.attack&&get_dist(usr.pet,Monster)<=1)
usr.pet.attack = 1
var/damage = usr.pet.str - Monster.def
var/num = damage
Monster.hp -= damage
s_damage(Monster, num, "#FF0000")
usr << "[usr.pet] attacks [Monster]!"
if(Monster.hp <= 0)
Monster.Death()
sleep(10)
usr.pet.attack = 0


This code assumes you take the advice given above, you could also give pets a current_action variable to keep track of what they are doing. When they are attacking for example, have it while(Monster&&src.pet.current_action=="Attack") Then you could make a "Stop!" command that would set current_action to null and would stop it from attacking.
In response to Nick231
Well, I put that code in and got these errors:

pets.dm:14:error:M.pet:undefined var
pets.dm:15:error:M.attack:undefined var
pets.dm:16:error:M.attack:undefined var
pets.dm:21:error:M:undefined var
pets.dm:25:error:M.attack:undefined var
pets.dm:17:error:usr.pet.str:undefined var

In response to Mecha Destroyer JD
I so badly hate people who think we can read minds and make full systems for them.
In response to AZA
My fault..I tried...
In response to Mecha Destroyer JD
Mecha Destroyer JD wrote:
My fault..I tried...

It was partially my fault, I left M in and never switched it out with usr.pet. But still, you should not expect to be able to just copy and paste code and have it work.
In response to Nick231
Ok