Divergent/mods/Western Goods/gamedata/scripts/western_goods_usable_items....

155 lines
7.2 KiB
Plaintext
Raw Permalink Normal View History

2024-03-17 20:18:03 -04:00
---==================================================================================================================---
--- ---
--- Original Author(s) : NLTP_ASHES ---
--- Edited : N/A ---
--- Date : 17/04/2023 ---
--- License : Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) ---
--- ---
--- Script used to manage the various usable items from the Western Goods addon. ---
--- This script contains functions used to return the text displayed when right-clicking on items. ---
--- It also contains a use_item(...) function where items will be filtered to their respective functions. ---
--- ---
---==================================================================================================================---
-- ---------------------------------------------------------------------------------------------------------------------
-- Constants, global variables and imported functions
-- ---------------------------------------------------------------------------------------------------------------------
local dbg_printf = western_goods_utils.dbg_printf
local CreatePersistentTimeEvent = western_goods_persistent_timed_events.CreatePersistentTimeEvent
-- ---------------------------------------------------------------------------------------------------------------------
-- Inventory Labels
-- ---------------------------------------------------------------------------------------------------------------------
--- Function used to return the text written when right clicking on a lighter.
--- @param obj game_object
--- @return string
function menu_use(obj)
return western_goods_utils.get_translation("st_wg_use")
end
--- Function used to return the text written when right clicking on a suitcase.
--- @param obj game_object
--- @return string
function menu_open(obj)
return western_goods_utils.get_translation("st_wg_open")
end
--- Function used to return the text written when right clicking on a magazine.
--- @param obj game_object
--- @return string
function menu_view(obj)
return western_goods_utils.get_translation("st_wg_view")
end
--- Function used to return the text written when right clicking on an MRE.
--- @param obj game_object
--- @return string
function menu_unpack(obj)
return western_goods_utils.get_translation("st_wg_unpack")
end
--- Function used to return the text written when right clicking on an porn magazine (Pinup Collect addon).
--- @param obj game_object
--- @return string
function menu_tear_page(obj)
if not item_pinup_collect then
return nil
end
return western_goods_utils.get_translation("st_wg_tear_page")
end
-- ---------------------------------------------------------------------------------------------------------------------
-- Use Functions
-- ---------------------------------------------------------------------------------------------------------------------
--- Function called by callback when any object in the game is used.
--- This redirects to the proper functions if the item used is one from Western Goods.
--- @param obj game_object
--- @return nil
function use_item(obj,_,cf)
-- Toblerone
if (obj:section() == "wg_toblerone") then
dbg_printf("[WG] Usable Items | Used %s",obj:section())
this.use_toblerone(obj)
return
end
-- Readable items (magazines, paper notes)
if ini_sys:r_bool_ex(obj:section(), "readable", false) then
dbg_printf("[WG] Usable Items | Used %s",obj:section())
western_goods_ui_readable.display(obj:section())
return
end
end
--- Function called by callback when an object is drag and dropped over another one.
--- This redirects to the proper functions if the item used is one from Western Goods.
--- @param obj game_object
--- @return nil
function use_item_drag_drop(dragged_item, dropped_on_item, slot_from, slot_to)
-- Danylo's pendrive
if dragged_item:section() == "wg_danylo_pendrive_quest_item" and western_goods_utils.validate_is_pda(dropped_on_item) then
if slot_from == EDDListType.iActorBag and slot_to == EDDListType.iActorSlot then
this.use_danylo_pendrive(dragged_item)
end
end
end
-- ---------------------------------------------------------------------------------------------------------------------
-- Toblerone
-- ---------------------------------------------------------------------------------------------------------------------
--- Function called when the Toblorone item is used by the player.
--- @param obj game_object
--- @return nil
function use_toblerone(obj)
CreatePersistentTimeEvent("western_goods_delay","toblerone_mask",2,function()
level.add_pp_effector("yantar_underground_psi.ppe", 57742, false)
dbg_printf("[WG] Usable Items | Toblerone - Started ppe effect '%s'",57742)
return true
end)
CreatePersistentTimeEvent("western_goods_delay","force_sleep",6,function()
level.remove_pp_effector(57742)
dbg_printf("[WG] Usable Items | Toblerone - Stopped ppe effect '%s'",57742)
actor_status_thirst.force_sleep()
return true
end)
end
-- ---------------------------------------------------------------------------------------------------------------------
-- Danylo's pendrive
-- ---------------------------------------------------------------------------------------------------------------------
--- Function called when the player uses Danylo's pendrive.
--- @param obj game_object
--- @return nil
function use_danylo_pendrive(obj)
ui_pda_encyclopedia_tab.unlock_note("encyclopedia__notes_western_goods_hand_drawn_map")
end
-- ---------------------------------------------------------------------------------------------------------------------
-- Pinup Collector addon
-- ---------------------------------------------------------------------------------------------------------------------
--- Function called by item use functors when a page is torn off a porn magazine.
--- @param obj game_object
--- @return nil
function tear_page(obj)
if item_pinup_collect then
item_pinup_collect.func_pinup(obj)
end
return nil
end
-- ---------------------------------------------------------------------------------------------------------------------
-- Callbacks registration
-- ---------------------------------------------------------------------------------------------------------------------
--- Function used to register callbacks.
--- @return nil
function on_game_start()
RegisterScriptCallback("actor_on_item_use", use_item)
RegisterScriptCallback("ActorMenu_on_item_drag_drop", use_item_drag_drop)
end