ID:164807
 
I'm using this dblclick() code for chopping trees:

obj/Tree/DblClick()
set src in oview(1)
var/Items/Axe = locate(/Items/Axe) in usr.contents
if(Axe)
if(usr.AFK==0)
if(usr.AxeEquipped==1)
if(usr.canchop==1)
usr.canchop=0
usr.lockmove=1
usr << "<b>You begin to chop the tree."
sleep(25)
if (prob(80))
usr << "<b>You found something!"
sleep(5)
usr << "<b>You chopped a log!"
usr.canchop=1
usr.lockmove=0
usr.contents+=new/Items/log
else
usr<<"<b>You fail to chop anything."
usr.lockmove=0
usr.canchop=1
else
usr<<"<b>You need to equip your Axe!"
else
usr<<"<b>You can't chop while AFK!"
else
usr<<"<b>You need an axe to chop wood."


It works fine, but you can chop trees that aren't any where near you. I'd like to know how to make it so it would only chop when you double clicked on a tree that you were touching.
Try that instead and of course indent under it. Also, try posting code problems under code problems in the future. :D
obj/Tree/DblClick()
if(src in view(1)) // <---------
var/Items/Axe = locate(/Items/Axe) in usr.contents
if(Axe)
if(usr.AFK==0)
if(usr.AxeEquipped==1)
if(usr.canchop==1)
usr.canchop=0
usr.lockmove=1
usr << "<b>You begin to chop the tree."
sleep(25)
if (prob(80))
usr << "<b>You found something!"
sleep(5)
usr << "<b>You chopped a log!"
usr.canchop=1
usr.lockmove=0
usr.contents+=new/Items/log
else
usr<<"<b>You fail to chop anything."
usr.lockmove=0
usr.canchop=1
else
usr<<"<b>You need to equip your Axe!"
else
usr<<"<b>You can't chop while AFK!"
else
usr<<"<b>You need an axe to chop wood."