Random Stashes

Discussions on Modding of S.T.A.L.K.E.R. SoC & Clear Sky

Random Stashes

Postby EggChen on 24 Sep 2008 23:56

Ok guys, a buddy of mine sent me a random stash script he is working on which is very clever and complex, but did not work for me. This is undoubtedly my merging rather than his script.

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.
User avatar
EggChen
Moderator
 
Posts: 1016
Joined: 13 Sep 2008 00:44
Location: Birmingham, UK

Postby Kanyhalos on 26 Sep 2008 16:44

I don't know why it does not work, I hate to say something about codes in the forums, I always would like to do it and test it myself integrated to my modification, but I think I would use a different method for this one.

I would parse the ini section, for example:

local egg = math.random(1,4)

local level_name = level.name()

if egg == 1 then
level_name = level_name.."_2"
end

so it will randomly choose maybe the l01_escape_2 settings, of course you must build the proper ltx as well.

Btw, this is just a pseudo-example, I did something similar in smart_terrain_params.script, and that works fine for ST's, so it should work for this, too, I guess, but not sure 100%, I don't like to say something if I didn't test it, that's why I'm saying it's just an example of a possible solution, mostly like a direction.
DOWNLOAD Oblivion Lost 2.2 for 1.0004
http://rapidshare.de/files/40226819/OL2 ... 04.7z.html

DOWNLOAD Oblivion Lost 2.2 for 1.0005
http://rapidshare.de/files/40226610/OL2 ... 05.7z.html
User avatar
Kanyhalos
Senior Resident
 
Posts: 312
Joined: 26 Sep 2008 09:46
Location: Auburn:)

Postby EggChen on 26 Sep 2008 16:50

Yep good idea, I had seen how you did that with the smart terrains.

Thanks Kany, the code I posted above works perfectly, but only if the stash has single items. I was wondering how to make it have multiple items like in the second example, so the ltx could say :

1 = wpn_pm, ammo_9x18_fmj
2 = wpn_bm16, buckshot

Etc, etc.

I have it working in game (with single items), and I like the random stashes, I now go to look at a stash that in vanilla I didn't bother with because I knew what was in it. Using the level names works pretty well for balancing, so if you kill an NPC in Radar you get better loot than Garbage for example.

Edit: Think I have an idea using your example, in pseudo code.

Code: Select all
local path = "misc\\random_treasure.ltx"
local ltx = ini_file(path)
local level_name = level.name()
local random_item = math.random(1,40)
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)
if random item <= 5 then
     local items = ltx:r_string(level_name_2, random_item)
     new_obj = sim:create(items, pos, lvid, gvid, pid)
     table.insert(item_ids, new_obj.id)
end


So this way I have a second section for the items that I want to be multiples. So the ltx would be like this :

Code: Select all
[l01_escape]
1 = wpn_bizon
2 = wpn_bm16
3 = wpn_fort
4 = wpn_mac10
5 = wpn_pb

[l01_escape_2]
1 = ammo_9x18_pmm
2 = ammo_12x76_dart
3 = ammo_9x18_pmm
4 = ammo_9x19_pbp
5 = ammo_9x18_pmm
Last edited by EggChen on 26 Sep 2008 16:59, edited 1 time in total.
User avatar
EggChen
Moderator
 
Posts: 1016
Joined: 13 Sep 2008 00:44
Location: Birmingham, UK

Postby Kanyhalos on 26 Sep 2008 16:55

local items = ltx:r_string(level_name, random_item)

Maybe this is just getting the first string, try to get multiple strings. Well, I'm just guessing dude.
DOWNLOAD Oblivion Lost 2.2 for 1.0004
http://rapidshare.de/files/40226819/OL2 ... 04.7z.html

DOWNLOAD Oblivion Lost 2.2 for 1.0005
http://rapidshare.de/files/40226610/OL2 ... 05.7z.html
User avatar
Kanyhalos
Senior Resident
 
Posts: 312
Joined: 26 Sep 2008 09:46
Location: Auburn:)

Postby EggChen on 26 Sep 2008 17:01

