A humble request of assistance with a script.

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

Re: A humble request of assistance with a script.

Postby NatVac on 16 Apr 2009 22:18

Heh, that's not a generic message. As I suspected a couple of posts back, your mask_sounds.script is not valid, and this debug output confirms that.

Now we're making real progress. How about posting all of that script file in a code block? I can "eyeball" it, and check it out in my test setup.
NatVac
Resident
 
Posts: 152
Joined: 16 Sep 2008 00:13
Location: Texas

Re: A humble request of assistance with a script.

Postby Darius6 on 16 Apr 2009 22:34

Ok, here is the current setup of the mask_sounds.script:

Code: Select all
--Gas mask breathing sound script

local suit_sounds={
--hud_gaz
svoboda_gaz_outfit_m1 = true,
dolg_gaz_outfit_m1 = true,
neytral_gaz_outfit_m1 = true,
neytral_novice_gaz_outfit_m1 = true,
svoboda_heavy_gaz_outfit_m1 = true,
bandit_gaz_outfit_m1 = true,
--hud_exo
neytral_exo_gaz_outfit_m1= true,
svoboda_yellow_exo_outfit_m1= true,
exo_outfit = true,
--hud_merc
killer_gaz_outfit_m1 = true,
--hud_sci
dolg_scientific_outfit = true,
ecolog_outfit = true,
protection_outfit = true,
scientific_outfit = true,
--hud_military
military_outfit = true,
militaryspec_outfit = true,
}

local snd_left = nil
local snd_right = nil

local pos_left = vector():set(0, 0, 0)
local pos_right = vector():set(0, 0, 0)

function start_stop_sound(suit_type)
dbglog("start_stop_sound() - got here -- suit type is " .. tostring(suit_type))

  if suit_type and suit_sounds[suit_type] then
    snd_left = xr_sound.get_safe_sound_object([[darius\mask_breath]])
    snd_right = xr_sound.get_safe_sound_object([[darius\mask_breath]])
    snd_left:play_at_pos(db.actor, pos_left, 0, sound_object.s2d + sound_object.looped)
    snd_right:play_at_pos(db.actor, pos_right, 0, sound_object.s2d + sound_object.looped)
  end

if snd_left ~= nil then
    snd_left:stop()
  end

  if snd_right ~= nil then
    snd_right:stop()
  end

dbglog("mask_sounds.script is valid")



And this is the current call from amk_mod.script:

Code: Select all
if mask_sounds then
    dbglog("mask_sounds script is valid")
    else
    dbglog("mask_sounds script is BROKEN")
    end
  if need_change and mask_sounds then
    if enabled then
      local hud_outfit = db.actor:get_current_outfit()
      local hud_outfit_id = nil
      if hud_outfit then
        hud_outfit_id = hud_outfit:section()
    end
      mask_sounds.start_stop_sound(hud_outfit_id)
    else
      mask_sounds.start_stop_sound(nil)
    end
  end


Might be something totally obvious. I've took a break from working on this so we'd get SmP 2.3 released, but now I'm trying to get back on it full throttle. Would like to get this possibly done for the next patch for SmP. :mozilla_smile:
Suomi Finland Perkele!
User avatar
Darius6
Senior Resident
 
Posts: 18
Joined: 13 Sep 2008 19:37
Location: Finland

Re: A humble request of assistance with a script.

Postby NatVac on 17 Apr 2009 01:56

First off: The mask_sounds.script file is missing an "end" statement. And the last element of the array should not have a comma, because that can cause trouble with the logic, perhaps by adding a nil element.

I took the liberty of switching the code around a bit, because you want to turn off the old sounds before you switch on the new. If the new suit is nil (suit removed) or doesn't match (not a gasmask suit), then the old sound will simply be switched off if it is on.

The way it was, you were stomping on the old left/right sound variables with the new sounds. Then you were turning the new sounds off. But this would leave the original sounds still playing, with no way to turn them off while playing.

Normally the vectors are used for stereo sound position, but the gas mask sound is not a stereo sound. So you only need one sound, not two, especially when both are 1) the same sound and 2) played at the same position, centered on the actor. So I removed one set of lines.

Try this for mask_sounds.script:
Code: Select all
--Gas mask breathing sound script

