Hey everyone. I have been trying to figure out how to make it so that when I cut down a tree it gives me a log. But I can't figure out how to do this. Anyone know?
Might I suggest attaching the verb to the tree itself?
I dont normally do this but this is something i wrote up a year or so ago...
Tree1 icon='WoodCutting.dmi' icon_state="small tree" name = "Small Tree" density=1 verb Cut() set src in view(1) if(!usr.Hatchet) usr << "You need a Hatchet inorder to Cut wood!" elseif(usr.Inventory==usr.MaxInventory) alert("Your Inventory is full!") elseif(src.active) usr << "This Tree is already being cut" elseif(src.down) usr << "This Tree has been Chopped down! It'll regrow eventually..." elseif(usr.WcLv<2) usr << "You need ATLEAST Level 2 Wood Cutting to chop this tree!" else usr << "You start chopping the tree" usr.Frozen=1 src.active=1 sleep(10) usr.WCxp+=1 sleep(10) usr.WCxp+=1 sleep(10) usr.WCxp+=1 sleep(10) usr.WCxp+=1 sleep(10) usr.WCxp+=1 sleep(10) usr.WCxp+=1 sleep(10) usr << "You stop chopping the tree" usr.Frozen=0 src.active=0 src.down=1 src.icon='WoodCutting.dmi' src.icon_state="small down" usr.contents += new /obj/wood usr.Inventory+=1 usr.WClvCHECK() sleep(300) src.down=0 src.icon='WoodCutting.dmi' src.icon_state="small tree" view() << "A tree has revived!" Examine() set src in view(1) usr << "What a nice little Tree!"
Not sure how accurate it is, but you can mess with it, if you'd like.
#7 Jul 25 2011, 9:30 am (Edited on Jul 25 2011, 9:37 am)
Wow! Thank you all for your help. One of the biggest things I need is a good reference...It seems I have trouble learning code just from reading. Anyhow, I went ahead and did this for now and it all works but when I cut down the tree I don't get a log. Just, emptiness.
Tree Code:
mob verb Chop_Down() for(var/obj/tree/tree in get_step(usr,usr.dir)) del tree Del() new/obj/log(loc)
..()
Log Code:
obj log icon = 'textures.dmi' icon_state = "log" canpickup = 1 New(position) position = loc
..()
EDIT: Now the log appears but the tree doesn't dissapear.
<small>Del()</small> goes in <small>obj/tree</small>, not in the chop_tree verb itself.
> mob > > verb > > chop_tree() > > /* check the tile in front. */for( var/obj/tree/tree in get_step ( usr , usr.dir ) ) del tree > > obj > > tree > > /* this is where you edit Del(). */ Del() > > new/obj/log( loc ) > > ..() > > log > > /* this is where you edit New(). */ New( position ) > > loc = position > > ..() >
Thats how I have it but I still get the same issue.
Code:
mob verb Chop_Down() for(var/obj/tree/tree in get_step(usr,usr.dir)) del tree
I don't know why you swapped their location in the code, but I will explain why the mistake happened.
You need to understand what is going on when you say
var/A = "turtles"
You are setting variable (A) to be equal to "turtles." Anything to the left of the equal sign will be modified to whatever is on the right This is proper "function notation" (I am a calculus nerd!).
When you put position = loc, you are modifying the position variable to be equal to loc (which by default is null) In Neimo's original example,
loc = position
You are modifying the location variable to be equal to the position which was input by the New() proc (as an argument)
You also neglected to add ..() (Which calls the default action of the New() procedure)