Thanks Kany, I think I have a workaround, posted above in an edit to my post. using your smart_terrain example :thumbleft:

Its ugly but it will do what I want, I really am a newb at scripting!!

Thanks again.
User avatar
EggChen
Moderator
 
Posts: 1016
Joined: 13 Sep 2008 00:44
Location: Birmingham, UK

Postby Kanyhalos on 26 Sep 2008 17:07

Nope, it will crash.

if random item <= 5 then
local items = ltx:r_string(level_name.."_2", random_item)
new_obj = sim:create(items, pos, lvid, gvid, pid)
table.insert(item_ids, new_obj.id)
end
DOWNLOAD Oblivion Lost 2.2 for 1.0004
http://rapidshare.de/files/40226819/OL2 ... 04.7z.html

DOWNLOAD Oblivion Lost 2.2 for 1.0005
http://rapidshare.de/files/40226610/OL2 ... 05.7z.html
User avatar
Kanyhalos
Senior Resident
 
Posts: 312
Joined: 26 Sep 2008 09:46
Location: Auburn:)

Postby EggChen on 26 Sep 2008 17:20

Ah yes,

level_name.."_2",


Thanks Kany, now I just need to tweak my ltx file again!!
User avatar
EggChen
Moderator
 
Posts: 1016
Joined: 13 Sep 2008 00:44
Location: Birmingham, UK

Postby Kanyhalos on 26 Sep 2008 17:23

EggChen wrote:Ah yes,

level_name.."_2",


Thanks Kany, now I just need to tweak my ltx file again!!


Firstly just try it in cordon with one stash, and if it works fine, you should start to build the whole config. It would save your time if we are doing szh wrong already.:)
DOWNLOAD Oblivion Lost 2.2 for 1.0004
http://rapidshare.de/files/40226819/OL2 ... 04.7z.html

DOWNLOAD Oblivion Lost 2.2 for 1.0005
http://rapidshare.de/files/40226610/OL2 ... 05.7z.html
User avatar
Kanyhalos
Senior Resident
 
Posts: 312
Joined: 26 Sep 2008 09:46
Location: Auburn:)

Postby EggChen on 26 Sep 2008 17:25

Will do, thanks for all your help buddy :rr:
User avatar
EggChen
Moderator
 
Posts: 1016
Joined: 13 Sep 2008 00:44
Location: Birmingham, UK

Postby Kanyhalos on 26 Sep 2008 17:32

I'm glad to help people who appreciate it:)
DOWNLOAD Oblivion Lost 2.2 for 1.0004
http://rapidshare.de/files/40226819/OL2 ... 04.7z.html

DOWNLOAD Oblivion Lost 2.2 for 1.0005
http://rapidshare.de/files/40226610/OL2 ... 05.7z.html
User avatar
Kanyhalos
Senior Resident
 
Posts: 312
Joined: 26 Sep 2008 09:46
Location: Auburn:)

Postby nandersen on 01 Oct 2008 20:45

EggChen, if you want you could use multiple items in each config line, it would just require some additional parsing and looping. I can't see any problems with doing this other than slightly increased complexity.
User avatar
nandersen
Senior Resident
 
Posts: 212
Joined: 17 Sep 2008 17:24

Postby EggChen on 01 Oct 2008 20:52

Thanks nanderson, that is the bit I didn't quite understand, the parsing and looping.

Anyway, I did an ugly hack that meant some tweaks to the ltx. Basically certain numbers on each level (1-5) had three items, some had two (6-15), the rest only one, etc. The script then accessed ["level_name"_2] and ["level_name"_3] to get the second and third items.

So the script is tailored to the ltx, I know that is not a great way to do something, but it achieved what I wanted.
User avatar
EggChen
Moderator
 
Posts: 1016
Joined: 13 Sep 2008 00:44
Location: Birmingham, UK

Postby Kanyhalos on 01 Oct 2008 21:05

An other important thing is the possible lag and stuttering what very big complexities can cause, as well as online object checks, like stashes and so on.
DOWNLOAD Oblivion Lost 2.2 for 1.0004
http://rapidshare.de/files/40226819/OL2 ... 04.7z.html

