ID:818913
 
(See the best response by Keeth.)
Code:
world
map_format = ISOMETRIC_MAP

mob
icon = 'Player.dmi'
icon_state = "player"
density = 1
var
hp = 10
maxhp = 10

Login()
loc = locate(58, 67, 1)
usr.verbs+=new/mob/verb/shoot()
mob
enemies
zombie
icon = 'Enemies.dmi'
icon_state = "zombie"
density = 1
hp = 5
maxhp = 5
mob
proc
DeathCheck()
if(src.hp<=0)
del src

mob
verb
shoot()
var/obj/Bullet/B=new(src.loc)
B.icon='Bullet.dmi'
walk(B,usr.dir)
obj
Bullet
density = 1
var
range = 20
Move()
..()
src.range-=1
if(range<=0)
del src
Bump(B)
if(ismob(B))
for(var/mob/enemies/Z)
Z.hp-=1
Z.DeathCheck()
del src
else
del src


Problem description:
Alright so I have it so my player can shoot bullets at a zombies and kill them. My problem is though whenever a 5 bullets hits a zombie it doesn't kill that zombie that got hit by the bullet it kills a random zombie and not the one that got hit. Can someone please explain to me what I'm doing wrong in as much detail as you can so I can try and fix this?

EDIT: Also if you see anything else that is wrong that I'm doing or any tips you could add would be helpful also!
for(var/mob/enemies/Z)

This loops through all enemies in the world. You might want to leave that line away and only do:
B.hp-=1
B.DeathCheck()
del src
In response to Raimo (#1)
Raimo wrote:
> for(var/mob/enemies/Z)
>

This loops through all enemies in the world. You might want to leave that line away and only do:
> B.hp-=1
> B.DeathCheck()
> del src
>

Well B stands for the bullet? I don't want to take away hp from a bullet. If
for(var/mob/enemies/Z)
loops through all the zombies in the world then my problem must lying some where around this I'm guessing?
i think b stands for Bump. it makes it for what ever it bumps damage.
        usr.verbs+=new/mob/verb/shoot()

Useless when you add a verb its viewable
Best response
obj
Bullet
[...]
Bump(B)
if(ismob(B))
for(var/mob/enemies/Z)
Z.hp-=1
Z.DeathCheck()
del src
else
del src


B is not the bullet. B is the thing being bumped into. As the person who wrote the code, I don't understand why you don't know this. Make sure you look new functions up in the reference.

Bump() is called when atom A bumps into atom B. A.Bump() is called with B as the first argument passed to it.

For some reason, you opted to loop through all the zombies in the world when the bullet hits something, deal damage to the first one, and then delete the bullet (del src).

Instead, you should be asking "is B a mob?" If yes, deal damage to B.
I actually didn't write it entirely. I actually modified someone else s work to do what I wanted it too(Bad idea seeing how I didn't even understand what B stood for).
I looked at what you said and clicked f1 and started reading more about what does what and ended coming up with this!
obj
Bullet
density = 1
var
range = 20
Move()
..()
src.range-=1
if(range<=0)
del src
Bump(mob/m) // bumps mob
if(istype(m,/mob/enemies))// if it is part of enemies
m.hp-=1
m.DeathCheck()
del src // delete bullet
else
del src // do nothing/delete if it bumps anything else


Is this the correct way? It seems to do what I wanted it too, but that doesn't mean I did it correctly. Also am I explaining things correctly next to my code? Sorry for so many questions I just want to make sure I understand everything.
From what you've given, you do seem to be understanding, yes. I can't say much other than that.