Divergent/mods/Zone Quit/gamedata/scripts/z_zone_quit.script

89 lines
2.2 KiB
Plaintext
Raw Permalink Normal View History

2024-03-17 20:18:03 -04:00
--[[
=====================================================================
Addon : Zone Quit
Link : https://www.moddb.com/mods/stalker-anomaly/addons/zone-quit
Author : party_50
Date : 19.02.2024
Last Edit : 21.02.2024
=====================================================================
--]]
local HAVE_TO_FINISH_STORY = true
local GATES_LEVEL = "l01_escape"
local GATES_POS = vector():set(-123.3811, -26.3140, -478.0168)
local TRIGGER_RADIUS = 3
local PAUSE_DURATION = 3000
local quit_zone_time = 0
local near_exit = false
local update_timer = 0
local dialog
class "exit_dialog" (CUIScriptWnd)
function exit_dialog:__init() super()
self:SetWndRect(Frect():set(0, 0, 1024, 768))
self.exit_mb = CUIMessageBoxEx()
self:Register(self.exit_mb, "exit_mb")
self:AddCallback("exit_mb", ui_events.MESSAGE_BOX_YES_CLICKED, self.OnMsgYes, self)
end
function exit_dialog:Show(mb_type, text)
self.exit_mb:InitMessageBox(mb_type)
self.exit_mb:SetText(text)
self.exit_mb:ShowDialog(true)
end
function exit_dialog:OnMsgYes()
quit_zone_time = time_global()
level.add_pp_effector("sleep_fade.ppe", 10006, false)
end
function show_dialog(mb_type, text)
if not dialog then
dialog = exit_dialog()
end
dialog:Show(mb_type, text)
end
function process_exit_dialog()
if has_alife_info("story_mode_disabled") or not HAVE_TO_FINISH_STORY or has_alife_info("operation_afterglow_complete") then
show_dialog("message_box_yes_no", "st_zone_quit_text")
else
actor_menu.set_msg(1, "st_zone_quit_not_done", 10)
end
end
function actor_on_update()
local tg = time_global()
if quit_zone_time == 0 and update_timer > tg then
return
end
update_timer = tg + 200
-- Following code is executed once per 200 ms
if level.name() ~= GATES_LEVEL then
return
end
if quit_zone_time == 0 and db.actor:position():distance_to(GATES_POS) < TRIGGER_RADIUS then
if not near_exit then
process_exit_dialog()
end
near_exit = true
else
near_exit = false
end
if quit_zone_time > 0 and time_global() - quit_zone_time > PAUSE_DURATION then
xr_effects.game_disconnect()
xr_effects.game_credits()
end
end
function on_game_start()
RegisterScriptCallback("actor_on_update", actor_on_update)
end