ID:1672858
 
(See the best response by Jittai.)
Hello,

When a monster is killed by the player in my game, I'd like the monster to have the chance of dropping an item from a predefined list (unique to that monster).

I don't seem to be having much luck, and any advice/suggestions would be greatly appreciated.

I'm trying to use the code given here as a guide... http://www.byond.com/forum/?post=173044#comment839477 but using the code...

mob/var/list/loot = new list(/obj/items/health_potion = 65)


results in two errors:

mobs.dm:5:error: list: undefined var
mobs.dm:5:error: =: expected a constant expression

What I'd like to do is have a list (loot) that all monsters have, and then add items to that list that are appropriate for each monster. Then, when that monster dies, I'd like my death() to choose a random item from that monster's loot list to drop.

Thanks for any help.

Best response
The code you linked uses type paths, so just remove that 'new' in front of list.
Thank you Jittai!

Now, all of my mobs drop health potions.

Next, I'd like to know how to give individual monster types their own lists of potential drops, but I'm not sure how to go about adding items to the loot list for this purpose.

Trying something like...

mob/monster
blob
loot.Add(/obj/items/health_potion)
rat
loot.Add(/obj/items/fur)


gives me errors:

Add: undefined proc

I think what I need to do is add something to a monster's loot list when the world is started, perhaps with new(), but I don't know.

Any advice would be appreciated.

Thanks again!
You can set an inherited variable's initial value like so:
mob
var some_variable = 123

monster
some_variable = 321


// demo code, to see it in action
proc/CheckVariable()
world << some_variable

Login()
var mob/monster/example_monster = new
CheckVariable() // my some_variable is 123 by default
example_monster.CheckVariable() // monster's some_variable is 321 by default
In your case, there's no difference whether the variable is a number or a list. Setting a variable to a list of things involves the list() proc. It's different from creating a new object instance using the "new" instruction, because list() is a proc that already contains code that creates a /list object, and then returns that /list object back to where you called list().
In response to Kaiochao
I'm sorry, I don't quite understand what you're saying.

I understand that I can change the default value of a variable by re-declaring it and assigning it a new value for a particular object, but what I'm having trouble with is actually changing the default value...

mob/var/list/loot = list(/obj/items/health_potion = 50)

mob/monster/green_blob
loot = list(/obj/items/blob_remains = 100)


doesn't result in any errors, but green_blobs continue to drop health_potions, and not blob_remains.

If it were a number, then I could certainly do it. But I don't quite understand how to do it with lists. Could you perhaps change your example that you've already kindly provided, so that instead of changing some variable that is an integer, it would demonstrate how to change some variable that contains a list of things?

In the mean time, I will certainly try and solve this on my own, but again, any information would be greatly appreciated.



In response to Takai Desu
The way you have it there should work. You must make sure you're using the right "loot" variable in the code that uses it. It's possible you're using the player's loot var instead of the monster's loot var to spawn the item.
Thanks for your help Kaiochao! I was able to get it working.