Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Actor Effects by Smurth
- -- Original code by Rulix aka Bak:
- -- rewritten for Coc by Nuor
- local DynHud,hud,current_helm,opt,helm_fx
- helmet_active = nil
- feature_is_active = nil
- function activate_hud()
- if (feature_is_active) then
- return
- end
- feature_is_active = true
- helm_fx = {
- helm_respirator = "level.add_pp_effector('helm_respirator.ppe',3000,true)",
- helm_exo = "level.add_pp_effector('helm_exo.ppe',3000,true)",
- helm_protective = "level.add_pp_effector('helm_protective.ppe',3000,true)",
- helm_hardhat = "level.add_pp_effector('helm_hardhat.ppe',3000,true)",
- helm_scientific = "level.add_pp_effector('helm_scientific.ppe',3000,true)",
- helm_battle = "level.add_pp_effector('helm_battle.ppe',3000,true)",
- helm_tactic = "level.add_pp_effector('helm_battle.ppe',3000,true)",
- }
- opt = {
- -- minimal distance from actor to draw helmet (increase it if helmet disappear when running / jumping)
- cam_dist = 1.6,
- radiation_ppe_threshold = 0.3,
- helmets = {
- -- texture to use when wearing the exo outfit
- exo_outfit = "helm_exo",
- merc_exo_outfit = "helm_exo",
- dolg_exo_outfit = "helm_exo",
- svoboda_exo_outfit = "helm_exo",
- military_exo_outfit = "helm_exo",
- bandit_exo_outfit = "helm_exo",
- monolith_exo_outfit = "helm_exo",
- cs_exo_outfit = "helm_exo",
- exo_proto_outfit = "helm_exo",
- -- texture to use when wearing the scientific outfit
- scientific_outfit = "helm_scientific",
- ecolog_outfit_orange = "helm_scientific",
- ecolog_outfit_green = "helm_scientific",
- ecolog_outfit_blue = "helm_scientific",
- ecolog_outfit_white = "helm_scientific",
- scientific_heavy_outfit = "helm_scientific",
- monolith_scientific_outfit = "helm_scientific",
- dolg_scientific_outfit = "helm_scientific",
- merc_scientific_outfit = "helm_scientific",
- svoboda_scientific_outfit = "helm_scientific",
- cs_scientific_outfit = "helm_scientific",
- isg_scientific_outfit = "helm_scientific",
- -- texture to use when wearing the respirator outfit
- monolith_radiation_outfit = "helm_respirator",
- merc_radiation_outfit = "helm_respirator",
- svoboda_radiation_outfit = "helm_respirator",
- dolg_radiation_outfit = "helm_respirator",
- radiation_outfit = "helm_respirator",
- monolith_nbc_outfit = "helm_respirator",
- cs_nbc_outfit = "helm_respirator",
- nbc_outfit = "helm_respirator",
- helm_respirator = "helm_respirator",
- helm_respirator_2 = "helm_battle",
- helm_facemask = "helm_respirator",
- helm_respirator_joker = "helm_respirator",
- helm_hardhat = "helm_hardhat",
- helm_tactic_2 = "helm_protective",
- helm_hardhat_snag = "helm_hardhat",
- helm_protective = "helm_scientific",
- helm_tactic = "helm_respirator",
- helm_battle = "helm_respirator",
- helm_battle_lucky = "helm_respirator",
- helm_m40 = "helm_respirator",
- },
- helmet_no_respi = {
- -- helmets that doesn't provide respirator (no gasmask breath sounds)
- helm_scientific = true,
- helm_respirator = true,
- helm_respirator_2 = true,
- helm_facemask = true,
- helm_respirator_joker = true,
- helm_tactic_2 = true,
- helm_hardhat_snag = true,
- helm_protective = true,
- helm_tactic = true,
- helm_battle = true,
- helm_battle_lucky = true,
- helm_m40 = true,
- helm_hardhat = true,
- helm_exo = true,
- },
- health = {
- -- health level for heavy injuring sounds
- level1 = 0.1,
- -- health level for light injuring sounds
- level2 = 0.2,
- -- little hit effect (played on every hit > little_delta)
- little_delta = 5,
- little_ppe = "amk_shoot.ppe",
- -- middle hit effect (played in addition of little effect, anm and snd randomly chosen)
- middle_delta = 20,
- middle_anm = {"shell_shock","hit_front","hit_right","hit_back","hit_left","hit_front_left","hit_back_left","hit_front_right","hit_back_right"},
- middle_snd = {"pain_2","pain_3","pain_5","pain_6","pain_7","pain_8"},
- -- huge hit effect (played in addition of little effect, anm and snd randomly chosen)
- huge_delta = 50,
- huge_ppe = "total_recall.ppe",
- huge_anm = {"head_shot","fusker"},
- huge_snd = {"pain_4","pain_1","hit_5","hit_6"},
- -- hit drop weapon probability (0-1)
- drop_wnp_prob = 0.05,
- -- non droppable items
- no_drop_wnp = { bolt = true,
- wpn_knife = true,
- wpn_binoc = true
- },
- },
- speed = {
- -- minimal speed for actor being treated as "running"
- mini = 0.5,
- -- speed time increase per update (when running)
- inc = 0.4,
- -- speed time decrease per update (when not running)
- dec = 0.5,
- -- minimal speed time for playing breath sounds (when no gasmask)
- time_mini = 4,
- -- play breath sounds (when no gasmask) when stamina is below this level
- stamina = 0.3,
- -- actor_speed_time += 1-db.actor.health*k_health
- k_health = 30,
- -- actor_speed_time += bleeding*k_bleed
- k_bleed = 1.2,
- },
- }
- helmet_active = true
- open_hud()
- RegisterScriptCallback("actor_on_net_destroy",net_destroy)
- end
- function deactivate_hud()
- if not (feature_is_active) then
- return
- end
- feature_is_active = false
- UnregisterScriptCallback("actor_on_net_destroy",net_destroy)
- opt = nil
- helmet_active = nil
- close_hud()
- end
- function open_hud()
- hud = get_hud()
- DynHud = DynamicHud()
- if DynHud then
- hud:AddDialogToRender(DynHud)
- end
- end
- function close_hud()
- if DynHud then
- if current_helm then hud:RemoveCustomStatic(current_helm) end
- current_helm = nil
- hud:RemoveDialogToRender(DynHud)
- DynHud = nil
- hud = nil
- end
- end
- ------------------------------------------
- function net_destroy()
- close_hud()
- end
- ------------------------------------------
- function on_game_start()
- if (axr_main.config:r_value("mm_options","enable_mask_hud",1,false) == false) then return end
- local function actor_on_first_update()
- activate_hud()
- end
- RegisterScriptCallback("actor_on_first_update",actor_on_first_update)
- end
- --// ----------------------------------------------------------
- --// -------------------DynHud class---------------------------
- --// ----------------------------------------------------------
- class "DynamicHud" (CUIScriptWnd)
- function DynamicHud:__init() super()
- self.snd_tg = time_global()
- self.tmr = self.snd_tg
- self.helmet_cond = 1
- self.helmet_name = ""
- self.suitfirstrun = true
- self.speed = 0
- self.health_play = 0
- self.gas_play = 0
- self.run_play = 0
- self.pos = db.actor:position()
- self.health = db.actor.health
- end
- function DynamicHud:__finalize() end
- function DynamicHud:Update()
- CUIScriptWnd.Update(self)
- local tg = time_global()
- if tg > self.tmr then
- self.tmr = tg+180
- self:HitEffect()
- self:hud_condition()
- self:ActorRadiation()
- end
- end
- --// OnUpdate Functions //--
- function DynamicHud:hud_condition()
- self.tg = time_global()
- self.helmet = db.actor:item_in_slot(12) or db.actor:item_in_slot(7)
- local cond = (self.helmet and self.helmet:condition()) or 0
- local helmet = db.actor:alive() and (self.helmet and opt.helmets[self.helmet:section()])
- local cam_dist = db.actor:bone_position("bip01_head"):distance_to_sqr(device().cam_pos)
- if not (helmet and helmet_active) or cam_dist > opt.cam_dist then
- if self.helmet_name then
- level.remove_pp_effector(3000)
- hud:RemoveCustomStatic(current_helm)
- current_helm = nil
- if cam_dist <= opt.cam_dist then
- local snd
- if opt.helmet_no_respi[self.helmet_name] or self.tg < (self.snd_tg-400) then
- snd = sound_object("actor\\gasmask_nobreath")
- else
- snd = sound_object("actor\\gasmask_off")
- end
- snd:play(db.actor,0,sound_object.s2d)
- self.snd_tg = self.tg+snd:length()+120
- self.gas_play = 0
- self.helmet_cond = 1
- self.helmet_name = nil
- self.suitfirstrun = true
- else
- self.helmet_name = ""
- end
- return
- end
- if helmet_active or self.health < opt.health.level2 then self:hud_no_mask() end
- else
- if self.suitfirstrun then
- local snd
- if opt.helmet_no_respi[helmet] or self.tg < self.snd_tg then
- snd = sound_object("actor\\gasmask_nobreath")
- else
- snd = sound_object("actor\\gasmask_on")
- end
- snd:play(db.actor,0,sound_object.s2d)
- self.snd_tg = self.tg+snd:length()+120
- self.suitfirstrun = false
- return
- end
- self:ActorSpeed()
- if opt.helmet_no_respi[helmet] then
- self:hud_no_mask()
- elseif self.tg>self.snd_tg then
- self.gas_play = self.gas_play+1
- if self.gas_play > 8 then self.gas_play = 1 end
- 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)
- self.snd_tg = self.tg+snd:length()*1.25
- snd:play(db.actor,0,sound_object.s2d)
- end
- --
- cond = math.floor(11*(1.17-cond))
- if helmet~=self.helmet_name or cond~=self.helmet_cond then
- if self.helmet_name then -- remove old
- hud:RemoveCustomStatic(current_helm)
- current_helm = nil
- end
- if self.suitfirstrun == false and cond > self.helmet_cond and helmet==self.helmet_name then --repaired
- local snd_obj = sound_object("material\\glass\\glass_fall03hl")
- snd_obj:play(db.actor,0,sound_object.s2d)
- elseif helmet~=self.helmet_name then -- changed
- level.remove_pp_effector(3000)
- self:UseHelm(helmet)
- end
- self.helmet_name = helmet
- self.helmet_cond = cond
- current_helm = self.helmet_name..self.helmet_cond
- hud:AddCustomStatic(current_helm)
- end
- --
- end
- end
- function DynamicHud:UseHelm(section)
- if helm_fx[section] then
- assert(loadstring(helm_fx[section]))()
- end
- end
- function DynamicHud:ActorSpeed()
- local pos = db.actor:position()
- self.speed = (pos.x - self.pos.x)^2+(pos.y - self.pos.y)^2+(pos.z - self.pos.z)^2
- self.pos = pos
- if self.speed > opt.speed.mini then
- self.speed = self.speed + opt.speed.inc
- elseif self.speed > opt.speed.dec then
- self.speed = self.speed - opt.speed.dec
- end
- self.speed = math.min(32, self.speed + db.actor.bleeding * opt.speed.k_bleed)
- self.speed = math.min(32, self.speed + (1-self.health) * opt.speed.k_health)
- end
- function DynamicHud:hud_no_mask()
- local health = self.health
- if self.tg < self.snd_tg or health < 0 then return end
- if health > opt.health.level2 then
- if self.speed > opt.speed.time_mini or db.actor.power < opt.speed.stamina or self.run_play == 1 then
- self.run_play = self.run_play+1
- if self.run_play > 8 then self.run_play = 1 end
- local snd = sound_object("actor\\run_"..math.ceil(3*self.speed/44).."_"..self.run_play)
- snd:play(db.actor,0,sound_object.s2d)
- self.snd_tg = self.tg+snd:length()*1.15
- else
- self.run_play = 2
- end
- return
- end
- if health <= opt.health.level1 then
- health = 1
- if math.random()<0.1 then
- self.health_play = 0
- else
- self.health_play = self.health_play+1
- if self.health_play > 4 then self.health_play = 1 end
- end
- else
- health = 2
- self.health_play = self.health_play+1
- if self.health_play > 4 then self.health_play = 1 end
- end
- local snd = sound_object("actor\\health_"..health.."_"..self.health_play)
- snd:play(db.actor,0,sound_object.s2d)
- self.snd_tg = self.tg+snd:length()*1.15
- end
- function DynamicHud:HitEffect()
- local health = db.actor.health
- local delta_health = (self.health-health)*100
- self.health = health
- if delta_health > opt.health.little_delta then
- level.add_pp_effector(opt.health.little_ppe, 2011, false)
- level.set_pp_effector_factor(2011, delta_health)
- if delta_health > opt.health.middle_delta then
- local cameffs,sounds
- if delta_health > opt.health.huge_delta then
- level.add_pp_effector(opt.health.huge_ppe, 2012, false)
- level.set_pp_effector_factor(2012, delta_health)
- cameffs = opt.health.huge_anm
- sounds = opt.health.huge_snd
- else
- cameffs = opt.health.middle_anm
- sounds = opt.health.middle_snd
- end
- if not wpn_effects.shott then --optional for recoil effects
- level.add_cam_effector("camera_effects\\"..cameffs[math.random(#cameffs)]..".anm",999,false,"")
- end --optional for recoil effects
- local snd_obj = sound_object("actor\\"..sounds[math.random(#sounds)])
- snd_obj:play(db.actor,0,sound_object.s2d)
- if math.random(100) < (delta_health*opt.health.drop_wnp_prob) then
- local active_item = db.actor:active_item()
- if active_item and not opt.health.no_drop_wnp[active_item:section()] then
- db.actor:drop_item(active_item)
- end
- end
- end
- end
- end
- function DynamicHud:ActorRadiation()
- local radiation = db.actor.radiation
- if radiation > 0 then
- if radiation > opt.radiation_ppe_threshold then
- level.add_pp_effector("radiation.ppe", 2020, true)
- else
- level.remove_pp_effector(2020)
- end
- level.set_pp_effector_factor(2020, radiation)
- if math.random()<radiation then
- radiation = radiation>0.5 and math.random()<radiation/1.3 and "click3" or math.random(8)
- local snd = sound_object("detectors\\geiger_"..radiation)
- snd:play(db.actor,0,sound_object.s2d)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement