ID:141045
 
Code:
mob
proc
Fire()
if(!src.equip||src.fired||src.reloading)return
var/obj/Guns/G=src.weapon
if(G.ACapacity<=0)
if(src.LocateAmmo()){src.reloading=1;src.Reload()}
else src<<"You need more ammo"
return
src.fired=1
var/damage = round(rand(G.Fire_Power/2,G.Fire_Power))
spawn(G.Firerate)if(src)src.fired=0
G.ACapacity--
G.suffix="[G.ACapacity]/[G.MACapacity]"
var/atom/movable/T = null
for(var/atom/movable/a in view(src))
if(!a||!a.density)continue
T = a
break
if(T)
src.dir = get_dir(src,T)
if(istype(T,/mob/AI))
s_damage(T,damage,"red")
T.Health -= damage
T.Death()


Problem description:
I got two errors.
Auto aim.dm:25:error:T.Health:undefined var
Auto aim.dm:26:error:T.Death:undefined proc
Also, if this get fixed, ill let you know if the shooting not works.
Is the Health variable defined for movable atoms?
It also helps to point out the lines the errors are pointing to. Just double click them in DM and it will select that line.
In response to Kaiochao
The errors are on the last two lines.
Also the variable for health is defined in the mob section.
In response to Gamemakingdude
The variable T there is defined as a movable atom, and you can only use the variables and procs contained within that type and its ancestors.

(Also, setting a variable's initial value to null is just pointless to type out. "var/stuff" is the same as "var/stuff=null".)
In response to Kaiochao
Can you explain and if possible show me the code how to do this?

Also defining health in the T area doesn't work either.
In response to Gamemakingdude
i figured out what went wrong, but now i have more errors...

procs.dm:7:error:src.client:undefined var
procs.dm:11:error:src.Spectate:undefined proc

atom
proc
DeathCheck() //check to see if an attack is deadly
if (src.Health <= 0)
if(src.NotDead == 1) //if the defender's Health is low enough...
world << "[src] dies!" //give the death messaging
if(src.client) //Lets change the 'if(src)' to 'if(!src.client)' <--- If they arn't a player but NPC
NotDead = 0
attackable = 0
Dead = 1
src.Spectate()
NewGame()
else//otherwise, if they are a player
if(src.pregant==1)
var/mob/AI/swarm/G = new(loc) //create a new obj from the gold blueprint
G.amount = rand(10,20) //set its amount variable randomly
if(src.brute==1 && BruteForce == 0)
usr << "You have achieved the Brute force Medal."
BruteForce = 1
world.SetMedal("Brute Force",src.last_hit)
ZOMBIES = ZOMBIES - 1
del(src)


In response to Gamemakingdude
Spectate() is quite obviously a mob proc.
The client var is a mob's var.

Either way, src = atom in this, so you need to define src as a mob.
In response to Gamemakingdude
Atoms lack a client property and likely lack your spectate proc.

i think you have 2 options.
define the proc under your mob heading.

mob
proc
DeathCheck()

or stick ":" between src and client and src and spectate
this indicates that the property might not be there for all applicable atoms.

so src:client and src:Spectate()

it will still run time error if it is called on an atom that is not a mob or able to spectate.
In response to Gamemakingdude
Typecast.
var/mob/m = T

Use typecasting to enable you to use properties of a type previously defined something else. T is a movable atom, but if you put an if() saying it's a mob, then it's safe to typecast T into a mob, which is stored in m.
In response to Kaiochao
I got no errors and im about to test it.
In response to Kaiochao
How do i type cast?
In response to Gamemakingdude
Same problem you had the first time.

Basically, you need to understand the idea of inheritance in an object oriented language.

var/atom/movable didn't work for you because Health and Death were over on your mob object. The atom/movable doesn't inherit anything from mob and so the compiler using an atom/movable reference has no idea what Health or Death are.

src.client can't be found because in this case the src (which points to wherever the code is and consequently can usually be left out entirely) is atom/movable and the client variable is under mob. Atom/movable doesn't inherit anything from mob so it can't find the mob.client variable.

src.Speculate couldn't be found, but it's hard to say where it is because it's not part of DM normally.

Inheritance in DM only works one way, mob inherits from atom/movable but not the only way around, and that's a large part of why you're having so much difficulty here.

Still confused? This chapter and the next might help you understand what's going on. They don't talk about inheritance very explicitly, but they do use a good analogy of thinking of it in terms of a tree and provide some good examples where you might figure out what's going on, as well as explain the core inheritance between the different BYOND defined types.
In response to Gamemakingdude
Because nobody else said it: you should never be using usr in procs. You need to pass an argument if you want to know - for example - who killed src. Like so:

mob/verb/kill(var/mob/M)
M.die(src)

mob/proc/die(var/mob/killer)
world << "[killer] killed [src]"
del(src)
In response to Garthor
Erm, there's no usr in this code so what you're talking about?
In response to Garthor
This is good to know, except he wasn't using usr anywhere. <_<
In response to Kaiochao
Sure he was. Just once, though. Really, he seemed to be using src for both the mob being killed and the mob doing the killing, which made no damn sense but oh well.

Specifically, in that BruteForce... stuff.