local suit_sounds={
  --hud_gaz
  svoboda_gaz_outfit_m1 = true,
  dolg_gaz_outfit_m1 = true,
  neytral_gaz_outfit_m1 = true,
  neytral_novice_gaz_outfit_m1 = true,
  svoboda_heavy_gaz_outfit_m1 = true,
  bandit_gaz_outfit_m1 = true,
  --hud_exo
  neytral_exo_gaz_outfit_m1= true,
  svoboda_yellow_exo_outfit_m1= true,
  exo_outfit = true,
  --hud_merc
  killer_gaz_outfit_m1 = true,
  --hud_sci
  dolg_scientific_outfit = true,
  ecolog_outfit = true,
  protection_outfit = true,
  scientific_outfit = true,
  --hud_military
  military_outfit = true,
  -- the last entry should NOT have a comma
  militaryspec_outfit = true
}

local suit_snd = nil

local pos_sound = vector():set(0, 0, 0)

function start_stop_sound(suit_type)
  dbglog("start_stop_sound() - got here -- suit type is " .. tostring(suit_type))

  if suit_snd ~= nil then
    suit_snd:stop()
    suit_snd = nil --prevent subsequent attempt to turn off sound already off
  end

  if suit_type and suit_sounds[suit_type] then
    suit_snd = xr_sound.get_safe_sound_object([[darius\mask_breath]])
    suit_snd:play_at_pos(db.actor, pos_sound, 0, sound_object.s2d + sound_object.looped)
  end
end

dbglog("mask_sounds.script is valid")

When you get this working properly, you can take out (or comment out) the debug statements.
NatVac
Resident
 
Posts: 152
Joined: 16 Sep 2008 00:13
Location: Texas

Re: A humble request of assistance with a script.

Postby Darius6 on 17 Apr 2009 12:42

Thank you very much for your help and patience! Now it works pretty much as intended! Now all I need to figure out is how to make the script stop, if a player chooses to turn off the "interactive hud" from the AMK options. Might annoy players, when they turn off the actual mask textures but the sound still keeps playing.

But thats for later, right now I'm just happy to finally get this to work!

Again, thank you very much!

:-bd
Suomi Finland Perkele!
User avatar
Darius6
Senior Resident
 
Posts: 18
Joined: 13 Sep 2008 19:37
Location: Finland

Re: A humble request of assistance with a script.

Postby NatVac on 18 Apr 2009 00:18

Thanks for posting the good news, Darius6.

