ID:178553
 
I wanna make it so it sez "There is no one to attack" when you click attack and there's nothing there. How might I go about doing this?

verb .
Attack(mob/M in oview(1))
Likwiddraino000 wrote:
verb
Attack(mob/M in oview(1))

Personally, I hate this attack system. I prefer attacking the nearest, strongest mob. Here's a sample attack verb :).
mob
var
attack = 5
defense = 5
hp = 30
npc
var/toughness //this will be used to determine what the strongest target is

New()
toughness = attack + defense + hp
..()

mob
verb
attack()
var/mob/npc/M = locate() in oview()
if(!M) return //if there are no nearby mobs, then don't do anything
var/mob/strongestmob //the strongest mob
var/highesttough = 0 //the strongest mob's toughness
for(M) //loop through every mob within one tile
if(M.toughness > highesttough)
strongestmob = M

//now we'll do the damage to the strongest mob

strongestmob.hp -= usr.attack
oview() << "[usr] attacked [strongestmob] for [usr.attack] damage!"
strongestmob.deathcheck()

You'll need to write your own deathcheck() proc. Please don't just copy and paste this into your game. Try to learn from it :p

=V

PS: This is untested code :)
In response to Vortezz
I mean, I want it to say something when you use the attack command and there's nothing around to attack.
In response to Likwiddraino000
In response to Likwiddraino000
Likwiddraino000 wrote:
I mean, I want it to say something when you use the attack command and there's nothing around to attack.

Simple. Just change:
         if(!M) return      //if there are no nearby mobs, then don't do anything

to:
         if(!M)
usr << "There's nothing to attack!"

;)

=V
In response to Vortezz
I put it in there, but it doesn't work. I tried attacking with no one around and it didn't say anything.

verb
Attack(mob/M in oview(1))

if(!M)
usr << "There's nothing to attack!"