On video 25 of the tutorial right now, trying to work off that to make my own changes... but I am having a hell of a time doing so. Currently I am trying to change the way looting works. Currently it works as it does in source:
if creature is killed, do a number 0-100, and if that number is less than "hasloot" (the chance number on the monster) then you get that item the monster is carrying because it takes all from store that are under 'name' (which the name is designated in the creature as well).
obviously this does not easily support a loot table.. And I am having one hell of a time trying to find out how to convert it.
my basic understanding is this:
if creature is killed
find out what its loot table is
then randomly pull out an item by random chance %.
my problem is I don't understand enough to know how to do this.. Atm I am trying to work it like this: (note nothing has been changed at all so far... and the following is all exact thought put in place to trying to figure it out.. Yes, unfortunately, this is how my mind works all the time.)
the hasloot for an orc is 50. So i figured I will just make this a pointer to the loot table. Thus, all orcs will have reward the player with loot from table 50 (my thoughts: How can I do this? obviously I have to make a new table in the database with multiple fields... Or maybe I have to make many tables in the database for the loot table... Or perhaps I can just make one new table, and put all items in there.. But then how would it call up different loot tables? Perhaps I can set a field in the 1 table that will be called Ltable and that will have the number on it.. But what if I wanted some mobs to have some of the same items but others to be different... then that wouldn't work....
Next I think about how to even script such a thing... How can I script it in to whats already there... As it is now it can only get the item because it was specifically named in the creature.. So I have to find out how to make it pull an item out of a list of items...
$critem="SELECT * from store where name='$creatureloot'"; ---ok... so its pulling it up from database store, but its pulling it by name from creatureloot... damn!!! Looking at where its pulling it from has shown me that it will only pull out an orc tooth, because it is only pulling it by name, and thus it would have to be named in the creature database..... So how do I make it pull out different things?.. nono, think... hmmm... if I had the loot table database, uhh... (5 mins later and several re-reading of the same things) ok.. creatureloot = value 'loot' in creatures database... but what can I do with this information? I still don't know how to make it pull out random loot from specific tables... I know it involves the random number isloot, but how can I do it...)
--------
and this is about as far as I could get in an hour... still stuck... still nothing done. any ideas?
cant figure out how to make random loot table.
Re: cant figure out how to make random loot table.
Alright... So now I think I can get it to work, however the method is so primitive there wont be a game once I finish adding and coding in every single lootable item... as I see it now, its going to take several lines of code per different item.. per different loot table. @_@.
database store: all loot items will be there. Added 3 new fields. loottable, lootchance, lootnumber.
Orcs contain ltable 50 so.... orc tooth, orc toe, rusty dagger, all have loottable field at 50.
orc tooth and orc toe will be common finds, so both fields of lootchance are at 45.
rusty dagger will be the harder find, so its lootchance field is 10.
orc tooth lootnumber is 1, orc toe is lootnumber 2, rusty dagger is lootnumber 3... (and for different mobs loot it will have to be similar numbers.. Meaning the rare item will always have to be 3. Idk what I am going to do if I want them to be able to find more than 3 possible items per monster...)
and in the attack script I had to make it do
if isloot < 11 then
give the player the item from store where loottable = 50 and lootnumber = 3
else
if isloot > 44 and if isloot < 46 then
isloot2 rand 1, 2
if isloot2 = 1 then
give the player the item from store where loottable = creatures ltable (which orc is 50) and lootnumber = 1
else
give the player the item from store where loottable = creatures ltable and lootnumber = 2
in other words, im supremely screwed.
database store: all loot items will be there. Added 3 new fields. loottable, lootchance, lootnumber.
Orcs contain ltable 50 so.... orc tooth, orc toe, rusty dagger, all have loottable field at 50.
orc tooth and orc toe will be common finds, so both fields of lootchance are at 45.
rusty dagger will be the harder find, so its lootchance field is 10.
orc tooth lootnumber is 1, orc toe is lootnumber 2, rusty dagger is lootnumber 3... (and for different mobs loot it will have to be similar numbers.. Meaning the rare item will always have to be 3. Idk what I am going to do if I want them to be able to find more than 3 possible items per monster...)
and in the attack script I had to make it do
if isloot < 11 then
give the player the item from store where loottable = 50 and lootnumber = 3
else
if isloot > 44 and if isloot < 46 then
isloot2 rand 1, 2
if isloot2 = 1 then
give the player the item from store where loottable = creatures ltable (which orc is 50) and lootnumber = 1
else
give the player the item from store where loottable = creatures ltable and lootnumber = 2
in other words, im supremely screwed.
Re: cant figure out how to make random loot table.
Ok providing i understand you.
you first need to get the table number from the enemy table and store it in a variable.
$tableNumber = $enemy['lootTable'];
then do your if else statements that determine your find
if isloot < 11 then
$lootNumber = 3;
else if isloot > 44 and if isloot < 46 then
$isloot2 rand (1, 2);
if ($isloot2 = 1)
$lootNumber = 1
else
$lootNumber= 2
then run the query to get your item
$query = "SELECT * FROM lootTable WHERE lootTable=$tableNumber AND lootNumber = $lootNumber LIMIT 1";
you first need to get the table number from the enemy table and store it in a variable.
$tableNumber = $enemy['lootTable'];
then do your if else statements that determine your find
if isloot < 11 then
$lootNumber = 3;
else if isloot > 44 and if isloot < 46 then
$isloot2 rand (1, 2);
if ($isloot2 = 1)
$lootNumber = 1
else
$lootNumber= 2
then run the query to get your item
$query = "SELECT * FROM lootTable WHERE lootTable=$tableNumber AND lootNumber = $lootNumber LIMIT 1";
New Site Coming Soon! Stay tuned 
Re: cant figure out how to make random loot table.
well, the problem I am having is...
what if I have other enemies that have more items than 3? I would have to modify that script to include more than just 3 items. But that wouldn't work because if you fight an enemy with less items, then you may end up getting an error because if you kill enemy orc, but it tries to give u loot number 5, it doesn't exist.
So I guess what I am asking is, how would you guys make a random loot table, where some things are easier to get, while some are rare.
what if I have other enemies that have more items than 3? I would have to modify that script to include more than just 3 items. But that wouldn't work because if you fight an enemy with less items, then you may end up getting an error because if you kill enemy orc, but it tries to give u loot number 5, it doesn't exist.
So I guess what I am asking is, how would you guys make a random loot table, where some things are easier to get, while some are rare.
Re: cant figure out how to make random loot table.
You could use ranges.
You roll a dice between 1 and a 100
The higher the number, the more rare a drop is.
If you have 10 items, where 7 items are consider "common" and you roll the dice which lands < 80, randomly pick an item there.
If have 1 uncommon and 1 rare, you can check if the dice was > 80 and < 95 give the uncommon, if >95 give the rare one.
In your table you can specify what the ranges should be, like the first 7 all have 11% to be dropped.
So: roll a dice: 45
You roll a dice between 1 and a 100
The higher the number, the more rare a drop is.
If you have 10 items, where 7 items are consider "common" and you roll the dice which lands < 80, randomly pick an item there.
If have 1 uncommon and 1 rare, you can check if the dice was > 80 and < 95 give the uncommon, if >95 give the rare one.
In your table you can specify what the ranges should be, like the first 7 all have 11% to be dropped.
So: roll a dice: 45
Code: Select all
if dice > 95 ?
give rare
if dice > 80 < 95 ?
give uncommon
if dice <= 80
query the common items
total = count all elements available
loot = random(1, total)
give loot , array[loot]
Re: cant figure out how to make random loot table.
I would personally take this approach.
Add a textfield to the enemies table.
name it loot.
this field will contain a list of item id numbers seperated by commas.
so enemy one's loot field looks like so.
1,2,1,2,3,1,2,3,1,1,2,1,2,1,3,1
Enemy two's loot field looks like so.
1,3,1,1,2,3,1,2,1,2,3,4,2,4,1,2
Item 1 = rock
Item 2 = Copper
Item 3 = Dagger
Item 4 = Helmet
As you can see, item 1 and 2 appears many times inside both of the loot fields, signifying they are common items. item 3 appears less times that the previous 2 items making it uncommon. Item 4 only appears in enemy twos list meaning it can only be found from that enemy and is an uncommon item.
when it comes to handing out items at the end of a battle. you retrieve that string and explode it.
$lootList = explode(',', $enemy['lootList']);
Thus making an array of items to be found form that enemy. you then get the amount of items in that array and minus 1 from it.
$lootTotal = count($lootList) - 1;
this now gives us our range. (0 to $lootTotal)
Get a random number using that range to select an item by the array index.
$itemNumber = rand(0, $lootTotal);
and gve that item to the player
$itemToGive = $lootList[$itemNumber];
and now you have the item ID to give to the player.
The advantage with this method is that it needs no additional tables. The more the item id number appears, the more common an item is. The less times an ID appears compared to the others, the less common it is and the less chance you have of finding the item.
Add a textfield to the enemies table.
name it loot.
this field will contain a list of item id numbers seperated by commas.
so enemy one's loot field looks like so.
1,2,1,2,3,1,2,3,1,1,2,1,2,1,3,1
Enemy two's loot field looks like so.
1,3,1,1,2,3,1,2,1,2,3,4,2,4,1,2
Item 1 = rock
Item 2 = Copper
Item 3 = Dagger
Item 4 = Helmet
As you can see, item 1 and 2 appears many times inside both of the loot fields, signifying they are common items. item 3 appears less times that the previous 2 items making it uncommon. Item 4 only appears in enemy twos list meaning it can only be found from that enemy and is an uncommon item.
when it comes to handing out items at the end of a battle. you retrieve that string and explode it.
$lootList = explode(',', $enemy['lootList']);
Thus making an array of items to be found form that enemy. you then get the amount of items in that array and minus 1 from it.
$lootTotal = count($lootList) - 1;
this now gives us our range. (0 to $lootTotal)
Get a random number using that range to select an item by the array index.
$itemNumber = rand(0, $lootTotal);
and gve that item to the player
$itemToGive = $lootList[$itemNumber];
and now you have the item ID to give to the player.
The advantage with this method is that it needs no additional tables. The more the item id number appears, the more common an item is. The less times an ID appears compared to the others, the less common it is and the less chance you have of finding the item.
New Site Coming Soon! Stay tuned 
Re: cant figure out how to make random loot table.
Seems to work properly indeed. My only problem with that is probably the overhead of having to store the same ID over and over again. The BEST way to approach it however, is non-existent, every situation begs for a different solution. If I were you sefer, i`d stick with Tourniquet, it`s easily implemented and requires little configuration for you, i think.
Tour, do you know some good algorithms too? You have a good practical approach to situations, I like that
Tour, do you know some good algorithms too? You have a good practical approach to situations, I like that
Re: cant figure out how to make random loot table.
I cant say i do 
It is something i would like to learn properly, but i have never been able to lol. I could produce one, but whether it would be an effective or suitable one (and thats if it really is a proper algorithm lol) i wouldnt know lol.
logical and practical thinking I can do no problem lol.
do you know any? lol
It is something i would like to learn properly, but i have never been able to lol. I could produce one, but whether it would be an effective or suitable one (and thats if it really is a proper algorithm lol) i wouldnt know lol.
logical and practical thinking I can do no problem lol.
do you know any? lol
New Site Coming Soon! Stay tuned 
Re: cant figure out how to make random loot table.
Plenty, but that`s all common knowledge, like how to use FIFO, FCFS, LIFO that sort of stuff. But it`s darn hard to find specific algo/logarithms for games. I tried looking at Wiki, but no luck there, yeah some use FCFS ( easiest ) up to a point reward system, which takes in consideration time, effort and level. But, no examples! Not even code snippets..
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: cant figure out how to make random loot table.
Isn't FIFO the same thing as FCFS? 
But anyway, I would suggest to go with Xaleph's method of making a range roll. This is how I have handled it in the past. Except I would maybe even bulk it up beyond 1 - 100 if you want to have super-rare items. Maybe 1 - 1000 or even 1 - 1000000. Even if you don't think you will ever have an item that has a 0.00001% chance of dropping, it takes a very small adjustment in your figures and provides you ample wiggle-room to do whatever you can imagine with your loot tables: a mob that drops 2 items, a mob that drops 200 items, an item with a 100% chance to drop, an item with a 0.0001% chance to drop, and everything inbetween.
But anyway, I would suggest to go with Xaleph's method of making a range roll. This is how I have handled it in the past. Except I would maybe even bulk it up beyond 1 - 100 if you want to have super-rare items. Maybe 1 - 1000 or even 1 - 1000000. Even if you don't think you will ever have an item that has a 0.00001% chance of dropping, it takes a very small adjustment in your figures and provides you ample wiggle-room to do whatever you can imagine with your loot tables: a mob that drops 2 items, a mob that drops 200 items, an item with a 100% chance to drop, an item with a 0.0001% chance to drop, and everything inbetween.
The indelible lord of tl;dr