To turn off the sounds when the configuration option is selected: I think that the amk.load_variable("option_hud",2)==n reference (where n is a number from 0 to 2) is checking to see what button was selected in the AMK options tab (again, if I'm reading the code correctly). So you can know when the options is off (==0, maybe, and/or ==1) and call the function at that point.

Or (easier) you could call the start_stop_sound() function based on enabled in the set_hud_tex() function in amk_mod.script:
Code: Select all
  if mask_sounds then
    if enabled then
      if need_change then
        local hud_outfit = db.actor:get_current_outfit()
        local hud_outfit_id = nil
        if hud_outfit then
          hud_outfit_id = hud_outfit:section()
        end
        mask_sounds.start_stop_sound(hud_outfit_id)
      end
    else
      mask_sounds.start_stop_sound(nil)
    end
  end

This is a reworked version of the code block you posted earlier. The debug stuff is removed and the logic is rearranged a bit. The idea here is that the enabled flag is set based on the AMK option, so this should turn off any sound if the player decides to disable the feature while in the game.

Keep the "if" statements matched with "end" statements; the indentation can help. The "function set_hud_tex()" line has a corresponding "end" statement as well. If you still have problems, post the entire set_hud_tex() function and I'll "eyeball" it for you.
NatVac
Resident
 
Posts: 152
Joined: 16 Sep 2008 00:13
Location: Texas

Re: A humble request of assistance with a script.

Postby Darius6 on 18 Apr 2009 10:06

Yeah, I think the amk_load_variable stuff is what I need. I think the option_hud number is determining the select option in the menu, so that 0 is off, 1 is "Dynamic Hud" option and 2 is "Dynamic Hud + Breath effects", so the logical thing would be to attach the enabling of the breath sounds to option 2, I guess.

EDIT: Although, I belive the get_hud_tex function is tied to the option in the menu being selected at all, so I guess this would also work (although, if a player wants to keep the hud textures and only get rid of the sound,then using this would be a kind of "take it or leave it" option.)

EDIT 2: Ok, I implimented the "easy" way, here is how it works now: If I go into the AMK options menu and turn OFF the dynamic hud, the sound stops. Then when I turn it back on, the sound remains silent UNTIL I either change a map or load a save. So, basically this works, although I think properly using the menu function would be more polished and "stylish" approach. :mozilla_smile:
Suomi Finland Perkele!
User avatar
Darius6
Senior Resident
 
Posts: 18
Joined: 13 Sep 2008 19:37
Location: Finland

Re: A humble request of assistance with a script.

Postby Darius6 on 19 Apr 2009 20:20

Well, I've found an issue when doing the "easier" way of disabling the sound: Now the suit sound stops after using a scope and only comes back if you either remove the suit and equip it again OR go through a levelchanger.

I guess I should look into the "harder" way and try to attach the function to the AMK menu option...
Suomi Finland Perkele!
User avatar
Darius6
Senior Resident
 
Posts: 18
Joined: 13 Sep 2008 19:37
Location: Finland

Re: A humble request of assistance with a script.

Postby Darius6 on 21 Apr 2009 01:43

Ok, got the option to work, somewhat.
Basically the AMK options now have an effect, only that it requires an extra step of removing the suit first, then disabling the option in the menu and then re-equipping the suit and presto! No sound.

Also, same in reverse, remove suit, activate option and then equip the suit, then you'll get the sound again.

And now the sound plays with scopes also, sweet.

Well, not exactly perfect, but I'm happy with it. I at least achieved the possibility to turn it off, if it gets annoying! :mozilla_smile:

Here is what I did:

Code: Select all
  if need_change and mask_sounds then
    if enabled and amk.load_variable("option_hud",2)==2 then
      local hud_outfit = db.actor:get_current_outfit()
      local hud_outfit_id = nil
      if hud_outfit then
        hud_outfit_id = hud_outfit:section()
    end
      mask_sounds.start_stop_sound(hud_outfit_id)
    else
      mask_sounds.start_stop_sound(nil)
    end
  end


In case you find a better way to do this, please let me know! :mozilla_smile:
Suomi Finland Perkele!
User avatar
Darius6
Senior Resident
 
Posts: 18
Joined: 13 Sep 2008 19:37
Location: Finland

Re: A humble request of assistance with a script.

Postby NatVac on 25 Apr 2009 03:02

It's good you have something working, Darius6.

If you knew when the setting was changed in the Options dialog, you could call the function to turn off any sound that might be playing.

I was thinking specifically of ui_amk_options.script. In the amk_options:on_okay() function, the variable is saved via amk.save_variable("option_hud", radio_hud:GetActiveIndex() ). If the active index at this point is NOT 2, then you could call mask_sounds.start_stop_sound(nil) if mask_sounds is valid (not nil).

Better still, perform the test in the on_quit() function of that script. If the level is present and the actor is valid and alive, then turn off the menu and call the function to adjust the sound based on the option setting and the current suit. Something like this:
Code: Select all
function amk_options:on_quit()
   local console = get_console()
   self:GetHolder():start_stop_menu (self.owner, true)
   self:GetHolder():start_stop_menu (self,true)
   --self.owner:Show   (true)

   if level.present() and (db.actor ~= nil) and db.actor:alive() then
      console:execute("main_menu off")
      if mask_sounds then
         if amk.load_variable("option_hud",2)==2 then
            local hud_outfit = db.actor:get_current_outfit()
            local hud_outfit_id = nil
            if hud_outfit then
               hud_outfit_id = hud_outfit:section()
            end
            mask_sounds.start_stop_sound(hud_outfit_id)
         else
            mask_sounds.start_stop_sound(nil)
         end
      end
   end
end

That way, you would turn off any sound currently playing if they disable the option, otherwise automatically turn it on if they are already wearing a suit with a mask.

I think you can remove the test for the option variable in the set_hud_tex() function in amk_mod.script if you do this.
NatVac
Resident
 
Posts: 152
Joined: 16 Sep 2008 00:13
Location: Texas

Re: A humble request of assistance with a script.

Postby Darius6 on 28 Apr 2009 21:50

Yup, that did the trick, the menu is now working properly. Thanks again!
Suomi Finland Perkele!
User avatar
Darius6
Senior Resident
 
Posts: 18
Joined: 13 Sep 2008 19:37
Location: Finland

Previous

Return to Modding Techniques

Who is online

Users browsing this forum: No registered users and 35 guests