ID:146008
 
Code:
mob
DblClick(mob/M)
if(istype(M,/mob/))
switch(usr:weapon)
if(null)
if(M in oview(1))
view() << "<strong>[src] attacks [M]!"
M.health -= 5
DeathCheck()
if("Shotgun")
if(usr.cwa <= 0)
usr << "<strong>Not enough ammo!"
else
var/obj/normal/munition/Shot/N = new /obj/normal/munition/Shot
missile(N, usr, M)
usr.cwa -= 1
del(N)
world << "<strong>[usr] fires the shotgun at [M]!"
Shotgun(M)
else
..()


Problem description:
Whenever I test this in my game, I DblClick a mob, but it registers as a turf, so nothing happens. I am one hundred percent sure the target I DblClicking is a mob. I've tried is without the If(istype) part, but again, the turf is affected, not the mob.

Wouldn't usr be the same mob as M?
but yet you have the usr shoot at M?
You're missing the src.

Either that or you meant to use the client click.
The argument for atom/Click or DblClick will be the location of what was clicked, so if you clicked the mob, M would be the mob's loc. You made a mistake by thinking that M was the person who clicked the guy, when usr would be right in this situation.

I suggest you put the actual attacking in one mob proc, then call it, since it would just be more organized.

Here is something which would roughly do what you are trying to do.

client/DblClick(atom/A)
if(ismob(A)) // do any other checks to see if you want to attack other stuff
mob.attack_enemy(A)
return ..()

mob/proc
attack_enemy(mob/M)
if(!src.weapon && (M in oview(src))
// attack
else if(src.weapon == "Shotgun")
// other attacking things


~~> Dragon Lord
In response to Unknown Person
Unknown Person wrote:
The argument for atom/Click or DblClick will be the location of what was clicked, so if you clicked the mob, M would be the mob's loc.

It can also be a string, if you clicked on an icon in a statpanel. In that case the argument will be the name of the statpanel.

Lummox JR
In response to Dever
Thanks everyone!