Advertisement
Guest User

sr_light.script

a guest
Nov 19th, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. local light_zones = {}
  2.  
  3. local indoor_levels = {
  4. jupiter_underground = true,
  5.  
  6. -- Call of Chernobyl
  7. l03u_agr_underground = true,
  8. l04u_labx18 = true,
  9. l08u_brainlab = true,
  10. l10u_bunker = true,
  11. l12u_sarcofag = true,
  12. l12u_control_monolith = true
  13. }
  14.  
  15. ---------------------------------------------------------------------------------------------------------------------
  16. class "action_light"
  17. function action_light:__init (obj, storage)
  18. self.object = obj
  19. self.st = storage
  20. self.active = false
  21. self.id = obj:id()
  22. end
  23. function action_light:reset_scheme()
  24. light_zones[self.id] = self
  25. end
  26. function action_light:update(delta)
  27. if xr_logic.try_switch_to_another_section(self.object, self.st, db.actor) then
  28. self.active = false
  29. light_zones[self.id] = nil
  30. return
  31. end
  32. self.active = true
  33. end
  34. function action_light:check_stalker(stalker)
  35. if self.active == false then
  36. return false, false
  37. end
  38.  
  39. if self.object:inside(stalker:position()) then
  40. return self.st.light, true
  41. end
  42.  
  43. return false, false
  44. end
  45.  
  46. ---------------------------------------------------------------------------------------------------------------------
  47. function add_to_binder(npc, ini, scheme, section, storage)
  48. --' printf("DEBUG: add_to_binder: scheme='%s', section='%s'", scheme, section)
  49. local new_action = action_light (npc, storage)
  50. xr_logic.subscribe_action_for_events(npc, storage, new_action)
  51. end
  52.  
  53. function set_scheme(npc, ini, scheme, section, gulag_name)
  54. local st = xr_logic.assign_storage_and_bind(npc, ini, scheme, section)
  55. st.logic = xr_logic.cfg_get_switch_conditions(ini, section, npc)
  56. st.light = ini:r_bool_ex(section,"light_on",false)
  57. end
  58.  
  59.  
  60.  
  61. ---------------------------------------------------------------------------------------------------------------------
  62. function check_light(stalker)
  63.  
  64. local st = db.storage[stalker:id()]
  65. local tg = time_global()
  66.  
  67. if (st.srlight_timer and tg < st.srlight_timer) then
  68. return
  69. end
  70. st.srlight_timer = tg + 2000 + math.random(100)
  71.  
  72. local torch = stalker:object("device_torch") or stalker:object("device_torch_low") or stalker:object("device_torch_normal") or stalker:object("dev_torch_light_better") or stalker:object("dev_torch_light_better_1")
  73.  
  74. -- Stalker dead or sleep animstate; release torch
  75. local anm = state_mgr.get_state(stalker)
  76. if (not stalker:alive() or anm == "zat_b106_wounded_idle" or anm == "sleep" or anm == "play_guitar" or string.find(anm,"animpoint") or string.find(anm,"sneak")) then
  77. if (torch) then
  78. if (torch:attachable_item_enabled()) then
  79. torch:enable_attachable_item(false)
  80. end
  81. local sim = alife()
  82. sim:release(sim:object(torch:id()),true)
  83. end
  84. return
  85. end
  86.  
  87. -- Stalker in danger mode; release torch
  88. if (st.danger_flag) then
  89. if (torch) then
  90. if (torch:attachable_item_enabled()) then
  91. torch:enable_attachable_item(false)
  92. end
  93. local sim = alife()
  94. sim:release(sim:object(torch:id()),true)
  95. end
  96. return
  97. end
  98.  
  99. -- Non-headlamp scheme in use; release torch
  100. local scheme = st.active_scheme
  101. if (scheme == "kamp" or scheme == "camper" or scheme == "sleeper") then
  102. if (torch) then
  103. if (torch:attachable_item_enabled()) then
  104. torch:enable_attachable_item(false)
  105. end
  106. local sim = alife()
  107. sim:release(sim:object(torch:id()),true)
  108. end
  109. return
  110. end
  111.  
  112. -- Stalker has enemy and is not underground; release torch
  113. if (stalker:best_enemy() and not indoor_levels[level.name()]) then
  114. if (torch) then
  115. if (torch:attachable_item_enabled()) then
  116. torch:enable_attachable_item(false)
  117. end
  118. local sim = alife()
  119. sim:release(sim:object(torch:id()),true)
  120. end
  121. return
  122. end
  123.  
  124. local forced, light = false, false
  125.  
  126. for k,v in pairs(light_zones) do
  127. light, forced = v:check_stalker(stalker)
  128. if forced == true then
  129. break
  130. end
  131. end
  132.  
  133. if not forced then
  134. local htime = level.get_time_hours()
  135. if htime <= 4 or htime >= 20 then
  136. light = true
  137. end
  138.  
  139. if light == false then
  140. if indoor_levels[level.name()] == true then
  141. light = true
  142. end
  143. end
  144. end
  145.  
  146. if (light) then
  147. if (torch) then
  148. if not (torch:attachable_item_enabled()) then
  149. torch:enable_attachable_item(true)
  150. end
  151. else
  152. local rnd = math.random(1,4)
  153. local sim = alife()
  154. if rnd == 1 and stalker:character_community() ~= "army" then
  155. sim:create("device_torch_low", vector(), 0, 0, stalker:id())
  156. elseif rnd == 2 and stalker:character_community() ~= "army" then
  157. sim:create("device_torch_normal", vector(), 0, 0, stalker:id())
  158. elseif rnd == 3 and stalker:character_community() ~= "army" then
  159. sim:create("dev_torch_light_better", vector(), 0, 0, stalker:id())
  160. elseif rnd == 4 or stalker:character_community() == "army" then
  161. sim:create("dev_torch_light_better_1", vector(), 0, 0, stalker:id())
  162. end
  163. end
  164. else
  165. if (torch) then
  166. if (torch:attachable_item_enabled()) then
  167. torch:enable_attachable_item(false)
  168. end
  169. local sim = alife()
  170. sim:release(sim:object(torch:id()),true)
  171. end
  172. end
  173. end
  174.  
  175. function clean_up ()
  176. for k,v in pairs(light_zones) do
  177. light_zones[k] = nil
  178. end
  179. end
  180.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement