Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// ----------------- sleep deprivation for CoC ---------------------
- --// author : Nuor
- --// version: 1.23 (alt)
- --// created: 4-09-2016
- --// last edit: 4-24-2016
- --//------------------------------------------------------------------------------
- last_sleep, no_sleep, caff_chk = nil,nil,nil -- to change defaults, edit below in 'activate_feature' function
- local items,force,start_blur,itn_mul,pwr_rate,rng_factor,caff_max,last_warning,die_chance,last_chk,pwr_chk, _tmr
- feature_is_active = nil
- local function main_loop()
- if not (db.actor) then
- return false
- end
- local tg = time_global()
- --[[// drain power when exhausted
- if last_sleep > start_blur then
- if (pwr_chk == nil or tg > pwr_chk) then
- --local coeff = area_skills and 1+area_skills.skills_table.survival_skill/25 or 1
- if (db.actor.power > 0) then
- db.actor.power = pwr_rate*(1+((last_sleep-start_blur)*rng_factor))-- * coeff
- end
- pwr_chk = tg+100
- end
- end
- --]]
- if (_tmr and tg < _tmr) then
- return false
- end
- _tmr = tg + 2000
- -- local cactor = db.actor:cast_Actor():conditions()
- -- local pwr = cactor and cactor[ "GetMaxPower" ] and cactor[ "GetMaxPower" ](cactor)
- -- printf("power:%s",pwr)
- --printf("last_chk=%s last_sleep=%s",last_chk and game.get_game_time():diffSec(last_chk) or "nil",last_sleep)
- if db.actor:has_info("actor_is_sleeping") then
- last_sleep = 0
- local cactor = db.actor:cast_Actor():conditions()
- if cactor and cactor[ "GetMaxPower" ] then
- cactor[ "SetMaxPower" ](cactor,1)
- end
- level.remove_pp_effector(1999)
- end
- if (last_chk and game.get_game_time():diffSec(last_chk) < 3600) then
- return false
- end
- last_chk = game.get_game_time()
- last_sleep = last_sleep + 1
- caff_chk = caff_chk > 1 and caff_chk - 1 or 0
- test_blur()
- return false
- end
- function activate_feature()
- if (feature_is_active) then
- return
- end
- feature_is_active = true
- items = {}
- local ini = ini_file("plugins\\sleep_deprivation.ltx")
- if (ini and ini:section_exist("items")) then
- local line_count = ini:line_count("items") or 0
- for i = 0, line_count - 1 do
- local junk1, section, value = ini:r_line("items", i, "", "")
- items[section] = value
- end
- end
- last_sleep = last_sleep or 0
- no_sleep = 1 --// change "no_sleep" to 0 to allow sleep spam
- caff_chk = caff_chk or 0
- force = 60 --// time between sleeps that triggers passing out
- start_blur = 20 --// time between sleeps when vision blur starts
- itn_mul = 0.05 --// blur intensity multiplier
- pwr_rate,rng_factor = -0.00065, 0.08 --// power reduction rate ,high/low range multiplier - lower is flatter
- caff_max = 3 --// max energy drinks per hr
- last_warning = 3 --// # of hourly warnings before passing out
- die_chance = 0.01 --// chance of dying if actor passes out
- sleep_penalty = 0.01 --// reduction in max power for every hour of exhaustion (start_blur >).
- RegisterScriptCallback("actor_on_item_use",actor_on_item_use)
- RegisterScriptCallback("save_state",save_state)
- AddUniqueCall(main_loop)
- end
- function deactivate_feature()
- if not (feature_is_active) then
- return
- end
- feature_is_active = false
- RemoveUniqueCall(main_loop)
- UnregisterScriptCallback("actor_on_item_use",actor_on_item_use)
- if (USE_MARSHAL) then
- UnregisterScriptCallback("save_state",save_state)
- UnregisterScriptCallback("load_state",load_state)
- end
- alife_storage_manager.get_state().sleep_deprived = nil
- end
- function on_game_start()
- if (axr_main.config:r_value("mm_options","enable_sleep_deprived",1,false) == false) then
- return
- end
- local function actor_on_first_update()
- activate_feature()
- if last_sleep > start_blur then
- --local coeff = area_skills and 1+area_skills.skills_table.survival_skill/25 or 1
- level.add_pp_effector("yantar_underground_psi.ppe", 1999, true)
- level.set_pp_effector_factor(1999, (last_sleep-start_blur) * itn_mul) -- * coeff)
- if last_sleep >= (force - last_warning + 1) then
- SetHudMsg(game.translate_string("st_sleep_exhausted_final"),5)
- else
- SetHudMsg(game.translate_string("st_sleep_exhausted"),4)
- end
- local cactor = db.actor:cast_Actor():conditions()
- local pwr = cactor[ "GetMaxPower" ] and cactor[ "GetMaxPower" ](cactor)
- cactor[ "SetMaxPower" ](cactor,pwr - sleep_penalty*(last_sleep-start_blur))
- end
- end
- RegisterScriptCallback("load_state",load_state)
- RegisterScriptCallback("actor_on_first_update",actor_on_first_update,true)
- end
- ----// add to bind_stalker or bind_stalker_ext save/load if used. //--
- function save(package) -- sleep_dep.save -> actor_binder:save()
- if (USE_MARSHAL) then
- return
- end
- package:w_u8(last_sleep)
- package:w_u16(last_chk)
- package:w_u8(caff_chk)
- end
- function load(package) -- sleep_dep.load -> actor_binder:load()
- if (USE_MARSHAL) then
- return
- end
- last_sleep = package:r_u8() or 0
- last_chk = package:r_u16() or 0
- caff_chk = package:r_u8() or 0
- end
- --//--------------------------------------------------------------//--
- function save_state(m_data)
- if (USE_MARSHAL) then
- m_data.sleep_deprived = m_data.sleep_deprived or {}
- m_data.sleep_deprived.last_sleep = last_sleep
- m_data.sleep_deprived.caff = caff_chk
- m_data.sleep_deprived.last_chk = last_chk
- end
- end
- function load_state(m_data)
- if (USE_MARSHAL and m_data.sleep_deprived) then
- last_sleep = m_data.sleep_deprived.last_sleep or 0
- -- printf("load state last_sleep [%s]", last_sleep)
- caff_chk = m_data.sleep_deprived.caff or 0
- last_chk = m_data.sleep_deprived.last_chk or game.get_game_time()
- m_data.sleep_deprived = nil
- end
- end
- function actor_on_item_use(item)
- local section = item:section()
- local value = items and tonumber(items[section]) or 0
- if items[section] then
- if value < 0 then
- caff_chk = caff_chk + 1
- if caff_chk > caff_max then return end
- end
- last_sleep = last_sleep + value
- test_blur()
- end
- end
- function test_blur()
- -- local coeff = area_skills and 1+area_skills.skills_table.survival_skill/25 or 1
- level.remove_pp_effector(1999)
- local cactor = db.actor:cast_Actor():conditions()
- if last_sleep > force then
- force_sleep()
- elseif last_sleep > start_blur then
- level.add_pp_effector("yantar_underground_psi.ppe", 1999, true)
- level.set_pp_effector_factor(1999, (last_sleep-start_blur) * itn_mul) -- * coeff)
- if last_sleep >= (force - last_warning + 1) then
- SetHudMsg(game.translate_string("st_sleep_exhausted_final"),5)
- else
- SetHudMsg(game.translate_string("st_sleep_exhausted"),4)
- end
- local pwr = cactor[ "GetMaxPower" ] and cactor[ "GetMaxPower" ](cactor)
- cactor[ "SetMaxPower" ](cactor,pwr - sleep_penalty)
- printf("max power:%s",cactor[ "GetMaxPower" ](cactor))
- else
- cactor[ "SetMaxPower" ](cactor,1)
- end
- end
- function force_sleep()
- ui_sleep_dialog.sleep_forced()
- if (math.random(1,100)/100) < die_chance then
- SetHudMsg(game.translate_string("st_sleep_deprived"),10)
- db.actor:kill(db.actor)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment