Advertisement
Daemonion

daemonion_sound with perspective functions

Dec 21st, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.13 KB | None | 0 0
  1. -- Zoom in and out for Daemonion
  2. -- by Alundaio
  3. -- additions by Daemonion
  4.  
  5. ------------------------------------------------------------
  6. -- debug
  7. function printf(text,...)
  8.     if not (text) then return end
  9.     local i = 0
  10.     local p = {...}
  11.     local function sr(a)
  12.         i = i + 1
  13.         return tostring(p[i])
  14.     end
  15.     local output = string.gsub(text,"%%s",sr)
  16.     get_console():execute(output)
  17.     --get_console():execute("load ~#I#:"..output)
  18. end
  19.  
  20. -----------------------------------------------------------
  21. -- [section]  = { sound, fov }
  22. local sections_zoom_in = {
  23.     ["wpn_pm"] = {[[weapons\in]],74},
  24. }
  25.  
  26. local sections_zoom_out = {
  27.     ["wpn_pm"] = [[weapons\out]],
  28. }
  29.  
  30. ------------------------------------------------------------
  31. -- goes in function actor_binder:on_item_take
  32. function weapon_perspective_take ()
  33.     if (isWeapon(obj)) then
  34.         local sec = obj:section()
  35.         local ini = system_ini()
  36.         -- Check system ini if section with the postfix "_actor" exists
  37.         if (ini:section_exist(sec.."_actor")) then
  38.             alife():release( alife():object(obj:id()),true )
  39.             alife():create(sec.."_actor",db.actor:position(),0,0,0)
  40.         end
  41.     end
  42.  
  43. -- goes in function actor_binder:on_item_drop
  44. function weapon_perspective_drop ()
  45.     if (isWeapon(obj) and string.find(obj:section(),"_actor")) then
  46.         local sec = string.gsub(obj:section(),"_actor","")
  47.         alife():release( alife():object(obj:id()),true )
  48.         alife():create(sec,db.actor:position(),db.actor:level_vertex_id(),db.actor:game_vertex_id())
  49.     end
  50.    
  51. ------------------------------------------------------------
  52. -- goes in stalker_binder:update()
  53. function actor_on_update()
  54.     --printf("device fov = %s",device().fov)
  55.     --printf("test")
  56.     local wpn = db.actor:active_item()
  57.     if (wpn) then
  58.         if (sections_zoom_in[wpn:section()]) then
  59.             if (sections_zoom_in[wpn:section()][2] and device().fov < sections_zoom_in[wpn:section()][2]) then
  60.                 if not (actor_scope) then
  61.                     actor_scope = true
  62.                     actor_on_weapon_zoom_in(wpn)
  63.                     printf("actor update zoomed in")
  64.                 end
  65.             else
  66.                 if (actor_scope) then
  67.                     actor_scope = nil
  68.                     actor_on_weapon_zoom_out(wpn)
  69.                     printf("actor update zoomed out")
  70.                 end
  71.             end
  72.         else
  73.             if (actor_scope) then
  74.                 actor_scope = nil
  75.                 actor_on_weapon_zoom_out(wpn)
  76.                 printf("actor update catch all")
  77.             end
  78.         end
  79.     end
  80. end
  81.  
  82. -- actor_on_weapon_zoom_in(wpn)
  83. function actor_on_weapon_zoom_in(wpn)
  84.     --local snd = sound_object("weapons\in")
  85.     local snd = sections_zoom_in[wpn:section()] and sections_zoom_in[wpn:section()][1] and get_sound(sections_zoom_in[wpn:section()][1])
  86.     if (snd) then
  87.         snd:play_at_pos (db.actor, db.actor:position())
  88.         --snd:play_at_pos(db.actor,db.actor:position(),0)
  89.     end
  90. end
  91.  
  92. -- actor_on_weapon_zoom_out(wpn)
  93. function actor_on_weapon_zoom_out(wpn)
  94.     --local snd = sound_object("weapons\out")
  95.     local snd = sections_zoom_out[wpn:section()] and get_sound(sections_zoom_out[wpn:section()])
  96.     if (snd) then
  97.         snd:play_at_pos (db.actor, obj:position())
  98.         --snd:play_at_pos(db.actor,db.actor:position(),0)
  99.     end
  100. end
  101.  
  102.  
  103. function get_sound(snd)
  104.     if snd then
  105.         return sound_object(snd)
  106.     end
  107. end
  108.  
  109. ------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement