---==================================================================================================================--- --- --- --- Original Author(s) : NLTP_ASHES --- --- Edited : N/A --- --- Date : 19/05/2023 --- --- License : Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) --- --- --- --- Script used to spawn NPCs that should permanently exist in the world (mostly if not exclusively traders). --- --- --- --- To add a new NPC to the system, add a new line in the squads_to_spawn table, as follows : --- --- --- --- { sec="", sid="", smart="" }, --- --- --- --- Where : --- --- - : section of the squad that needs to be spawned in; --- --- - : story id of the squad that needs to be spawned in; --- --- - : name of the smart where the squad should be spawned at; --- --- --- ---==================================================================================================================--- -- --------------------------------------------------------------------------------------------------------------------- -- Constants, global variables and imported functions -- --------------------------------------------------------------------------------------------------------------------- -- Imported functions local dbg_printf = western_goods_utils.dbg_printf -- Constants local squads_to_spawn = { ["stalker_western_goods_trader_squad"] = { sid="stalker_western_goods_trader_squad", smart="pri_a18_smart_terrain" }, ["stalker_oleksandr_chernenko_squad"] = { sid="stalker_oleksandr_chernenko_squad", smart="gar_smart_terrain_6_3" }, } local squads_relations = { ["stalker_western_goods_trader_squad"] = "neutral", ["stalker_oleksandr_chernenko_squad"] = "neutral", ["stalker_danylo_chernenko_squad"] = "neutral", ["western_goods_act_2_task_2_bandit_1_squad"] = "enemy", ["western_goods_act_2_task_2_bandit_2_squad"] = "enemy", } -- --------------------------------------------------------------------------------------------------------------------- -- General functions -- --------------------------------------------------------------------------------------------------------------------- --- Function used to spawn the permanent NPCs on the map. --- @return nil function spawn_squads() for section,data in pairs(squads_to_spawn) do local squad_se = western_goods_utils.server_object_by_sid(data.sid) if not squad_se then squad_se = western_goods_utils.spawn_story_squad(section, nil, SIMBOARD.smarts_by_names[data.smart]) dbg_printf("[WG] Permanent NPCs | Created %s(%s) at %s", section, squad_se.id, data.smart) else dbg_printf("[WG] Permanent NPCs | Squad %s(%s) already exists", squad_se:section_name(), squad_se.id) end end end --- Function used to force some NPCs to be neutral to and with everyone. --- This function is fired by 'on_enemy_eval' callback. --- @param obj game_object --- @param enemy game_object --- @param flags table --- @return nil function eval_ignore_npcs(obj,enemy,flags) -- Skip mutants if IsMonster(obj) or IsMonster(enemy) then return end -- Get squad local squad_obj = western_goods_utils.get_squad_of(obj) local squad_enemy = western_goods_utils.get_squad_of(enemy) -- Get squad relation (if any) local relation_obj = squad_obj and squads_relations[squad_obj:section_name()] local relation_enemy = squad_enemy and squads_relations[squad_enemy:section_name()] -- Skip unaffected squads if (not relation_obj) and (not relation_enemy) then return end -- Override eval if relation_obj == "neutral" or relation_enemy == "neutral" then flags.override = true flags.result = false return elseif relation_obj == "enemy" or relation_enemy == "enemy" then flags.override = true flags.result = true return end end -- --------------------------------------------------------------------------------------------------------------------- -- Oleksandr Chernenko functions -- --------------------------------------------------------------------------------------------------------------------- --- Function used to determine if Oleksandr Chernenko can show the Flea Market dialog. --- @param actor game_object --- @param npc game_object --- @param flags table function oleksandr_can_show_flea(actor,npc,flags) if npc:section() == "stalker_oleksandr_chernenko" then flags.result = western_goods_utils.has_info("western_goods_oleksandr_chernenko_meet_over") end end -- --------------------------------------------------------------------------------------------------------------------- -- Williams Heades functions -- --------------------------------------------------------------------------------------------------------------------- if western_goods_core.is_barter_ui_installed() then --- Function used to initiate the Barter UI. --- @return nil function ashes_barter() utils_obj.play_sound("interface\\inv_open") barter_ui.start() end end --- Function used to determine if Williams Heades can show the EUR/USD trade dialog. --- @param actor game_object --- @param npc game_object --- @param flags table function ashes_can_show_trade(actor,npc,flags) if npc:section() == "stalker_western_goods_trader" then flags.result = western_goods_utils.has_info("western_goods_trader_first_meet_over") end end -- --------------------------------------------------------------------------------------------------------------------- -- Crew Member functions -- --------------------------------------------------------------------------------------------------------------------- if western_goods_core.is_barter_ui_installed() then --- Function used to initiate the Barter UI. --- @return nil function crew_member_barter() utils_obj.play_sound("interface\\inv_open") barter_ui.start() end end -- --------------------------------------------------------------------------------------------------------------------- -- Callbacks registration -- --------------------------------------------------------------------------------------------------------------------- --- Function used to register callbacks. --- @return nil function on_game_start() RegisterScriptCallback("on_enemy_eval", eval_ignore_npcs) RegisterScriptCallback("actor_on_first_update", spawn_squads) RegisterScriptCallback("western_goods_flea_on_dialog", oleksandr_can_show_flea) RegisterScriptCallback("western_goods_trade_eur_usd_on_dialog", ashes_can_show_trade) end