Page 1 of 1

Here's one for ya

Posted: Mon Nov 05, 2012 4:10 am
by msyblade
Fhizban is working on a HUGE item upgrade mod, scripting them all and planning a randomizing function with different tiers of each item type so you dont get Dismantlers on floor 1. My question is this, I saw a script (Crismans, I believe) that allows sockets to take all gem types. I Copied it and pasted it in my objects expecting it to name all iterations of gems and save me typing. But what I found was this.

cloneObject{
name = "eye_socket_left",
baseObject = "eye_socket_left",
onInsertItem = function (self, item)
local a, b = string.find (item.name, "_gem")
return a ~= nil and b == string.len(item.name)
end,
}

cloneObject{
name = "eye_socket_right",
baseObject = "eye_socket_right",
onInsertItem = function (self, item)
local a, b = string.find (item.name, "_gem")
return a ~= nil and b == string.len(item.name)
end,
}

cloneObject{
name = "mouth_socket",
baseObject = "mouth_socket",
onInsertItem = function (self, item)
local a, b = string.find (item.name, "_gem")
return a ~= nil and b == string.len(item.name)
end,
}
Anyone else see that? all items with the string suffix _gem are accepted. Like an * in DOS days.Any way to use this feature to make fhizbans randomizers much more manageable?He's talking hundreds of items.

Re: Here's one for ya

Posted: Mon Nov 05, 2012 7:04 am
by HaunterV
he can use "_tier_1..."
or "_magic_tier_1...."

Re: Here's one for ya

Posted: Mon Nov 05, 2012 8:53 am
by Fhizban
but the function the wildcards are used are always string.find functions

the true question is, if there is a way to include this functionality when selecting an item from a list. so instead of writing lists for each item type and selcting one randomly, i would like to use a wildcard string. how is this possible?

Code: Select all

-- -------------------------------------------------- LOOT TABLES
fiz_itemList = {
	fiz_list_vc_wpn_sword     = { "fiz_itm_wpn_swd_smallsword", "fiz_itm_wpn_swd_machete", "fiz_itm_wpn_swd_falchion", "fiz_itm_wpn_swd_middlesword", "fiz_itm_wpn_swd_rapier", "fiz_itm_wpn_swd_longsword", "fiz_itm_wpn_swd_sabre", "fiz_itm_wpn_swd_cutlass", "fiz_itm_wpn_swd_bastardsword", "fiz_itm_wpn_swd_broadsword", "fiz_itm_wpn_swd_katana", "fiz_itm_wpn_swd_greatsword" },
	fiz_list_vc_wpn_mace      = { "fiz_itm_wpn_mac_crudemaul", "fiz_itm_wpn_mac_cudgel", "fiz_itm_wpn_mac_club", "fiz_itm_wpn_mac_spikedclub", "fiz_itm_wpn_mac_knoffer", "fiz_itm_wpn_mac_mace", "fiz_itm_wpn_mac_hammer", "fiz_itm_wpn_mac_morningstar", "fiz_itm_wpn_mac_warhammer", "fiz_itm_wpn_mac_flail", "fiz_itm_wpn_mac_greatmaul", "fiz_itm_wpn_mac_powerhammer" },
}

