ID:1125404
 

I want to make a certain item check for the owners location in the oview of the item and when they get far enough away to delete the items.
Get_Book()
set src in oview(2)
if(usr.hasbook == 0)
var/Books= list(new/obj/A_History_of_Magic/,new/obj/Fantasic_Beasts_and_Where_to_Find_Them/,new/obj/Magical_Water_Plants_of_the_Mediterranean,new/obj/Magical_Drafts_and_Potions,new/obj/Defensive_Magical_Theory)
var/obj/L = input("Please select a book you would like to read") in Books
L.owner = usr.name
usr.hasbook = 1
L.loc = locate(usr.x,usr.y,usr.z)
var/mob/M = L.owner
loop
for(M in oview(8))
if(!M)
del(L)
else
goto loop
Don't use goto. Just use a loop inside the item.

item/book
var/mob/owner
New()
..()
owner_check()
proc/owner_check()
if(owner) // If they have an owner
var/d = get_dist(src, owner)
if(d > 8) del src //Or maybe just set owner=null? Instead of deleting the book, leave it for someone else.
spawn(1) owner_check() //Now have owner_check() call itself so it loops. The spawn() allows other procs to process so this process doesn't freeze the game.
Recursive spawning of procs has a tendency to produce an infinite call stack so it is not advised. It is better to use a normal loop
proc/owner_check()
spawn(1)
while(owner)
// get distance / delete here
sleep(1)


Though a more preferred way is to check the distance only when the owner moves. For example,
player
var/tmp/list/belongings = new

proc
own(item/item)
belongings += item
item.owner = src

Move()
.=..()
for(var/item/item in belongings)
if( get_dist(src,item) > 8 )
del item // or disown it like Albro suggested

item
var/player/owner

Del()
if(owner && (src in owner.belongings))
owner.belongings -= src
..()

Note: It is best to remove the item from the belongings list when you move it into your inventory to avoid unnecessary checks.