ID:1033238
 
Keywords: drop, obj, random
(See the best response by A.T.H.K.)
Okay so im trying to set it so if a player uses a verb on a tree, theres a chance it will drop an obj, thanks for the help

Code:
        tree
verb
shake()
switch(alert("Do you want to shake the tree?",,"Yes","No"))
if("No")
return
if("Yes")
//chance to drop orange?




Best response
Look up rand() if you were to have two drop you could throw in pick().

And have a look at this example here -

http://www.byond.com/forum/?post=576071#comment1662220
In response to A.T.H.K
No mention of prob()?

Also, rand() and pick().
In response to NNAAAAHH
Ahh yea seems we have a few ways to do it :)

don't forget roll().
In response to A.T.H.K
I was woundering what that proc was called, lol. Link to reference:
http://www.byond.com/docs/ref/info.html#/proc/roll

Could've sworn there was another proc simular to roll(), but I could just be thinking of Java.
this is what i've got so far

obj
var
dice = "2d6"
item
tree
verb
shake()
switch(alert("Do you want to shake the tree?",,"Yes","No"))
if("No")
return
if("Yes")
var/h = roll(dice)
if(h>8) //drop orange on floor
In response to Forcorrie1996
I would go for the prob() proc, it is perfect here

obj
item
tree
verb
shake()
switch(alert("Do you want to shake the tree?",,"Yes","No"))
if("No")
return
if("Yes")
if(prob(20)) //20 % chance
//drop orange on floor
okay will do, do you know how to make an obj, orange in this case, appear on the floor?
under the if(prob(20))

 new/obj/Orange(src.loc) // src being the tree in this case.
Just as a little aside here, Forcorrie1996, I'd recommend checking out the resource repository and reading the tutorials and articles there. Especially the Blue Book/Guide. The questions you've been asking have been about rather basic functions of the language, so it could benefit you quite nicely to read the manual. :)
Thanks andrew will do :)

and two problems,
one, no errors, but no orange is dropping, (prob is set to 100)
two, if i right click the tree, the verb doesnt show, I have to type it in manually
Assuming you changed the snippet for the Orange I gave you, it would be creating it on the tree (or under) you should move it closer to the player or away from the tree.
its not showing up on the same tile as the tree


EDIT. how do i set it so its 1 tile away from the tree?
In response to Forcorrie1996
new/obj/item(location)
//OR
var/obj/item/o=new(location)


The second allows you to make changes/re-use/move the obj by accessing the variable that relates to it(in this case, o).

Location in these examples is any atom available you wish to move the obj to, the obj will be moved into that atom's contents. The contents of areas and turfs are displayed ontop of them, such as a mob in contained inside of the turf it is standing in. You cannot input co-ords into new() without over-writing the new() proc for what you're making. locate(x,y,z) will output the turf at those co-ords.
yeah, the only problem with using (x,y,z) is that i would have to change it for every tree i want to drop the obj- but if theres no other way round it i will just have to haha
src.y-1 src.x-1 should do it.

Although I'm unsure never tried it how about you tell me ;)
no errors, but no orange is dropping
In response to Forcorrie1996
Can you show your code for creating the orange?

Here's a few proper examples.
obj/tree
verb/shake()
set src in oview(1)
if(prob(100))
// The above goes for all of these examples

// This drops the orange at the tree's location.
new /obj/orange (loc)

// This drops the orange at a random location next to the tree.
new /obj/orange (locate(x + pick(-1, 1), y + pick(-1, 1), z))

// This drops the orange under the shaker.
new /obj/orange (usr.loc)
it worked, i think the problem was i forgot to use

set src in oview(1)


for the shake command, and i also used your random location code kaichao, thanks for the help :)

also i tried doing it myself but couldnt manage it,is there a way to set it so if the user has already shaken the tree, it doesnt let it shake it again, i only managed to get it so if i say yes it doesnt let me :(
You need to add a variable to the user or for the tree.

I honesty think you that the tree should just refresh or re-create it's fruit after a certain amount of time, the user shouldn't be stopped from shaking it all together..
Page: 1 2