-- ============================================================ -- -- dialogs_axr_companion.script -- CoC 1.4.21 - DoctorX Questlines 1.20 -- -- Modified by: DoctorX -- Last revised: December 21, 2016 -- -- ============================================================ --Scripting Dialog Made Easy local saved_dialog function add_dialog(p_id,id,phrase_id,cond,act) if not ( saved_dialog ) then return end local phrase = saved_dialog:AddPhrase(phrase_id,tostring(id),tostring(p_id),-10000) if not ( phrase ) then return end --printf("phrase_id = %s",phrase_id) local phrase_script = phrase:GetPhraseScript() if ( cond ) then if ( type(cond) == "table" ) then for key, value in pairs(cond) do if (utils_data.findfunction(value,_G)) then phrase_script:AddPrecondition(value) --table.insert(cond_list,value) else printe("!ERROR dialog_manager | No such function exists '%s'",value) end end else if (utils_data.findfunction(cond,_G)) then phrase_script:AddPrecondition(cond) --table.insert(cond_list,value) else printe("!ERROR dialog_manager | No such function exists '%s'",cond) end end end if ( act ) then if ( type(act) == "table" ) then for key, value in pairs(act) do if (utils_data.findfunction(value,_G)) then phrase_script:AddAction(value) else printe("!ERROR dialog_manager | No such function exists '%s'",value) end end else if (utils_data.findfunction(act,_G)) then phrase_script:AddAction(act) else printe("!ERROR dialog_manager | No such function exists '%s'",act) end end end return phrase_script end function set_actor_dialogs(npc, ini, name, dialog_section) if dialog_section == nil then return end local actor_dialogs_string = ini:r_string_ex(dialog_section,"id") or "" if actor_dialogs_string ~= nil then db.storage[npc:id()].actor_dialogs = parse_names(actor_dialogs_string) end local actor_disable = ini:r_string_ex(dialog_section,"disable") or "" if actor_disable ~= nil then db.storage[npc:id()].actor_disable = parse_names(actor_disable) end end function dm_init_is_actor_companion(dialog) saved_dialog = dialog ------MAIN [ DIALOG INITATION ] -- add_dialog("",0,"axr_phrase_actor_give_command","dialogs_axr_companion.is_actor_companion") add_dialog(0,1,"axr_phrase_companion_ask_for_command") ------MAIN [ SWAP ItEMS ] (666+) add_dialog(1,666,"st_companion_inv_show_gui",nil,"axr_companions.start_trade") add_dialog(1,667,"st_companion_inv_take_all_my_items","axr_companions.can_handle_all_items","axr_companions.give_all_to_companion") add_dialog(667,6671,"st_companion_inv_take_all_my_items_response_accept_" .. tostring(math.random(1,50))) add_dialog(1,668,"st_companion_inv_take_all_my_items_dummy","axr_companions.can_not_handle_all_items") add_dialog(668,6681,"st_companion_inv_take_all_my_items_response_refuse_" .. tostring(math.random(1,50))) add_dialog(1,669,"st_companion_inv_give_me_back_all_items","axr_companions.is_assigned_companion","axr_companions.take_all_from_companion") add_dialog(669,6691,"st_companion_inv_give_me_back_all_items_response") ------MAIN [ FOLLOW/WAIT ] (10+) add_dialog(1,10,"axr_phrase_actor_give_command_follow","dialogs_axr_companion.companion_is_not_following","dialogs_axr_companion.set_companion_to_follow_state") add_dialog(1,11,"axr_phrase_actor_give_command_wait","dialogs_axr_companion.companion_not_waiting","dialogs_axr_companion.set_companion_to_wait_state") ------MAIN [ COMBAT ] (20+) add_dialog(1,20,"axr_phrase_actor_give_command_combat") add_dialog(20,21,"axr_phrase_companion_acknowledge_3") -- sub-menu --[[ add_dialog(21,22,"axr_phrase_actor_give_command_combat_type_camper","dialogs_axr_companion.companion_combat_type_not_camper","dialogs_axr_companion.set_companion_combat_type_camper") add_dialog(21,23,"axr_phrase_actor_give_command_combat_type_monolith","dialogs_axr_companion.companion_combat_type_not_monolith","dialogs_axr_companion.set_companion_combat_type_monolith") add_dialog(21,24,"axr_phrase_actor_give_command_combat_type_default","dialogs_axr_companion.companion_combat_type_not_default","dialogs_axr_companion.set_companion_combat_type_default") --]] add_dialog(21,25,"axr_phrase_actor_give_command_ignore_combat","dialogs_axr_companion.companion_is_not_ignoring_combat","dialogs_axr_companion.set_companion_to_ignore_combat_state") add_dialog(21,26,"axr_phrase_actor_give_command_dont_ignore_combat","dialogs_axr_companion.companion_is_ignoring_combat","dialogs_axr_companion.set_companion_to_attack_state") add_dialog(21,27,"axr_phrase_actor_give_command_ignore_combat_but_help_actor","dialogs_axr_companion.companion_is_not_ignoring_combat","dialogs_axr_companion.set_companion_to_attack_only_actor_combat_enemy_state") ------MAIN [ Find-Cover ] (30+) --add_dialog(1,30,"axr_phrase_actor_give_command_hide_in_cover","dialogs_axr_companion.companion_not_hiding_in_cover","dialogs_axr_companion.set_companion_hide_in_cover") ------MAIN [ DISTANCE ] (40+) add_dialog(1,40,"axr_phrase_actor_give_command_stay_close","dialogs_axr_companion.companion_distance_far","dialogs_axr_companion.switch_companion_distance") add_dialog(1,41,"axr_phrase_actor_give_command_keep_distance","dialogs_axr_companion.companion_distance_near","dialogs_axr_companion.switch_companion_distance") ------MAIN [ STEALTH ] (50+) add_dialog(1,50,"axr_phrase_actor_give_command_stealth","dialogs_axr_companion.companion_not_stealthy","dialogs_axr_companion.set_companion_to_stealth_substate") add_dialog(1,51,"axr_phrase_actor_give_command_stop_stealth","dialogs_axr_companion.companion_is_stealthy","dialogs_axr_companion.set_companion_to_default_substate") ------MAIN [ Looting ] (55+) add_dialog(1,55,"axr_phrase_actor_give_command_gather_items","dialogs_axr_companion.companion_gather_items_disabled","dialogs_axr_companion.switch_companion_gather_items") add_dialog(1,56,"axr_phrase_actor_give_command_gather_items_stop","dialogs_axr_companion.companion_gather_items_enabled","dialogs_axr_companion.switch_companion_gather_items") add_dialog(1,57,"axr_phrase_actor_give_command_loot_corpses","dialogs_axr_companion.companion_loot_corpses_disabled","dialogs_axr_companion.switch_companion_loot_corpses") add_dialog(1,58,"axr_phrase_actor_give_command_loot_corpses_stop","dialogs_axr_companion.companion_loot_corpses_enabled","dialogs_axr_companion.switch_companion_loot_corpses") ------MAIN [ PATROL ] (55+) --add_dialog(1,55,"axr_phrase_actor_give_command_patrol_menu") --add_dialog(55,56,"axr_phrase_companion_acknowledge_2") -- sub-menu --add_dialog(56,57,"axr_phrase_actor_give_command_stop_patrol","dialogs_axr_companion.companion_is_patrolling","dialogs_axr_companion.switch_companion_patrol_mode") --add_dialog(56,58,"axr_phrase_actor_give_command_start_patrol",{"dialogs_axr_companion.companion_not_patrolling","dialogs_axr_companion.companion_has_waypoint"},"dialogs_axr_companion.switch_companion_patrol_mode") --add_dialog(56,59,"axr_phrase_actor_give_command_patrol_add_waypoints","dialogs_axr_companion.companion_not_patrolling","dialogs_axr_companion.companion_add_waypoints") --add_dialog(56,60,"axr_phrase_actor_give_command_patrol_remove_waypoints",{"dialogs_axr_companion.companion_not_patrolling","dialogs_axr_companion.companion_has_waypoint"},{"dialogs_axr_companion.companion_remove_waypoints","dialogs_axr_companion.switch_companion_patrol_mode"}) ------MAIN [ COMPANION REMOVE ] (100+) --add_dialog(1,100,"axr_phrase_actor_give_command_leave") --add_dialog(100,101,"axr_phrase_companion_are_you_sure") -- sub-menu --add_dialog(101,102,"axr_phrase_actor_give_command_leave",nil,"dialogs_axr_companion.remove_companions_from_squad") ------{{Submenu --> exit}} (900+) add_dialog(1,900,"axr_phrase_actor_give_command_nevermind") add_dialog(21,901,"axr_phrase_actor_give_command_nevermind") --add_dialog(56,902,"axr_phrase_actor_give_command_nevermind") --add_dialog(101,903,"axr_phrase_actor_give_command_nevermind") end --[[ dialogs_axr_companion.is_actor_companion axr_phrase_actor_give_command_stealth dialogs_axr_companion.companion_not_stealthy dialogs_axr_companion.set_companion_to_stealth_substate axr_phrase_actor_give_command_stop_stealth dialogs_axr_companion.companion_is_stealthy dialogs_axr_companion.set_companion_to_default_substate --]] function dm_init_companion_patrol(dialog) saved_dialog = dialog add_dialog("",0,"axr_phrase_actor_give_command_patrol_menu") add_dialog(0,1,"axr_phrase_companion_acknowledge_2") add_dialog(1,2,"axr_phrase_actor_give_command_stop_patrol","dialogs_axr_companion.companion_is_patrolling","dialogs_axr_companion.switch_companion_patrol_mode") add_dialog(1,3,"axr_phrase_actor_give_command_start_patrol",{"dialogs_axr_companion.companion_not_patrolling","dialogs_axr_companion.companion_has_waypoint"},"dialogs_axr_companion.switch_companion_patrol_mode") add_dialog(1,4,"axr_phrase_actor_give_command_patrol_add_waypoints","dialogs_axr_companion.companion_not_patrolling","dialogs_axr_companion.companion_add_waypoints") add_dialog(1,5,"axr_phrase_actor_give_command_patrol_remove_waypoints",{"dialogs_axr_companion.companion_not_patrolling","dialogs_axr_companion.companion_has_waypoint"},{"dialogs_axr_companion.companion_remove_waypoints"}) add_dialog(1,6,"axr_phrase_actor_give_command_nevermind") end --[[ function dm_actor_become_companion_guide_precond(actor, npc) if not (axr_companions) then return false end if not (axr_companions.Enabled) then return false end local squad = get_object_squad(npc) if squad ~= nil and squad:commander_id() ~= npc:id() then return false end if npc:character_community() == "bandit" then return false end if npc:character_community() == "army" then return false end local npc_squad = get_object_squad(npc) if (npc_squad.current_action and npc_squad.current_action == 1) then return false end return is_not_actor_companion(actor,npc) end ------------------------------------------- function squad_action_description_for_chasing(actor,npc) local target_obj = alife_object(target_id) return "dm_" .. "stalker" .."_chasing_squad_"..alife_character_community(target_obj) --npc:character_community() end function squad_action_description_for_travelling(actor,npc) local target_obj = alife_object(target_id) local smart_name = target_obj:name() local travel_class = travel_manager.get_travel_class() local desc = travel_class.smart_to_stringtables[smart_name] if desc == nil then printf("wrong smart name [%s] in travel_manager.ltx", tostring(smart_name)) end return desc end function precond_squad_target_is_squad(actor,npc) local target_obj = alife_object(target_id) local target_clsid = target_obj:clsid() return target_clsid == clsid.online_offline_group_s end function precond_squad_target_is_smart(actor,npc) local target_obj = alife_object(target_id) local target_clsid = target_obj:clsid() return target_clsid == clsid.smart_terrain end --]] --[[ Become Companion Dialog Preconditions --]] function is_non_story(actor,npc) local squad = get_object_squad(npc) if not (squad) then return false end if (get_object_story_id(squad.id)) then return false end return true end function is_room_in_actor_squad(actor,npc) local max_size = axr_companions.max_actor_squad_size + (game_achievements.has_achievement("patriarch") and 2 or 0) if (axr_companions.get_companion_count() + utils_obj.get_squad_count(npc) <= max_size) then return true end return false end function is_module_enabled(actor,npc) return axr_companions and axr_companions.Enabled or false end function is_actor_friend(actor,npc) local npc = dialogs.who_is_npc(actor,npc) local squad = get_object_squad(npc) if not (squad) then return false end if not (axr_companions.allow_simulation_squads_as_companions) then return false end if not (axr_companions.allow_only_friends_as_companions) then return true end return npc:relation(db.actor) == game_object.friend end function set_squad_relation_by_chance(npc,actor) local chance = math.floor(random_number(1,10)+0.5) if ( chance < 3 ) then --axr_hostile_relations.set_squad_relation(npc,actor,game_object.enemy) end end function is_squad_count_greater(first_speaker,second_speaker) local count = utils_obj.get_squad_count(first_speaker) if ( count == nil or ( count and count <= 1 )) then return false end return true end function is_squad_count_one(first_speaker,second_speaker) local count = utils_obj.get_squad_count(first_speaker) if ( count and count > 1 ) then return false end return true end function become_actor_companion(actor,npc) local npc = dialogs.who_is_npc(actor,npc) local squad = get_object_squad(npc) if not (squad) then return end axr_companions.companion_squads[squad.id] = squad SIMBOARD:assign_squad_to_smart(squad, nil) for k in squad:squad_members() do local member = db.storage[k.id] and db.storage[k.id].object if ( member and member:alive() ) then axr_companions.add_to_actor_squad(member) end end end -- //////////////////////////////////////////////////////////////////////////////////////////////// -- -- is_hostage_task_giver function -- -- ------------------------------------------------------------------------------------------------ -- -- Description: -- - Determines if the current NPC is a simulation hostage task giver -- -- Usage: -- is_hostage_task_giver( ) -- -- Parameters: -- none -- -- Return value (type: bool): -- Returns true if the NPC is a current simulation hostage task giver, false otherwise -- -- ------------------------------------------------------------------------------------------------ -- Modified by DoctorX -- for DoctorX Questlines 1.6 -- Last modified October 13, 2016 -- ------------------------------------------------------------------------------------------------ -- Determine if current NPC is sim hostage giver: function is_hostage_task_giver( a, b ) -- Determine if current NPC is sim hostage task giver: local npc = dialogs.who_is_npc( a, b ) local se_obj = npc and alife( ):object( npc:id( ) ) local giver_id = se_obj and (se_obj.group_id ~= 65535 and se_obj.group_id or se_obj.id) if ( load_var( db.actor, ("drx_sl_hostage_giver_" .. giver_id), false ) ) then return true end return false end -- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ function is_not_hostage_task_giver(a,b) return not is_hostage_task_giver(a,b) end --[[ Companion Dialog Preconditions --]] function is_actor_companion(actor,npc) return npc:has_info("npcx_is_companion") end function is_not_actor_companion(actor,npc) return npc:has_info("npcx_is_companion") ~= true end function can_dismiss_companion(actor,npc) return npc:has_info("npcx_beh_cannot_dismiss") ~= true end function companion_is_stealthy(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_substate_stealth") end function companion_not_stealthy(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_substate_stealth") == false end function companion_is_not_ignoring_combat(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_ignore_combat") == false end function companion_is_ignoring_combat(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_ignore_combat") end function companion_is_not_following(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_wait") end function companion_not_waiting(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_wait") == false end function companion_distance_far(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_distance_far") end function companion_distance_near(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_distance_far") == false end function companion_using_cover(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_hide_in_cover") == true end function companion_not_using_cover(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_hide_in_cover") ~= true end function companion_combat_type_not_camper(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_combat_tactics_camper") == false end function companion_combat_type_not_monolith(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_combat_tactics_monolith") == false end function companion_combat_type_not_default(actor,npc) local npc = dialogs.who_is_npc(actor,npc) if ( npc:has_info("npcx_beh_combat_tactics_monolith") or npc:has_info("npcx_beh_combat_tactics_camper") ) then return true end end function companion_not_patrolling(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_patrol_mode") == false end function companion_is_patrolling(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_patrol_mode") end function companion_has_waypoint(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return se_load_var(npc:id(),npc:name(),"pathpoint2") ~= nil--load_var(npc,"pathpoint2") ~= nil end function companion_gather_items_enabled(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_gather_items") end function companion_gather_items_disabled(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_gather_items") == false end function companion_loot_corpses_enabled(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_loot_corpses") end function companion_loot_corpses_disabled(actor,npc) local npc = dialogs.who_is_npc(actor,npc) return npc:has_info("npcx_beh_loot_corpses") == false end --[[ Companion Dialog Actions --]] function set_companion_to_stealth_substate(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.set_companion_to_stealth_substate) end function set_companion_to_default_substate(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.set_companion_to_default_substate) end function set_companion_to_wait_state(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.set_companion_to_wait_state) end function set_companion_to_follow_state(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.set_companion_to_follow_state) end function set_companion_to_attack_state(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.set_companion_to_attack_state) end function set_companion_to_ignore_combat_state(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.set_companion_to_ignore_combat_state) end function set_companion_to_attack_only_actor_combat_enemy_state(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.set_companion_to_attack_only_actor_combat_enemy_state) end function switch_companion_distance(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.switch_companion_distance) end function remove_companions_from_squad(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.remove_from_actor_squad) end function set_companion_hide_in_cover(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.set_companion_hide_in_cover) end function set_companion_combat_type_camper(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.set_companion_combat_type_camper) end function set_companion_combat_type_monolith(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.set_companion_combat_type_monolith) end function set_companion_combat_type_default(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.set_companion_combat_type_default) end function switch_companion_patrol_mode(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.switch_companion_patrol_mode) --axr_companions.switch_companion_patrol_mode(npc) end function companion_add_waypoints(actor,npc) local npc = dialogs.who_is_npc(actor,npc) --utils_obj.execute_script_on_squad(npc,axr_companions.companion_add_waypoints) axr_companions.companion_add_waypoints(npc) end function companion_remove_waypoints(actor,npc) local npc = dialogs.who_is_npc(actor,npc) --utils_obj.execute_script_on_squad(npc,axr_companions.companion_remove_waypoints) axr_companions.companion_remove_waypoints(npc) end function switch_companion_gather_items(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.switch_companion_gather_items) end function switch_companion_loot_corpses(actor,npc) local npc = dialogs.who_is_npc(actor,npc) utils_obj.execute_script_on_squad(npc,axr_companions.switch_companion_loot_corpses) end function st_companion_talk_anecdote(a,b) local str = game.translate_string("st_phrase_companion_talk_" .. math.random(1,128)) return str end function st_companion_talk_fact(a,b) local str = game.translate_string("st_phrase_companion_fact_" .. math.random(1,196)) return str end