Any elegant way to make a loot system?

Hey, recently I’ve been trying to make an adventure game with a system such that when an enemy dies, they have a certain chance of dropping several items. It’s easy enough making the probability, but I’ve had major problems in doing a system such that I don’t have to write out a lot of code for each enemy. Ideally I’d want it such that I can attribute items to a enemy, then once they die the code will look at which items were attributed to it and move the correct number from a storage room to the room the enemy died in, once rolling for rarer items of course. I tried a system using lists, but I haven’t found a way to store names of kinds in lists. Am I missing something obvious? I’m kind of stumped on this one, help is greatly appreciated.

What about something like this?

[code]A thing has a person called the loot owner. A thing has a number called the loot probability.

Hank is a person. [An enemy.]

The storage room is a room. [For loot.]

The magical toothpick is in the storage room. The loot owner of the magical toothpick is Hank. The loot probability of the magical toothpick is 45.

To do the looting with (guy - a person):
repeat with item running through things in the storage room:
if loot owner of item is guy:
if a random chance of loot probability of item in 100 succeeds:
move item to the location.[/code]
You’ll obviously need to start the “do the looting” phrase whenever an enemy is killed, but that shouldn’t be too hard.

Thanks! Just one question, if I have a lot of items won’t this slow down the program, as it’s checking through them all? Just I did think of doing it that way, but I feared it may end up being laggy

Yes, but there are some ways to speed it up a bit. You could use a one-to-various “ownership” relation instead of a property, then “repeat with the item running through things owned by the guy”.

The fastest thing would be to have a distinct room or container for each person.

Is that faster? Or does Inform just repeat through everything anyway?

Anyway, I wouldn’t worry too much about speed. A single loop through all items in a room isn’t going to hurt your game speed much, not even if there are hundreds of items.

Ah, thanks. I was slightly worried about this, but if it won’t be too bad I won’t worry. Thanks again, guys ^^

Inform is inconsistent about optimizations. I find it hard to predict whether a given loop will repeat through all objects; I wind up looking at the generated I6 code if I need to know.

You generally don’t have to care, unless your code runs many times in a turn or your game has several hundred objects.