ID:159730
 
My code works perfectly , with the exception of the whole location being deleted when I try to delete the tree.

I tried using (var/turf/tree/T in M.loc) but it still deletes the whole location.

I also thought about using a loop when the tree is created to check to see if it's out of resources to delete it, but I figured that would create lag.

Any way around this?

skills
var/NPC/soldier/owner
parent_type=/obj
Gather1
name="Gather"
icon='turfs.dmi'
icon_state="treeicon"
Click()
..()
var/NPC/soldier/P=owner
P.gathering=1
while(P.gathering)
var/turf/tree/M=locate(/turf/tree) in range(10,owner)
if(!M)
M=locate(/turf/tree) in range(10,owner)
if(!M) return
while(!(owner in orange(1,M)))
walk_to(owner,M,1,05)
sleep(05)
M.resources--
if(M.resources<=0)
del(M)
M=locate(/turf/tree) in range(10,owner)
if(!M) return
var/turf/Z=Castleproc(owner)[rand(1,4)]
sleep(10)
while(!(owner in orange(1,Z)))
walk_to(owner,Z,1,05)
sleep(05)
var/mob/player/O=owner.owner
var/turf/L=owner.loc
owner.loc=Z
sleep(10)
O.resources+=rand(10,20)
sleep(10)
owner.loc=L
The tree is a turf, which is why it is getting deleted.

This is horrible looking code, by the way. It looks so redundant and full of pointless checks. What exactly is it supposed to do?
In response to Kaiochao
It's a gather command for units in a real-time strategy game. Units are supposed to travel between a tree and the base returning resources each time.

In response to Aixelsyd
Again, the tree is a turf. That is why the whole location is getting deleted, because the location IS the tree, which is a turf.
In response to Kaiochao
Well, thanks.