obj/tree/verb
cut()
set src in view(1)
var/obj/tree/T = locate() in get_step(usr,usr.dir)
if(!Fell)
if(T)
var/turf/G = get_step(src,usr.dir)
if (!G.density)
Move(G)
T.icon = 'fallen.dmi'
new/obj/stump(get_step(usr,usr.dir))
Fell = 1
else
return
There are two problems. The easier one to solve is that this code doesn't detect if there is an object with density in the next space. It detects if the turf has density but not if any objects in the turf has density(i.e. if there is a tree in the next space)
The other problem will be harder to solve (I think). You see I want the player to cut the tree that he is facing (no diagonals). However if there are two trees right next to eachother(look at the "picture" below") and a player is facing one of the trees and the other tree is diagonal to the player, the code will behave funny. It will usually treat the tree that is diagonal to the player as the src. So in the game the tree diagonal to the player will move but the tree next to the player will change into the fallen icon. I tried to avoid this by putting "if(src == T)" into the code but instead of solving the problem it will just do nothing! Please help!
(Picture)
t
pt (p is player location and the two t's are the tree locations)
Loop through the atom/movables on the turf and see if they are dense, and if they are, FAIL.
As for the latter problem, you have a few options.
One is to change the verb to your mob instead of having it on your tree. Then you can do /obj/tree in get_step(usr,usr.dir)
Another is to check in the verb to see if the player is in a diagonal.