ID:632497
 
(See the best response by Lugia319.)
Code:
        Bump(mob/M)
if(!M.client)
killit(M)


Problem description:
ive tried this

        Bump(mob/M)
if(!M.client)
if(istype(src,mob/Units/)) return
killit(M)


but it gets an error, but i got it to where i can make my troops. my troops do what i want them to do. only problem is, when they bump each other, they attack each other, i want to get rid of that...how?
A) You can't assume that 'M' is a mob. You have to test its type first

B) You need a slash at the start of that type-path: /mob/Units/

C) Assuming this Bump() is defined under the Unit type, you want to be checking that M's type is /mob/Units and not src's.

D) The killit() call shouldn't be indented under that second if(), as the return statement is the only thing that's meant to be inside it.
but the M's im fighting are mobs. and my units are npcs, so wouldnt src be the thing to use instead of usr,/mob/
The if statement will always return either true or false for any mob doing it. Assuming the path this code is under is /mob/Unit, it will always return true. So you will always return... and the proc will end. The return should be the last thing to be done because it's what you'd use to tell the result of a finished proc.

DC is making a guess that you want to check the target's type (which should change from time to time) instead of the src's type (which never changes). I agree, you want to check M's type not the src's.

But even all of that aside, you're not making any distinction between units. Even if they're allies, your code is suggesting an attempt to make them destroy each other. So you may want to add a "owner" variable so you can make sure they don't destroy each other.
ok heres what im doing. im making a bunch of these units. and im walking around...they follow me. but when they bump each other, they want to attack each other, or anything else they bump into. i just want them to attack what i say attack. any other time bumb attack is negated
        Bump(mob/Enemy/M)
if(!M.client)
killit(M)
proc/killit(mob/Enemy/M)
if(prob(83))
var/damage = rand(1,10)
view() << "[src] attacked [M] for [damage] damage!"
M.hp -= damage
if(M.hp <= 0)
Wood+=1
del(M)
else
view() <<"[src] attacked [M] but missed!"
Well you're still not accounting for that in your code. You're saying if they bump a not-client, attack it. Which is why I will now suggest a target variable instead of an owner variable.
well this is off a AI demo. im just trying to include "if its a owners unit type - do not attack" but everytime i try with it it fails. and cant compile...ive put it after if(!M.client) but error. put it after if(prob(83)) and it errored. so idk where i should put it...letalone after the unit kills the enemy, my wood doesnt get added
Best response
The wood is probably being added but to the NPC's wood variable, not yours. I am quite confident you can figure this out. With a target variable, you can have the NPCs only attack that target. With an owner variable, you can modify where the wood goes. I am sure you can figure this out.

mob
Unit
var
Wood = 0
Owner // I would make these 2 variables references
Target