Advertisement
Guest User

mask_hud.script

a guest
Nov 16th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.06 KB | None | 0 0
  1. -- Actor Effects by Smurth
  2. -- Original code by Rulix aka Bak:
  3. -- rewritten for Coc by Nuor
  4. local DynHud,hud,current_helm,opt,helm_fx
  5. helmet_active = nil
  6. feature_is_active = nil
  7.  
  8. function activate_hud()
  9. if (feature_is_active) then
  10. return
  11. end
  12. feature_is_active = true
  13. helm_fx = {
  14. helm_respirator = "level.add_pp_effector('helm_respirator.ppe',3000,true)",
  15. helm_exo = "level.add_pp_effector('helm_exo.ppe',3000,true)",
  16. helm_protective = "level.add_pp_effector('helm_protective.ppe',3000,true)",
  17. helm_hardhat = "level.add_pp_effector('helm_hardhat.ppe',3000,true)",
  18. helm_scientific = "level.add_pp_effector('helm_scientific.ppe',3000,true)",
  19. helm_battle = "level.add_pp_effector('helm_battle.ppe',3000,true)",
  20. helm_tactic = "level.add_pp_effector('helm_battle.ppe',3000,true)",
  21. }
  22. opt = {
  23. -- minimal distance from actor to draw helmet (increase it if helmet disappear when running / jumping)
  24. cam_dist = 1.6,
  25. radiation_ppe_threshold = 0.3,
  26.  
  27. helmets = {
  28. -- texture to use when wearing the exo outfit
  29. exo_outfit = "helm_exo",
  30. merc_exo_outfit = "helm_exo",
  31. dolg_exo_outfit = "helm_exo",
  32. svoboda_exo_outfit = "helm_exo",
  33. military_exo_outfit = "helm_exo",
  34. bandit_exo_outfit = "helm_exo",
  35. monolith_exo_outfit = "helm_exo",
  36. cs_exo_outfit = "helm_exo",
  37. exo_proto_outfit = "helm_exo",
  38.  
  39. -- texture to use when wearing the scientific outfit
  40. scientific_outfit = "helm_scientific",
  41. ecolog_outfit_orange = "helm_scientific",
  42. ecolog_outfit_green = "helm_scientific",
  43. ecolog_outfit_blue = "helm_scientific",
  44. ecolog_outfit_white = "helm_scientific",
  45. scientific_heavy_outfit = "helm_scientific",
  46. monolith_scientific_outfit = "helm_scientific",
  47. dolg_scientific_outfit = "helm_scientific",
  48. merc_scientific_outfit = "helm_scientific",
  49. svoboda_scientific_outfit = "helm_scientific",
  50. cs_scientific_outfit = "helm_scientific",
  51. isg_scientific_outfit = "helm_scientific",
  52.  
  53. -- texture to use when wearing the respirator outfit
  54. monolith_radiation_outfit = "helm_respirator",
  55. merc_radiation_outfit = "helm_respirator",
  56. svoboda_radiation_outfit = "helm_respirator",
  57. dolg_radiation_outfit = "helm_respirator",
  58. radiation_outfit = "helm_respirator",
  59. monolith_nbc_outfit = "helm_respirator",
  60. cs_nbc_outfit = "helm_respirator",
  61. nbc_outfit = "helm_respirator",
  62.  
  63. helm_respirator = "helm_respirator",
  64. helm_respirator_2 = "helm_battle",
  65. helm_facemask = "helm_respirator",
  66. helm_respirator_joker = "helm_respirator",
  67. helm_hardhat = "helm_hardhat",
  68. helm_tactic_2 = "helm_protective",
  69. helm_hardhat_snag = "helm_hardhat",
  70. helm_protective = "helm_scientific",
  71. helm_tactic = "helm_respirator",
  72. helm_battle = "helm_respirator",
  73. helm_battle_lucky = "helm_respirator",
  74. helm_m40 = "helm_respirator",
  75. },
  76. helmet_no_respi = {
  77. -- helmets that doesn't provide respirator (no gasmask breath sounds)
  78. helm_scientific = true,
  79. helm_respirator = true,
  80. helm_respirator_2 = true,
  81. helm_facemask = true,
  82. helm_respirator_joker = true,
  83. helm_tactic_2 = true,
  84. helm_hardhat_snag = true,
  85. helm_protective = true,
  86. helm_tactic = true,
  87. helm_battle = true,
  88. helm_battle_lucky = true,
  89. helm_m40 = true,
  90. helm_hardhat = true,
  91. helm_exo = true,
  92. },
  93. health = {
  94. -- health level for heavy injuring sounds
  95. level1 = 0.1,
  96. -- health level for light injuring sounds
  97. level2 = 0.2,
  98. -- little hit effect (played on every hit > little_delta)
  99. little_delta = 5,
  100. little_ppe = "amk_shoot.ppe",
  101. -- middle hit effect (played in addition of little effect, anm and snd randomly chosen)
  102. middle_delta = 20,
  103. middle_anm = {"shell_shock","hit_front","hit_right","hit_back","hit_left","hit_front_left","hit_back_left","hit_front_right","hit_back_right"},
  104. middle_snd = {"pain_2","pain_3","pain_5","pain_6","pain_7","pain_8"},
  105. -- huge hit effect (played in addition of little effect, anm and snd randomly chosen)
  106. huge_delta = 50,
  107. huge_ppe = "total_recall.ppe",
  108. huge_anm = {"head_shot","fusker"},
  109. huge_snd = {"pain_4","pain_1","hit_5","hit_6"},
  110. -- hit drop weapon probability (0-1)
  111. drop_wnp_prob = 0.05,
  112. -- non droppable items
  113. no_drop_wnp = { bolt = true,
  114. wpn_knife = true,
  115. wpn_binoc = true
  116. },
  117. },
  118. speed = {
  119. -- minimal speed for actor being treated as "running"
  120. mini = 0.5,
  121. -- speed time increase per update (when running)
  122. inc = 0.4,
  123. -- speed time decrease per update (when not running)
  124. dec = 0.5,
  125. -- minimal speed time for playing breath sounds (when no gasmask)
  126. time_mini = 4,
  127. -- play breath sounds (when no gasmask) when stamina is below this level
  128. stamina = 0.3,
  129. -- actor_speed_time += 1-db.actor.health*k_health
  130. k_health = 30,
  131. -- actor_speed_time += bleeding*k_bleed
  132. k_bleed = 1.2,
  133. },
  134. }
  135.  
  136. helmet_active = true
  137. open_hud()
  138. RegisterScriptCallback("actor_on_net_destroy",net_destroy)
  139. end
  140.  
  141. function deactivate_hud()
  142. if not (feature_is_active) then
  143. return
  144. end
  145. feature_is_active = false
  146. UnregisterScriptCallback("actor_on_net_destroy",net_destroy)
  147. opt = nil
  148. helmet_active = nil
  149. close_hud()
  150. end
  151.  
  152. function open_hud()
  153. hud = get_hud()
  154. DynHud = DynamicHud()
  155. if DynHud then
  156. hud:AddDialogToRender(DynHud)
  157. end
  158. end
  159.  
  160. function close_hud()
  161. if DynHud then
  162. if current_helm then hud:RemoveCustomStatic(current_helm) end
  163. current_helm = nil
  164. hud:RemoveDialogToRender(DynHud)
  165. DynHud = nil
  166. hud = nil
  167. end
  168. end
  169. ------------------------------------------
  170. function net_destroy()
  171. close_hud()
  172. end
  173. ------------------------------------------
  174. function on_game_start()
  175. if (axr_main.config:r_value("mm_options","enable_mask_hud",1,false) == false) then return end
  176. local function actor_on_first_update()
  177. activate_hud()
  178. end
  179. RegisterScriptCallback("actor_on_first_update",actor_on_first_update)
  180. end
  181. --// ----------------------------------------------------------
  182. --// -------------------DynHud class---------------------------
  183. --// ----------------------------------------------------------
  184. class "DynamicHud" (CUIScriptWnd)
  185. function DynamicHud:__init() super()
  186. self.snd_tg = time_global()
  187. self.tmr = self.snd_tg
  188. self.helmet_cond = 1
  189. self.helmet_name = ""
  190. self.suitfirstrun = true
  191. self.speed = 0
  192. self.health_play = 0
  193. self.gas_play = 0
  194. self.run_play = 0
  195. self.pos = db.actor:position()
  196. self.health = db.actor.health
  197. end
  198.  
  199. function DynamicHud:__finalize() end
  200.  
  201. function DynamicHud:Update()
  202. CUIScriptWnd.Update(self)
  203. local tg = time_global()
  204. if tg > self.tmr then
  205. self.tmr = tg+180
  206. self:HitEffect()
  207. self:hud_condition()
  208. self:ActorRadiation()
  209. end
  210. end
  211.  
  212. --// OnUpdate Functions //--
  213. function DynamicHud:hud_condition()
  214. self.tg = time_global()
  215. self.helmet = db.actor:item_in_slot(12) or db.actor:item_in_slot(7)
  216. local cond = (self.helmet and self.helmet:condition()) or 0
  217. local helmet = db.actor:alive() and (self.helmet and opt.helmets[self.helmet:section()])
  218. local cam_dist = db.actor:bone_position("bip01_head"):distance_to_sqr(device().cam_pos)
  219.  
  220. if not (helmet and helmet_active) or cam_dist > opt.cam_dist then
  221. if self.helmet_name then
  222. level.remove_pp_effector(3000)
  223. hud:RemoveCustomStatic(current_helm)
  224. current_helm = nil
  225. if cam_dist <= opt.cam_dist then
  226. local snd
  227. if opt.helmet_no_respi[self.helmet_name] or self.tg < (self.snd_tg-400) then
  228. snd = sound_object("actor\\gasmask_nobreath")
  229. else
  230. snd = sound_object("actor\\gasmask_off")
  231. end
  232. snd:play(db.actor,0,sound_object.s2d)
  233. self.snd_tg = self.tg+snd:length()+120
  234. self.gas_play = 0
  235. self.helmet_cond = 1
  236. self.helmet_name = nil
  237. self.suitfirstrun = true
  238. else
  239. self.helmet_name = ""
  240. end
  241. return
  242. end
  243. if helmet_active or self.health < opt.health.level2 then self:hud_no_mask() end
  244. else
  245. if self.suitfirstrun then
  246. local snd
  247. if opt.helmet_no_respi[helmet] or self.tg < self.snd_tg then
  248. snd = sound_object("actor\\gasmask_nobreath")
  249. else
  250. snd = sound_object("actor\\gasmask_on")
  251. end
  252. snd:play(db.actor,0,sound_object.s2d)
  253. self.snd_tg = self.tg+snd:length()+120
  254. self.suitfirstrun = false
  255. return
  256. end
  257.  
  258. self:ActorSpeed()
  259. if opt.helmet_no_respi[helmet] then
  260. self:hud_no_mask()
  261. elseif self.tg>self.snd_tg then
  262. self.gas_play = self.gas_play+1
  263. if self.gas_play > 8 then self.gas_play = 1 end
  264. local snd = sound_object("actor\\gas_breath_"..tostring((self.health > 0.2) and math.ceil((1.01-db.actor.power)*3+self.speed/8) or 8).."_"..self.gas_play)
  265. self.snd_tg = self.tg+snd:length()*1.25
  266. snd:play(db.actor,0,sound_object.s2d)
  267. end
  268. --
  269. cond = math.floor(11*(1.17-cond))
  270. if helmet~=self.helmet_name or cond~=self.helmet_cond then
  271. if self.helmet_name then -- remove old
  272. hud:RemoveCustomStatic(current_helm)
  273. current_helm = nil
  274. end
  275. if self.suitfirstrun == false and cond > self.helmet_cond and helmet==self.helmet_name then --repaired
  276. local snd_obj = sound_object("material\\glass\\glass_fall03hl")
  277. snd_obj:play(db.actor,0,sound_object.s2d)
  278. elseif helmet~=self.helmet_name then -- changed
  279. level.remove_pp_effector(3000)
  280. self:UseHelm(helmet)
  281. end
  282. self.helmet_name = helmet
  283. self.helmet_cond = cond
  284. current_helm = self.helmet_name..self.helmet_cond
  285. hud:AddCustomStatic(current_helm)
  286. end
  287. --
  288. end
  289. end
  290.  
  291. function DynamicHud:UseHelm(section)
  292. if helm_fx[section] then
  293. assert(loadstring(helm_fx[section]))()
  294. end
  295. end
  296.  
  297. function DynamicHud:ActorSpeed()
  298. local pos = db.actor:position()
  299. self.speed = (pos.x - self.pos.x)^2+(pos.y - self.pos.y)^2+(pos.z - self.pos.z)^2
  300. self.pos = pos
  301.  
  302. if self.speed > opt.speed.mini then
  303. self.speed = self.speed + opt.speed.inc
  304. elseif self.speed > opt.speed.dec then
  305. self.speed = self.speed - opt.speed.dec
  306. end
  307. self.speed = math.min(32, self.speed + db.actor.bleeding * opt.speed.k_bleed)
  308. self.speed = math.min(32, self.speed + (1-self.health) * opt.speed.k_health)
  309. end
  310.  
  311. function DynamicHud:hud_no_mask()
  312. local health = self.health
  313.  
  314. if self.tg < self.snd_tg or health < 0 then return end
  315.  
  316. if health > opt.health.level2 then
  317. if self.speed > opt.speed.time_mini or db.actor.power < opt.speed.stamina or self.run_play == 1 then
  318. self.run_play = self.run_play+1
  319. if self.run_play > 8 then self.run_play = 1 end
  320. local snd = sound_object("actor\\run_"..math.ceil(3*self.speed/44).."_"..self.run_play)
  321. snd:play(db.actor,0,sound_object.s2d)
  322. self.snd_tg = self.tg+snd:length()*1.15
  323. else
  324. self.run_play = 2
  325. end
  326. return
  327. end
  328.  
  329. if health <= opt.health.level1 then
  330. health = 1
  331. if math.random()<0.1 then
  332. self.health_play = 0
  333. else
  334. self.health_play = self.health_play+1
  335. if self.health_play > 4 then self.health_play = 1 end
  336. end
  337. else
  338. health = 2
  339. self.health_play = self.health_play+1
  340. if self.health_play > 4 then self.health_play = 1 end
  341. end
  342. local snd = sound_object("actor\\health_"..health.."_"..self.health_play)
  343. snd:play(db.actor,0,sound_object.s2d)
  344. self.snd_tg = self.tg+snd:length()*1.15
  345. end
  346.  
  347. function DynamicHud:HitEffect()
  348. local health = db.actor.health
  349. local delta_health = (self.health-health)*100
  350. self.health = health
  351. if delta_health > opt.health.little_delta then
  352. level.add_pp_effector(opt.health.little_ppe, 2011, false)
  353. level.set_pp_effector_factor(2011, delta_health)
  354.  
  355. if delta_health > opt.health.middle_delta then
  356. local cameffs,sounds
  357. if delta_health > opt.health.huge_delta then
  358. level.add_pp_effector(opt.health.huge_ppe, 2012, false)
  359. level.set_pp_effector_factor(2012, delta_health)
  360. cameffs = opt.health.huge_anm
  361. sounds = opt.health.huge_snd
  362. else
  363. cameffs = opt.health.middle_anm
  364. sounds = opt.health.middle_snd
  365. end
  366. if not wpn_effects.shott then --optional for recoil effects
  367. level.add_cam_effector("camera_effects\\"..cameffs[math.random(#cameffs)]..".anm",999,false,"")
  368. end --optional for recoil effects
  369. local snd_obj = sound_object("actor\\"..sounds[math.random(#sounds)])
  370. snd_obj:play(db.actor,0,sound_object.s2d)
  371.  
  372. if math.random(100) < (delta_health*opt.health.drop_wnp_prob) then
  373. local active_item = db.actor:active_item()
  374. if active_item and not opt.health.no_drop_wnp[active_item:section()] then
  375. db.actor:drop_item(active_item)
  376. end
  377. end
  378. end
  379. end
  380. end
  381.  
  382. function DynamicHud:ActorRadiation()
  383. local radiation = db.actor.radiation
  384. if radiation > 0 then
  385. if radiation > opt.radiation_ppe_threshold then
  386. level.add_pp_effector("radiation.ppe", 2020, true)
  387. else
  388. level.remove_pp_effector(2020)
  389. end
  390. level.set_pp_effector_factor(2020, radiation)
  391. if math.random()<radiation then
  392. radiation = radiation>0.5 and math.random()<radiation/1.3 and "click3" or math.random(8)
  393. local snd = sound_object("detectors\\geiger_"..radiation)
  394. snd:play(db.actor,0,sound_object.s2d)
  395. end
  396. end
  397. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement