Random encounters in a scene

Users who are viewing this thread

Keedo420

Knight at Arms
I have recently added a dungeon to my mod and I am trying to figure out a way to implement random encounters. The dungeon is entered through a Passage in a village scene (a set of ruins that has a tavern run by a band of mercenaries). I'm thinking the easiest way to do it would be to make it similar to the combat scene when you are ambushed entering a town, but I can't seem to find the right mission template for that to examine. But I'm also wondering if it is possible to make it so that a combat encounter is triggered when passing certain points of the dungeon (such as when approaching an intersection or room) and then having the enemies spawn at nearby but out of site spawn points (around the corner, behind you, in the room ahead, etc) to make it seem a little more random. Can anyone give me suggestions on the best way to implement this?
 
Keedo420 said:
I have recently added a dungeon to my mod and I am trying to figure out a way to implement random encounters. The dungeon is entered through a Passage in a village scene (a set of ruins that has a tavern run by a band of mercenaries). I'm thinking the easiest way to do it would be to make it similar to the combat scene when you are ambushed entering a town, but I can't seem to find the right mission template for that to examine. But I'm also wondering if it is possible to make it so that a combat encounter is triggered when passing certain points of the dungeon (such as when approaching an intersection or room) and then having the enemies spawn at nearby but out of site spawn points (around the corner, behind you, in the room ahead, etc) to make it seem a little more random. Can anyone give me suggestions on the best way to implement this?

You should pm WickedShot, he's got that stuff figured out.
 
Wickedshot found out how to get troops to randomly spawn while the player is in a scene, but not to get troops to spawn when the player goes somewhere in a scene.
 
heres a simple version of what you want:
("random_encounter_bandits",
[(get_player_agent_no,":player_agent"),
(agent_get_position,pos1,":player_agent"),
(entry_point_get_position, pos2, 10),
(get_distance_between_positions,":temp_distance",pos1,pos2),
(lt, ":temp_distance", 200),
(set_spawn_position, pos1),
(spawn_agent,"trp_looter"),
]),

it spawns a looter at entry point 10 if you come within 2 meters (200 centimeters) from entry point 10

to make it only happen once youd add a trigger to the mission template you use that can only be called once, like:
(0, 0, ti_once,[(call_script, "script_random_encounter_bandits")],[]),
 
Hey thanks! :smile: I meant to PM you about this, but I got distracted with my first attempt at modelling a weapon in wings3d. I didn't actually make the weapon. I just wanted a Gladius style weapon, so I took the throwing daggers mesh (which looks pretty close to a gladius except for the color) and resized/realigned it. Anyway, thanks. I'll play around with that code and see if I can make it work for me.
 
OK, I got it to work. At first, it was spawning the troop as a normal npc (including generic dialogue if I talked to it), so I modified the script to include the lines in red and the troop started spawning as an enemy.
#random skeleton encounter
  ("cf_random_encounter_skeletons",
  [(get_player_agent_no,":player_agent"),
    (agent_is_alive, ":player_agent"),
    (agent_get_position,pos1,":player_agent"),
    (entry_point_get_position, pos2, 10),
    (get_distance_between_positions,":temp_distance",pos1,pos2),
    (lt, ":temp_distance", 200),
    (set_spawn_position, pos2),
    (spawn_agent,"trp_skeleton"),
    (try_for_agents, ":cur_agent"),
      (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
      (eq, ":cur_agent_troop", "trp_skeleton"),
      (agent_set_team, ":cur_agent", 1),
    (try_end),

  ]),
Currently, the troop spawns when I'm right in front of the spawn point so I think I will play with the distance so the troop spawns when I am farther away.
 
Oh, instead of that search for skelettes, you can just use:
(assign, ":cur_agent", reg0),
(agent_set_team, ":cur_agent",1),
After you spawn an agent, reg0 contains a pointer to them, so no need to go searching for them.
 
Well that is certainly easier. :mrgreen: Thanks again. My next challenge is figuring out how to get loot from the spawned enemies. I want players to be able to explore and fight in the dungeon as long as they want (or until they die  :twisted:) so it is basically an endless battle scene with no victory conditions. You can't tab out of the mission and the only ways out are to die or return to the entrance. I tried setting up a periodic trigger that would take you to the loot menu if no enemies were present in the scene but that didn't quite work out and now it is time for bed so I must tackle that challenge another day.
 
:grin: I modified the script a little more so that now it randomly spawns one of two different skeletal troops at one of two different spawn points. If I am out of range of one of the spawn points but in range of the other, then it either doesn't spawn or spawns at the closer one.

  ("cf_random_encounter_skeletons",
  [(get_player_agent_no,":player_agent"),
    (agent_is_alive, ":player_agent"),
    (agent_get_position,pos1,":player_agent"),
    (store_random_in_range, ":random_entry_point", 10, 12),
    (entry_point_get_position, pos2, ":random_entry_point"),
    (get_distance_between_positions,":temp_distance",pos1,pos2),
    (lt, ":temp_distance", 700),
(store_random_in_range, ":random_spawned_troop", 0, 2),
(try_begin),
  (eq, ":random_spawned_troop", 0),
  (set_spawn_position, pos2),
      (spawn_agent,"trp_skeleton"),
(else_try),
  (set_spawn_position, pos2),
      (spawn_agent,"trp_skeletal_fighter"),
(try_end),
(assign, ":cur_agent", reg0),
    (agent_set_team, ":cur_agent",1),
  ]),
 
I have modified the random encounters script so that now I have a script to award xp and gold when the player enters a certain area. So in a sense, players are now rewarded for exploring the scene. Combined with the treasure chests, this makes up for the fact that the player gets no loot from the random encounters. When I start working on the dungeon-related quests, I will be able to tie them into these exploration rewards. I might also be able to use this modified script to give players more incentive to walk around towns instead of doing everything from the menu.

  ("cf_dungeon_xp_awards",
  [(get_player_agent_no,":player_agent"),
    (agent_is_alive, ":player_agent"),
    (agent_get_position,pos1,":player_agent"),
    (store_random_in_range, ":random_entry_point", 10, 11),
    (entry_point_get_position, pos2, ":random_entry_point"),
    (get_distance_between_positions,":temp_distance",pos1,pos2),
    (lt, ":temp_distance", 200),
  (try_begin),
    (eq,":random_entry_point", 10),
    (display_message, "@You discovered a haunted bedchamber. Upon entering the room, you find 10 denars on the floor."),
    (add_xp_as_reward, 50),
        (troop_add_gold, "trp_player", 10),
(val_add, "$g_already_triggered", 1),
  (try_end),
 
Back
Top Bottom