-- -------------------------------------------------- ADD LOOT TO LOCATION
function fiz_addRandomLoot(level, x, y, iCategories, aMin, aMax)
	aMin = aMin or 1
	aMax = aMax or 1
	local amount = math.random(aMin, aMax)
	for i=1, amount do
		local category = iCategories[math.random(#iCategories)]
		local iName = fiz_getRandomItemName(category)
		local facing = (party.facing + 2) %4
		spawn(iName, level, x, y, facing)
	end
end

-- -------------------------------------------------- ADD LOOT TO MONSTER/ALCOVE
function fiz_addRandomMonsterLoot(monster, iCategories, aMin, aMax)
	aMin = aMin or 1
	aMax = aMax or 1
	local amount = math.random(aMin, aMax)
	for i=1, amount do
		local category = iCategories[math.random(#iCategories)]
		local iName = fiz_getRandomItemName(category)
		monster:AddItem(spawn(iName))
	end
end

-- -------------------------------------------------- 
function fiz_getRandomItemName(category)
	return fiz_itemList[category][math.random(#fiz_itemList[category])]
end

To get a random very common (vc) weapon (wpn) of type sword (sword):

fiz_itemList['fiz_list_vc_wpn_sword'][math.random(#fiz_itemList['fiz_list_vc_wpn_sword'])]

Wich means i have to create a list for every loot table there is. Easily sums up to 50-100 different lists. Using a wildcard could make it much easier, faster and shorter. Any idea how this could be implemented?

Re: Here's one for ya

Posted: Mon Nov 05, 2012 9:04 am
by msyblade
Think You're going to rearrange the name have the END be wpn_vc_swd and wpn_vc_mace etc..

Then you would try this:

fiz_itemList = {
fiz_list_vc_wpn = { "_wpn_vc_swd", _wpn_vc_mace", etc..
}

would include all swds and maces you have tagged very common. At least I HOPE it's that simple.

Re: Here's one for ya

Posted: Mon Nov 05, 2012 12:52 pm
by ZeroAlligator
I have two ideas, neither of which have I tested. :lol:

The first idea:

Have a master weapon table, a master clothing table, and so on, and to have the items standardly named within it like you suggested, here is an example (fiz_itm, item type, commanality, magical/non-magical, sub-type, item name):

Code: Select all

MasterWeaponList = {     
   "fiz_itm_wpn_vc_mag_swd_smallsword",
   "fiz_itm_wpn_rr_nm_swd_machete",
   "fiz_itm_wpn_un_nm_swd_falchion",
   "fiz_itm_wpn_vc_mag_swd_middlesword",
   "fiz_itm_wpn_vc_nm_mac_crudemaul",
   "fiz_itm_wpn_un_nm_mac_cudgel", 
   "fiz_itm_wpn_un_nm_mac_hammer",
   "fiz_itm_wpn_rr_nm_dag_sharpdagger", 
                              }
For the sake of slimplicity, you would make separate lists for clothes, and a separate one for food or loot, or whatever main categories of items you are wanting.

Next, let's say that you want to call a common weapon, and you don't really care what type it is, but you want it to be magical and common, and of a particular level. You could call a random item from that list, test it for compliance with your specifications with the string function ("_nm_" for example), and if it passed, use it. This would take a lot of time though, especially if your list is large. A better way of doing this might be to create a list containing ONLY the items that pass your requirements, then call an item randomly from that newly created list. You would do this with a for function that parses through the list and pulls anything matching your string requirements.

Alternatively....

And I think this is a much better idea...

Would be to create a master list, everything in the list like in the first example, but only have one of each item, here is an example:

Code: Select all

MasterItemList = {     
   "fiz_itm_wpn_swd_smallsword",
   "fiz_itm_wpn_mac_machete",
   "fiz_itm_wpn_dag_sharpdagger",
   "fiz_itm_food_bread",
   "fiz_itm_food_apple",
   "fiz_itm_clo_sillyhat", 
   "fiz_itm_clo_flyingpants",
   "fiz_itm_clo_shoesofdiscouragement", 
                              }
Now you would pull all swords, all weapons, or all food into a new list like we did before, and then pull an item randomly from that list. The difference being that there are no common, uncommon, magical, and so forth items in this list. All of that is contained in the item definitions. After you have an item randomly from the list, you would pull the preset stats from within that item's definition.

For each item you would have different properties (or levels so to speak) such as common(10, 3, nm, "rusty"), where the first number would represent, attack, the second defense, the third it's magical properties, and the fourth, a name prefix (or whatever... hopefully you get the idea.) Basically, once you have an item, you would pull the stats of a common, uncommon, or rare item from some preset options within the item's definition. You could even have multiple versions of commonality for an item, the options are endless. Within the item's definition you would simply be calling for a particular level of commonality, and returning the statistics to be cloned.

Once you have the item you want to create, you would call the clone function and create the item using the stats that you've pulled. Creating items this way would allow a high degree of randomality and customizability. Hopefully this makes sense and is helpful. Let me know if you want additional explanation on the coding aspect, I'm new to Lua and am stumbling my way through it with some trial and error.

-Mark

Re: Here's one for ya

Posted: Mon Nov 05, 2012 4:03 pm
by Fhizban
@ZeroAlligator thanks! creating random items on-the-fly is a bit too much for me right now (is there a clone function? did not know!)

but the idea with a master table and then selecting parts of it, copy them into a new table to use for loot drops is good!