How to summon allies to current location

Users who are viewing this thread

Keedo420

Knight at Arms
I came up with this simple little script to solve a dilemma involving the dungeon in my mod. When you first enter the dungeon, the first two troops in your party (or the first two troops in a stack if a stack is first in your party) will spawn near you. However, since there are no enemies in the dungeon until you trigger various encounters, those troops will just stand there unless you issue the "Follow me" command. On top of that, npc path finding in the dungeon is horrible which made getting the troops where you needed them a monumental test of patience. So I came up with this little script to summon your allies to your current location.

In the dungeon mission template (the only one I wanted this option to be available in), I added this trigger:
Code:
	  (0, 0, 0, [(key_clicked, key_m),(call_script, "script_cf_summon_allies")], []),

And in module_scripts, I added this script:
Code:
#summon allies
  ("cf_summon_allies",
   [(get_player_agent_no,":player_agent"),(agent_is_alive,":player_agent"),(agent_get_position,pos1,":player_agent"),
    (try_for_agents, ":ally"),
	  (neq,":ally",":player_agent"),
      (agent_is_alive,":ally"),
      (agent_is_ally,":ally"),
      (agent_set_position,":ally",pos1),
    (try_end),
	]),

This causes your allies in the scene to be relocated to your current position when you press the M key. I was quite pleased that I actually figured out how to do this myself, since this is the first script I wrote entirely on my own without looking at other scripts for examples. So I thought I would share it in case anyone wanted to do something similar.
 
Keedo420 said:
I came up with this simple little script to solve a dilemma involving the dungeon in my mod. When you first enter the dungeon, the first two troops in your party (or the first two troops in a stack if a stack is first in your party) will spawn near you. However, since there are no enemies in the dungeon until you trigger various encounters, those troops will just stand there unless you issue the "Follow me" command. On top of that, npc path finding in the dungeon is horrible which made getting the troops where you needed them a monumental test of patience. So I came up with this little script to summon your allies to your current location.

In the dungeon mission template (the only one I wanted this option to be available in), I added this trigger:
Code:
	  (0, 0, 0, [(key_clicked, key_m),(call_script, "script_cf_summon_allies")], []),

And in module_scripts, I added this script:
Code:
#summon allies
  ("cf_summon_allies",
   [(get_player_agent_no,":player_agent"),(agent_is_alive,":player_agent"),(agent_get_position,pos1,":player_agent"),
    (try_for_agents, ":ally"),
	  (neq,":ally",":player_agent"),
      (agent_is_alive,":ally"),
      (agent_is_ally,":ally"),
      (agent_set_position,":ally",pos1),
    (try_end),
	]),

This causes your allies in the scene to be relocated to your current position when you press the M key. I was quite pleased that I actually figured out how to do this myself, since this is the first script I wrote entirely on my own without looking at other scripts for examples. So I thought I would share it in case anyone wanted to do something similar.
Sounds ok but is it on  the map or in a fight
 
looks to be during a battle scene (or non-map scene).  Sounds good, but wouldn't it be better to just have them follow you, then mark a spot?  Doesn't the "Hold This Position" do the same thing?

Not knocking your code, its good to try things yourself, but seems like it already exists.

What interests me in this thread is you talk about just the fisrst 2 troops thing.  I was always interested in how it chooses the troops you bring into battle.  I found that I never wanted my "doctor" to enter the fray, but even if he was at the end of my list he still was in battle...
 
Beelzeboss666 said:
Sounds ok but is it on  the map or in a fight
It's in an indoor combat scene with enemies that are spawned by triggers (activated when you get within a certain distance of them) rather than when you first enter the scene.

jik said:
looks to be during a battle scene (or non-map scene).  Sounds good, but wouldn't it be better to just have them follow you, then mark a spot?  Doesn't the "Hold This Position" do the same thing?

You can have them follow you, but their pathfinding is horrible and if you move too fast they tend to get stuck on corners as they try to move directly towards you instead of seeing the wall they are trying to walk through.  :lol: There is a spiral staircase that you have to sort of slowly walk backwards in order to get them to follow you down the stairs without getting stuck. They can also get stuck at doorways if they are not directly behind you when you go through it. I haven't tried using the hold this position command, but I don't imagine it would be any less hassle than the Follow Me/Move an inch/wait for them to move to me/move another inch/etc method that is the only way to get them down the stairs.  That is also why I decided to limit it to two troops that enter with you. More than that would be a pathfinding nightmare.
 
Well, what about in sieges, where the AI will walk up stairs and stuff?  I haven't looked at it a lot, but are there waypoints you can lay using the scene editor or something?  That way you could use the "Follow me" command.

But I do have so say, congrats on creating your own script.  It feels pretty good when you can code something from scratch and see it do what you want it to.
 
Hmm...That is something I may want to look into. I always thought the troops going up seige ladders was merely a case of pathfinding, but now that you mention it, in certain areas of the dungeon allies will not try to climb stairs to get to an enemy that is, for example, on the upper level of the big room (castle courtyard prop with battlement for roof). Instead they will move towards the enemy until they are beneath them and then just run around in that spot until a closer target becomes available.
 
Yeah, I know some pathfinding is done in scenes using invisible AI barriers, but there's got to be more to it than that.  I'd really suggest studying the scenes for Custom Battle sieges; I've been up in towers and the enemy AI has correctly navigated the staircases to get to me, and I've also seen my troops navigate from the siege tower all the way around the castle to the enemy on top of their central tower.  That can't be all done by AI barriers, otherwise they'd act like you just described.  There's got to be some sort of waypoints you can place.
 
It's called an "AI Mesh" and you can edit by activating edit mode (press Ctrl+E in any scene) you also need to be in windowed mode to access the menu.
 
Thanks for mentioning that. I know the basics of scene editing, but I'd forgotten about the AI mesh. That is now going to be one of my next projects. On the bright side, the summoning code gives me a basis for a teleport spell when I get deeper into adding magic into my mod.
 
Back
Top Bottom