obj/Shadow
New()
..()
spawn(40)
del(src)
Shadow_Rain
icon = 'barrier.dmi'
icon_state = ""
densed = 1
var/lockedon=0
Bump(A)
world<<"I have been bumped"
if(ismob(A))
if(A==src.myOwner)
return
src.YuBumped(A,src.damage)
Move()
..()
if(!src.lockedon)
src.FindMyEnemy()
proc/FindMyEnemy()
for(var/mob/M in view(5,src))
if(M!=src.myOwner)
walk_to(src,M)
src.lockedon=1
Problem description:
The user selects Shadow Rain and it creates the obj at a random location within the user's view and makes it walk_rand().
The obj then is searching for a mob around it to walk_to. When one is found the attack walks towards it however whenever it bumps into the object nothing happens. Bump() isn't even called. I am currently having to force Bump() to be called. Can anyone help as to why this is happening?
You should also be breaking that for() loop in FindMyEnemy() when it finds one, otherwise it's going to keep looking and call walk_to() on everyone around you and only go after the last person it finds.
Don't use del() either, it has a dramatic amount of overhead that only gets worse as your game scales upwards, instead just clear any variables that are referring to the object and any variables on the object itself referencing something else and the garbage collector will handle it without the overhead of the lookups required to del() something. You can override Del() to allow the usage of del(), as long as you don't call ..()
Like I said above, you'd also need to clear any references to this object from the variables of other things, a good setup will keep track of these things. You'd also want to call walk(null,src) when it hits something otherwise it's just gonna keep on trying to follow that target until the end of time (which I believe would prevent garbage collection)