ID:143538
 
Code:
mob
proc
ItemChance(mob/player/P,mob/monsters/M)
var/chance1 = rand(1.10)
var/chance2 = rand(20,20)
var/continues = 1
if(chance2 == 20)
if(istype(M.drop2,/obj/keys/))
if(!(M.drop2 in P.keys))
AddInfo(P,"An item drops from the monster...","It is a [M.drop2]!")
new M.drop2 (P.keys)
continues = 0
else
AddInfo(P,"An item drops from the monster...","It is a [M.drop2]!")
new M.drop2 (P)
continues = 0
else if(chance1 == 5 && continues == 1)
AddInfo(P,"An item drops from the monster...","It is a [M.drop1]!")
new M.drop1 (P)


Problem description:

The problem I'm encountering is that even though an item that is in the /obj/keys tree, it does not go into the first group of item drops. It always goes into the 2nd for the key. (Its 20,20 rand for testing to get it to work, so I dont have a small chance of testing it) It's like the item is not a /obj/keys, but drop 2 for the monster is this:
drop2 = /obj/keys/basickey
I don't understand why it doesn't work. Any help would be great.
chance1 = rand(1.20)

Note the decimal, it's suppose to be a comma.

Another simpler way (instead of making variables and checking if it ==20) would be to use
if(prob(5))
prob(X) means it has a X% chance of happening. 1/20 is a 5% chance. [1/20 = 5/100]

For your actual problem, try seeing what M.drops2 actually is:
world << M.drop2.type


Of course it would been useful to see a monster's drop2 variable here..
In response to GhostAnime
Well firstly, drop1 from the proc has no relevance here, but thanks for noticing that mistake on my part. And I did show you drop2 from the monster, if you would read the 2nd to last line, I clearly stated this:
Polantaris wrote:
but drop2 for the monster is this:
drop2 = /obj/keys/basickey

And I know what prob(5) means, but I'm used to using rand, and I prefer it over prob, because thats the way I am.
In response to Polantaris
Okay, I've decided to clarify the problem, simply for the sake that I don't get any more confusion on it.

Simple clarifications:
M.drop2 IS /obj/keys/basickey. I know this because I GET the item in my NORMAL inventory, instead of my Keys inventory, where it should be going. I get the correct item, but NOT in the correct location.

M.drop1, and all relevances to the SECOND if statement have no point in this problem, there is no problem with the SECOND part of this code, which deals with drop1.

When I kill the monster, I get dialogue saying that I GOT the correct item, EVERYTHING is fine, but the item goes to the wrong location. THAT IS THE PROBLEM, NOTHING ELSE.