Advertisement
Daemonion

callback on fire weapon

Mar 19th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.38 KB | None | 0 0
  1. -- when the player fires any weapon, it spawns a bottle of vodka at their feet
  2. -- I want this to ultimately play a stereo sound file (in the actor's head, see method below)
  3. -- As another layer, I would like the script to also read an info portion which determines what kind of environment the player is in (tunnel, house, outside, etc), THEN see what kind of weapon the actor is using, THEN pick the right audio file to use
  4.  
  5. local activeItem = nil --last recorded active item
  6. local oldCondition = 0 --condition of activeItem
  7. local report_l = xr_sound.get_safe_sound_object ("daemonion\\misc\\rain_test_l")
  8. local report_r = xr_sound.get_safe_sound_object ("daemonion\\misc\\report_r")
  9.  
  10. function update()
  11.     if (db.actor:active_item() ~= nil) then --if any item is active
  12.         local newItem = db.actor:active_item()
  13.         local newCondition = newItem:condition()
  14.        
  15.         if activeItem == nil then --if this is the first time running
  16.             activeItem = newItem
  17.         end
  18.            
  19.         if (newItem:id() ~= activeItem:id()) then --if actor switches items, record the new information
  20.             activeItem = newItem
  21.             oldCondition = newCondition
  22.         end
  23.  
  24.         if (oldCondition > newCondition) then --if condition of the active item decreases
  25.             oldCondition = newCondition
  26.             alife():create("vodka", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id())
  27.         end
  28.     end
  29. end
  30.  
  31.  
  32. -- example of script which reads an info_portion (interior_whitenoise_playing, when true, means the actor is indoors) and looks for a new line in the current weapon's .ltx
  33. -- Weapon Interior Audio Update by Daemonion
  34.  
  35. function weapon_interior_update()
  36.     level_tasks.proceed(self.object)
  37.     local sec = obj:section()
  38.     local ini = system_ini()
  39.    
  40.     if has_alife_info("interior_whitenoise_playing") then
  41.         if (ini:section_exist(sec.."_actor_indoors")) then
  42.             alife():release( alife():object(obj:id()),true )
  43.             alife():create(sec.."_actor_indoors",db.actor:position(),0,0,0)
  44.         end
  45.     end
  46.    
  47.     if not has_alife_info("interior_whitenoise_playing") then
  48.         if (isWeapon(obj) and string.find(obj:section(),"_actor_indoors")) then
  49.             local sec = string.gsub(obj:section(),"_actor_indoors","")
  50.             alife():release( alife():object(obj:id()),true )
  51.             alife():create(sec,db.actor:position(),db.actor:level_vertex_id(),db.actor:game_vertex_id())
  52.         end
  53.     end
  54. end
  55.  
  56.  
  57. -- example of script which plays stereo audio on the actor
  58. -- Rain on Clothes by Daemonion
  59. -- Thanks to EvanTheUseless, Decane and NatVac
  60.  
  61. function rain_on_clothes()
  62.     local actor = db.actor
  63.     local rain_fps_l = xr_sound.get_safe_sound_object ("daemonion\\misc\\rain_test_l")
  64.     local rain_fps_r = xr_sound.get_safe_sound_object ("daemonion\\misc\\rain_test_r")
  65.     -- c_print (level.rain_factor())
  66.    
  67.     if not has_alife_info("interior_whitenoise_playing") and  level.rain_factor() > 0.05 then
  68.         -- c_print("it is raining; player is outside restrictor")
  69.         if rain_fps_l:playing() == false and rain_fps_r:playing() == false then
  70.             -- c_print("playing sounds")
  71.             rain_fps_l:play_at_pos (actor, vector():set(-5, 0, 1), 0, sound_object.s2d)
  72.             rain_fps_r:play_at_pos (actor, vector():set(5, 0, 1), 0, sound_object.s2d)
  73.         end
  74.     elseif level.rain_factor == 0 then
  75.         -- c_print("not raining; stopping")
  76.         rain_fps_l:stop()
  77.         rain_fps_r:stop()
  78.        
  79.     elseif has_alife_info("interior_whitenoise_playing") then
  80.         -- c_print("player indoors; audio stopped")
  81.         rain_fps_l:stop()
  82.         rain_fps_r:stop()      
  83.     end
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement