ID:1537647
 
(See the best response by Kaiochao.)
Hey guys! I'm new at Byond, started two days ago, but I am already quite in depth here. I need help. First, my Bow'n'Arrow will only fire at another Player mob. Why?
mob/Player/verb/Shoot()
set src in oview(5)
missile(/obj/Arrow, usr, /obj/Lion)
world << "You fired an Arrow!"
del src


Also I have a tree that the player can cut down and harvest Lumber. I don't know how to write a verb that gives the player an item. How?

Tree
icon = 'big tree.dmi'
verb
ChopDown()
set src in oview(1)
world << "You chopped down a tree."
src.Move (usr)
icon = 'lumber.dmi'
CraftBow()
set src in usr
alert("Do you want to craft Lumber into a Bow'n'Arrow?")
del src

(What now? What goes in here to put /obj/bow in players invent?)
ok thanks!
Best response
Shoot() is defined under /mob/Player, so it's only attached to /mob/Player objects. Due to the "set src in oview(5)", any player can shoot any other player within 5 tiles. If you want to shoot other things, you can either define it higher up on the inheritance tree (somewhat bad), or you can define it for each thing you want to be able to shoot. For the latter, you'd probably want to make a proc attached to players to keep shooting in one place:
mob/player
// one place to handle shooting any atom
proc/Shoot(atom/Target)
missile(/obj/Arrow, src, Target)
src << "You fired an Arrow!"
sleep get_dist(src, Target)
del Target

// add ability to shoot players
verb/shoot()
set src in oview(5)
usr.Shoot(src)

obj/archery_target
// add ability to shoot archery targets
verb/shoot()
set src in oview(5)
usr.Shoot(src)


To create a new object, use the "new" statement.
new Type(args for type.New)

// e.g.
new /obj/bow (usr)

// because of the built-in atom.New(loc), the argument for
// new Type() specifies where the new Type is created.
Ok thanks man! That helps heaps!
the new statement didn't work. What did I do wrong? I copied pasted that under the verb statement.

// add ability to shoot players
verb/shoot()
set src in oview(5)
usr.Shoot(src)
Undefined proc : usr.shoot(src)
Huh?
CraftBow()
set src in usr
alert("Do you want to craft Lumber into a Bow'n'Arrow?")
del src
new /obj/BownArrow (usr.loc)

It's not working, even with (usr) by itself
Even for short bits, those dm tags are super helpful

usr is typed as /mob. shoot() is a /mob/player verb. Either redefine shoot() as a /mob proc or typecase usr as a /mob/player.

When you del() an object, you also kill all its running procs like CraftBow()
In response to MisterPerson
MisterPerson wrote:
When you del() an object, you also kill all its running procs* like CraftBow()


* Unless you set src = null before you delete them.
this is awesome but could you give me an example code with the Shoot() please? Thanks guys :)