ID:1548036
 
(See the best response by Nadrew.)
            Move(/**/)
src.length --
if(src.name=="Sword")
src.density=0
for(var/turf/a in src.loc)
if(a.density)
del(src)
for(var/mob/m in src.loc)
if(istype(m,/mob/player))
if(m.level < 20|| src.owner.level < 20)
src.owner<<"<font color=gray>PvP will be activated at lvl 20"
del(src)
return
if(!src.length) del(src)

return ..(/**/)


I want to create piercing beam. So I made src density = 0 so it cannot bump().

Detecting players in src.loc works fine. But not for turfs.It wont delet src if turf in the same loc has density.
Best response
You don't need to loop for turfs, 'src.loc' is the turf the object is on.

You can do:

if(src.loc.density) del(src)


When you're doing what you're doing you're basically asking it to loop over every turf inside of a turf, which isn't gonna work out so well.

You should probably also move the 'src.owner.level' check higher up to prevent in undue processing, since if the owner's level isn't above 20 they shouldn't need to fire it -- unless of course this is a restriction only applied to player targets, in which case you can do 'continue' instead of deleting the thing and returning, since I imagine you'd just want it to skip over things you can't attack instead of failing the moment it touches one.