reward_stash bug?

User avatar
DoctorX
Trespasser
Posts: 53
Joined: 10 Mar 2016, 00:36

reward_stash bug?

Postby DoctorX » 10 Mar 2016, 00:54

Hi all,

So I'm working on creating an addon to this fantastic game, and in the process of scanning through the code I came across this bit in xr_effects.script:

Code: Select all

function reward_stash(actor,npc,p)
   if (p and p[1] ~= "true") or (math.random() <= 0.5) then
      local bonus
      local rnd = math.random(100)
      if (rnd < 10) then
         bonus = {"itm_repairkit_tier_1"}
      elseif (rnd < 5) then
         bonus = {"itm_repairkit_tier_2"}
      elseif (rnd <= 2) then
         bonus = {"itm_repairkit_tier_3"}
      end
      coc_treasure_manager.create_random_stash(nil,nil,bonus)
   end
end


There are two issues I see with this, unless I'm misunderstanding something...

Code: Select all

if (p and p[1] ~= "true") or (math.random() <= 0.5) then


So this means if I include =reward_stash(true) on completion of a task there is only a 50% chance of getting a stash location, but if I include =reward_stash(false) there is a 100% chance of getting one? Seems counterintuitive to me. Is this what was intended?

The other issue I see is with this:

Code: Select all

   if (rnd < 10) then
         bonus = {"itm_repairkit_tier_1"}
      elseif (rnd < 5) then
         bonus = {"itm_repairkit_tier_2"}
      elseif (rnd <= 2) then
         bonus = {"itm_repairkit_tier_3"}
      end


Again, I might be missing something here, but doesn't this make it impossible to spawn a tier 2 or tier 3 toolkit in a stash? For instance, if math.random returned 1, which by looks of the intent should add a tier 3 toolkit as a bonus, it would actually only bonus a tier 1 toolkit since the conditional would stop at the first if statement (since 1 is less than 10). This might explain why it is so blasted hard to find tools for your mechanic!

Not trying to be critical here with my first post, and this is something I could fix on my own, but if it is indeed a mistake I would rather not reproduce this file in my addon if it will be fixed in a future patch.

Thanks.

User avatar
Alundaio
S.T.A.L.K.E.R.
Posts: 1368
Joined: 26 May 2012, 22:26

Re: reward_stash bug?

Postby Alundaio » 10 Mar 2016, 18:31

Code: Select all

if (p and p[1] ~= "true") or (math.random() <= 0.5) then


True is for random. If you don't want to reward a stash, then you don't use the function at all. In logic it's easier to write out "=reward_stash" to 100% give something out. Later the ability to randomize the chance for the reward was added.

Yeah it should be

Code: Select all

   if (rnd < 2) then
          bonus = {"itm_repairkit_tier_3"}
      elseif (rnd < 5) then
         bonus = {"itm_repairkit_tier_2"}
      else
         bonus = {"itm_repairkit_tier_1"}
      end
"I have a dream that one day this community will rise up and live out the true meaning of its creed: "We hold these truths to be self-evident; that all mods are created equal."


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests