ID:147420
 
I just did alot of searches over the byond forums and i think I got what i needed.Everything runs fine I just need for you guys to check if theres any useless coding or any other problems.Here's my code.Btw Thanks in advance.
EDIT:How would i make it different chances to get different items?For example 60% to get Fruit 30% to get Mint Leaf and 10% to get Nothing?
mob
Bump(atom/movable/A)
if(isobj(A))
var/obj/O=A
spawn()
O.Bumped(src)

obj
proc
Bumped(atom/movable/A)
Ruins
Tower1
name = "Ruins"
icon ='Ruins.dmi'
icon_state = "Tower1"
density = 1
var/list/Treasure = list(/obj/Items/Food/Mint_Leaf,/obj/Items/Food/Fruit)
Bumped(atom/movable/A)
if(ismob(A))
usr << "You search the tower"
sleep(10)
if(!Treasure.len)
usr << "There is No Items in Tower"
else
var/Z=pick(Treasure)
if(Z == /obj/Items/Food/Mint_Leaf)
usr << "You find Mint Leaf"
new Z(usr)
Treasure -= Z
if(Z == /obj/Items/Food/Fruit)
usr << "You find Fruit"
new Z(usr)
Treasure -= Z
prob proc
See also:
pick proc
rand proc
rand_seed proc
roll proc
Format:
prob(P)
Returns:
1 with probability P percent; otherwise 0
Args:
P: A number.
One thing I would do is generalize your Bumped() proc a bit more. There is no reason to limit it to mobs and objs.
atom/movable/Bump(atom/Obstacle)
Obstacle.Bumped(src)
..()

atom/proc/Bumped(atom/movable/Bumper)

The rest of your procs can stay the same, but you now have allowed yourself to call Bumped for any movable atom.


To adjust the probabilities of your call to pick(), you have to set up the list within the proc itself. Something along the line of:
pick(60; /obj/Items/Food/Mint_Leaf, 30;/obj/Items/Food/Fruit, 10; "nothing")

There is more information about adjusting probabilities listed near the bottom of the pick() procs entry in the reference.