ID:141585
 
Code:
obj
Eevee_gun//again....don't ask why.....xD
icon = 'evee.dmi'
icon_state = "rest"
density = 1
var/Spatt = 0
var/Gowner = "nobody"
Bump(A)
if(ismob(A))
var/mob/M = A
var/damage = round(src.Spatt*5)
if(Gowner == A)
del(src)
if(damage <= 0)
world << "Missed"
if(damage >= 1)
M.hp -= damage
view(M) << "[M] was hit by Eevee gun for [damage] damage!!"
world << "Eevee gun done [damage] damage"
M.Death(M)
del(src)
if(istype(A,/turf/))
del(src)
if(istype(A,/obj/))
del(src)


Problem description:(This is a object of a ranged attack) Everything works...if it bumps in a turf or object it gets deleted but if it bumps a turf with a Enter() proc then it gets deleted but i also get a runtime error. I know it's because it tries to sent it to another location because of Enter() but i don't know how to fix it.

runtime error: Cannot modify null.loc.
proc name: Enter (/turf/grassb/Enter)
usr: 0
src: the grassb (10,1,2) (/turf/grassb)
call stack:
the grassb (10,1,2) (/turf/grassb): Enter(Eevee gun (/obj/Eevee_gun))
Eevee gun (/obj/Eevee_gun): Move(the grassb (10,1,2) (/turf/grassb), 2)
What's your turf/grassb Enter() look like? I suspect you're using Enter() wrong, and/or using usr in Enter().

Also, there is an isturf() and isobj() proc, so you don't need to use istype() - slightly cleaner.
In response to Jp
He actually should get rid of both those checks entirely, seeing as they're entirely extraneous and only lead to repeating code. In fact he should of course change the code around so there is only a single del src statement in the end, seeing as it always happens in any case, rather than have it indented on isolated if()s.

Also, you're right, he's most definitely using Enter() wrong, as he appears to try to relocate something there (unfortunately also by modifying loc instead of calling Move()), which should only be done in Entered().
Lastly, although the design is his call, he shouldn't put such specific code at a specific node, since he's going to end up duplicating it for every single projectile...
In response to Kaioken
turf
grassb
icon = 'turf.dmi'
icon_state = "grassb"
density = 1
Enter()
usr.Move(locate(5,20,1))


If i try to use src.Move() then it just says that "src.Move:undefined proc"
In response to Destrojer
That would make sense, seeing as src is a turf, which can't move.
As Jp already implied, you should never use usr in most procs, especially movement procs. It is not an all-purpose solution for being whatever you want it to be; and using it in procs can bring errors, or worse, unintended results. You should look use an appropriate var instead, this may be src or another var (like a proc argument or an object var). Here you'd need to use Enter()'s argument, but you should really be using Entered() instead.
In response to Kaioken
Ugh....how do I use Entered() proc? >.<
In response to Destrojer
same way just add 'ed' on the end of Enter() which would make it Entered() >_>
In response to Yash 69
turf
grassa
icon = 'turf.dmi'
icon_state = "grassa"
density = 1
Entered()
src.Move(locate(10,2,2))


i get the same error is what i meant......."src.Move():undefined proc" >.>
In response to Destrojer
Entered(mob/M)
M.loc=locate(10,2,2)
..()
In response to Yash 69
Yeah,great....now my projectile just runs trough to the other map......xDDD
In response to Destrojer
if(isobj(M)) return FALSE
In response to Yash 69
Ok,it works now,thx.