DOWNLOAD Oblivion Lost 2.2 for 1.0005
http://rapidshare.de/files/40226610/OL2 ... 05.7z.html
User avatar
Kanyhalos
Senior Resident
 
Posts: 312
Joined: 26 Sep 2008 09:46
Location: Auburn:)

Postby nandersen on 01 Oct 2008 22:49

Agree. Modders should be very careful about how their code is being processed. Creating complex code that is called every frame or in a loop can be very bad.

Now, to me it looks like this should not cause any issues here - the function is called when the stash info is received, right?

Great Job EggChen.

As for the multiple items per config line: I made some code for Greedy Trader Repair that read the multiple profit entries from the trader file sections and the code could be ripped and modified for other purposes. For the stash configs it would have to be modified to read strings and not numbers and to allow single items as well as comma separated item list but that's easy to do.
User avatar
nandersen
Senior Resident
 
Posts: 212
Joined: 17 Sep 2008 17:24

Postby EggChen on 01 Oct 2008 23:25

nanderson - Thanks buddy I will have a look at that mod, see if I can improve the code.... I have posted my current code below just so you can see how ugly it is!! Never been a scripter!!

Code: Select all
      local path = "misc\\random_treasure.ltx"
      local ltx = ini_file(path)
      local level_name = level.name()
      local random_item = math.random(1,25)
      local theme_stash = math.random(1,100)
      if theme_stash >= 91 then
         level_name = "theme"
      end
      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)
      if random_item <= 5 or theme_stash >= 91 then
         local items = ltx:r_string(level_name.."_ammo", random_item)
         new_obj = sim:create(items, pos, lvid, gvid, pid)
         table.insert(item_ids, new_obj.id)
      end
      if theme_stash >= 91 then
         local items = ltx:r_string(level_name.."_ammo", random_item)
         new_obj = sim:create(items, pos, lvid, gvid, pid)
         table.insert(item_ids, new_obj.id)
      end


As you can see, I have now changed it to include a sort of theme stash list that has a 10% chance of being found. This includes say an M203 and two grenades....

Edit: Yes, this is inserted in the treasure manager function to give a stash, so that it is only called when you get treasure.
User avatar
EggChen
Moderator
 
Posts: 1016
Joined: 13 Sep 2008 00:44
Location: Birmingham, UK

Postby jamie1992 on 01 Oct 2008 23:34

Eggchen you got mail. :D
User avatar
jamie1992
Senior Resident
 
Posts: 802
Joined: 12 Sep 2008 23:04
Location: Oxford, Oxfordshire, United Kingdom

Postby Kanyhalos on 01 Oct 2008 23:44

jamie1992 wrote:Eggchen you got mail. :D


Why don't you just post here that you wanna use this in your mod, LOL
DOWNLOAD Oblivion Lost 2.2 for 1.0004
http://rapidshare.de/files/40226819/OL2 ... 04.7z.html

DOWNLOAD Oblivion Lost 2.2 for 1.0005
http://rapidshare.de/files/40226610/OL2 ... 05.7z.html
User avatar
Kanyhalos
Senior Resident
 
Posts: 312
Joined: 26 Sep 2008 09:46
Location: Auburn:)

Postby jamie1992 on 02 Oct 2008 00:17

Lol it wasnt about stashes, it was because he was on this so i posted it here thinking he would notice it easily. :D
User avatar
jamie1992
Senior Resident
 
Posts: 802
Joined: 12 Sep 2008 23:04
Location: Oxford, Oxfordshire, United Kingdom

Postby Kanyhalos on 02 Oct 2008 07:23

:D
DOWNLOAD Oblivion Lost 2.2 for 1.0004
http://rapidshare.de/files/40226819/OL2 ... 04.7z.html

DOWNLOAD Oblivion Lost 2.2 for 1.0005
http://rapidshare.de/files/40226610/OL2 ... 05.7z.html
User avatar
Kanyhalos
Senior Resident
 
Posts: 312
Joined: 26 Sep 2008 09:46
Location: Auburn:)

Next

Return to Modding Techniques

Who is online

Users browsing this forum: No registered users and 41 guests

cron