Anyway, the point :
I managed to create my own very basic script by adding to the give_treasure function in treasure_manager.script, see below.
- Code: Select all
function CTreasure:give_treasure(k)
local v = self.treasure_info[k]
local sim = alife()
local obj = sim:story_object(v.target)
if obj ~= nil then
local text = "%c[255,238,155,23]"..game.translate_string(v.name).."\\n"..
"%c[default]"..game.translate_string(v.description)
local item_ids = {}
local pos, lvid, gvid, pid, new_obj
local need_workaround = level.object_by_id(obj.id) ~= nil
if need_workaround then
pos = db.actor:position()
lvid = db.actor:level_vertex_id()
gvid = db.actor:game_vertex_id()
pid = db.actor:id()
else
pos = obj.position
lvid = obj.m_level_vertex_id
gvid = obj.m_game_vertex_id
pid = obj.id
end
-- ******** start new ********
local path = "misc\\random_treasure.ltx"
local ltx = ini_file(path)
local level_name = level.name()
local random_item = math.random(1,5)
local items = ltx:r_string(level_name, random_item)
new_obj = sim:create(items, pos, lvid, gvid, pid)
table.insert(item_ids, new_obj.id)
-- ******** end new ********
if need_workaround then
self.loss_workaround_queue[v.target] = item_ids
bind_stalker.nv_need_update = true
end
news_manager.send_treasure(v.name)
level.map_add_object_spot_ser(obj.id, "treasure", text)
--' Ïîìåòèì òàéíèê êàê âûäàííûé
self.treasure_info[k].active = true
self.treasure_info[k].done = true
else
printf("TREASURE %s, target doesnt exist", k)
end
end
It references a section in an ltx like this :
[l01_escape]
1 = wpn_pb
2 = wpn_fort
3 = wpn_toz34
4 = wpn_bm16
5 = wpn_mp5
The question I have is, what if I want the treasure to have multiple items?
I know I can create a loop with a random iteration, but I really want to be able to specifiy multiple items in the ltx, like so :
[l01_escape]
1 = wpn_pb, ammo_9x18_fmj
2 = wpn_fort, ammo_9x18_fmj
3 = wpn_toz34, buckshot
4 = wpn_bm16, buckshot
5 = wpn_mp5, ammo_9x19_fmj
That way the items in a stash would go together rather than be a random selection of say a gun and a medkit.
Anyone know how I make the code I have added to the treasure_manager script read multiple values from a single string then spawn all of those items?
Please excuse my code if it is ugly and poorly optimised, I have never done anything with scripts before other than tweaking other people's work!!
PS: I have built this into the ZRP treasure manager, so it may look slightly different to your version.