
EDIT: DOH! Why did I suggest the profit setup function? Now I see that I have a function for random gifts that is much closer to what you wanted in your first post...
- Code: Select all
-- setup table of gift items based on what actor has in the various slots
-- for weapons this will randomly select one of applicable ammo types
-- for other item types one of the non_ammo_gift_items elemets will be used
local function setup_gift_items(actor, npc)
for _, slot in ipairs(equipment_slots) do
local item = actor:item_in_slot(slot)
if item ~= nil then
local ammo_list = utils.cfg_get_string(system_ini(), item:section(), "ammo_class", nil, false, "", nil)
if ammo_list ~= nil then
local ammo_table = {}
for ammo in string.gfind(ammo_list, "([^,%s]+)") do
table.insert(ammo_table, ammo)
end
gift_item_by_slot[slot] = ammo_table[math.random(1, #ammo_table)]
else
gift_item_by_slot[slot] = non_ammo_gift_items[math.random(1, #non_ammo_gift_items)]
end
end
end
end