ID:1825004
 
(See the best response by Turboskill.)
Code:
mob
var/fire_on = 0

proc/on_fire()
if(src.fire_on != 1)
src.fire_on = 1
spawn(4)
src.fire_on = 0
view(7) << "pif-paf"
var/obj/bullet/B = new()
B.dir = usr.dir
B.loc = usr.loc

while(B)
var/nextLocation = step_to(B, src.loc)
var/turf/T = nextLocation

if(B)
step_to(B, src.loc)
sleep(0.0001)

for(var/mob/M as mob in T)
usr << "You shot [M]."
sleep(2)
M.HP -=30
del B

if(T.density != 0)
usr << "You shot [T]."
sleep(2)
del B

for(var/obj/O in T)
if((O.density == 1) && (B.loc == O.loc))
usr << "You shot [O]."
sleep(2)
del B


Problem description:
In a collision with bullets Turf gives an error. Bullet did not respond to mobs and objects.
Your problem is likely that you're using the step_to proc which returns a 0 or 1 to signal failure or success of the step into a new location. What you'll like want to use instead is the get_step_to proc. You call it in pretty much the same way, except it should return to you the proper value to store in your turf/T.

I would comment that i'm not sure Turfs work like that, as in allowing you to define one simply based on location parameters, but i'll go check that now.
Best response
Yeah so after thinking about it (and some quick testing :P), i don't think what you are trying to make happen/check for will work unless you do something like:

var/nextLocation = get_step_to(B, loc)
var/turf/T
if(nextLocation!= 0)
T = locate(nextLocation)

if(T != null && B)
step_to(B, src.loc)
sleep(0.0001)

for(var/mob/M in T) // pretty sure 'as mob' would be redundant here
usr << "You shot [M]."
sleep(2)
M.HP -=30
del B

if(T.density != 0)
usr << "You shot [T]."
sleep(2)
del B

for(var/obj/O in T)
if((O.density == 1) && (B.loc == O.loc))
usr << "You shot [O]."
sleep(2)
del B



By the way, i have a suggestion about how to make the code inside your while loop a little more 'elegant' -if not more efficient.
The idea would be to make use of the fact that everything you'll want the bullet to hit will be dense (right?). This means you can use one loop to check all atoms in the turfs loc, applying an action if dense, and as needed using the istype() proc -in the case of having actions which are specific to certain types of atom i.e. damage factoring for any mobs that get hit.