ID:155341
 
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?


Thanks,
Namone
Do you have any coding attempts that I could see for this process?
You can do this my simply modifying the <small>Del()</small> of the tree creating a log at the location of the tree.

Del()

/* the log. */ new/obj/log( loc )

..()


also, modifying <small>obj/log/New()</small>

New( position )

loc = position

..()
In response to Neimo (#2)
Thanks.
In response to Namone (#3)
So now, I am stuck. I can't get the Chop_down() verb to work.


Code:
mob
verb
Chop_Down(tree/T as obj in oview(1))
del(T)
In response to Namone (#4)
You're not completely doing it correctly, but you're somewhat on the correct track.

You will need to get the tile in front of you and see if it is a tree. If so, delete it.

mob

verb

chop_tree()

/* check the tile in front. */ for( var/obj/tree/tree in get_step ( usr , usr.dir ) ) del tree
In response to Namone (#4)
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!"
else if(usr.Inventory==usr.MaxInventory)
alert("Your Inventory is full!")
else if(src.active)
usr << "This Tree is already being cut"
else if(src.down)
usr << "This Tree has been Chopped down! It'll regrow eventually..."
else if(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.
In response to Komuroto (#6)
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.
In response to Namone (#7)
You have it backwards and parts out of place.

<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

..()
In response to Neimo (#8)
Neimo wrote:
You have it backwards and parts out of place.

<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





obj
tree
icon = 'textures.dmi'
icon_state = "tree"
luminosity = 0
density = 1
opacity = 0
canpickup = 0
Del()
new/obj/log(loc)

obj
log
icon = 'textures.dmi'
icon_state = "log"
canpickup = 1
New(position)
position = loc

..()

In response to Namone (#9)
You don't have it exactly as provided, you're missing the key part.

..() /* Look for this in my code for obj/tree/Del(). */
In response to Namone (#9)
It's a rather silly mistake!

position = loc


should be

loc = position


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)
In response to Lugia319 (#11)
That did it! thanks everyone.
In response to Namone (#9)
check your tabbing
In response to Komuroto (#13)
There is nothing wrong with the tabbing, sir.