Making a troop die when his mount falls

Users who are viewing this thread

Zarthas

Knight at Arms
I've been messing around with creating aggressive animals in Neolithic Mod.  My current project is to get an invisible, invincible rider, who dies when his mount dies.  However, this is my first time writing any real code in the Module System, and I'm getting some funny results.  For some reason, the mounted troops will just stand where they spawn, but it might be because he doesn't have a weapon.  If you kill his mount, he simply gets up, and attempts to punch you to death.

Code:
animal_death = (
     1, 0, 0, [],
       [
                            (try_for_agents,":rider"),     
                                (agent_is_human,":rider"),
                                (agent_get_horse,":horse",":rider"),
                                (try_begin),
                                (agent_is_alive,":horse"),
                                (else_try),
                                (agent_set_hit_points,":rider",0,0),
                                (try_end),
                            (try_end),])

I meant for the code to check all the agents, see if its a human, get the horse he's on, see if its alive, and if its not, set the rider's hp to 0.
Just occurred to me that this might not be working since the mount is dead, so he's technically not mounted.

This bit of code is called just before common_battle_check_inventory in the "lead charge" mission type.

I don't really understand the trigger structure very well, so could someone give me a few pointers?
 
No you might be doing it right.  But for some reason when you set an agents hit points to 0 he needs to be hit one more time to be killed.  But fortunately there is an operation that arbitrarily does damage to an agent.
(agent_deliver_damage_to_agent,":rider",":rider"),  It only works when the agent delivers damage to himself or the player_agent delivers the damage.  This operation also tends to autokill which would work for your purposes.
 
                              (try_begin),
                                (agent_is_alive,":horse"),
                                (else_try),
                                (agent_set_hit_points,":rider",0,0),
                                (try_end),
I'm very new to this myself, but should it be:

            (neg|agent_is_alive, ":horse"),

Instead of that whole block, or is that just the same thing?

EDIT:
                     
                                (try_begin),
                                (neg|agent_is_alive,":horse"),
                                (agent_set_hit_points,":rider",0,0),
                                (try_end),
EDIT 2: I was wondering about a code for this a while ago, when I was thinking about centaurs.
EDIT 3: And maybe you should change  1, 0, 0, [],  to  0, 0, 0, [], so it is always checking?
 
Thanks for the tip Berserker, And wookie, I'm going to try out both of your suggestions and see what happens.  It certainly looks nicer your way.

edit: Oh, hah.  I ran into another problem.  This code checks every agent, and even if they don't have a horse to begin with, it auto-kills them.  Going to change it to work from the horse's point of view, brb.

Code:
animal_death = (
     1, 0, 0, [],
       [
                
                            (try_for_agents,":horse"),     
                                (neg|agent_is_human,":horse"),
                                (agent_get_rider,":rider",":horse"),
                                (try_begin),
                                (neg|agent_is_alive,":horse"),
                                (agent_set_hit_points,":rider",0,0),
                                (agent_deliver_damage_to_agent,":rider",":rider"),
                                (try_end),
                            (try_end),])

edit: Hm, this just gets me a big error text where you normally would see the damage you're dealing and what not.  The game doesn't crash, but the guy doesn't die either.
 
Then they die. They die of death.

Or rather, I think he was planning to get wild animals (thus with invisible riders.)
 
lol.  At the moment, yes, they do die of death.  I was planning to make a new tf, tf_beast, that the code would check for before killing the agent.  Troops with tf_beast will never dismount, if I get it working :razz:

Haven't had the time to work any more on this, but I'd like to clarify a bit.  The battle will run normally until you kill the mount of one of the riders, then you get that error.
 
It seems like you are going about this the wrong way?  You are getting the rider of the horse, but if there is a rider then its fine, and if there isn't a rider then it would be -1 so you wouldn't know what troop to kill...  I'd probably add something like the following into the mission template.

Code:
common_kill_beast_rider = (
	 5, 0, 0,            #check every 5 seconds
      [
        (try_for_agents, ":cur_agent"),
            (agent_is_alive, ":cur_agent"),  	     # so we don't try dead agents
            (agent_is_human,":cur_agent"),	     #agent is a human
            (agent_get_troop_id, ":cur_agent_troop", ":cur_agent"),
            (eq, ":cur_agent_troop", "trp_beast_rider"),
            (agent_get_horse,":agent_horse",":cur_agent"),
            (le, "agent_horse", 0),           # agent doesn't have a horse
            (agent_set_hit_points,":cur_agent",0,0),
            (agent_deliver_damage_to_agent,":cur_agent",":cur_agent"),
        (try_end),
     ])

Note - I haven't tested this code.  I also posted some other examples below, because I had a script in SWC that plays an animation for un-mounted horses and also ones that kills players when they are underwater.  So you could potentially check if they were off the ground, but that seems more complicated then its worth...

Code:
common_speeder_trigger_1 = (
	 # SW - script to stop riderless horses (ie. speeders) from moving (code help from KON_Air)
	 5, 0, 0,	#length of stationary animation
      [
	  (try_for_agents, ":cur_agent"),
	   (agent_is_alive, ":cur_agent"),	#so we don't try dead agents
	    (neg|agent_is_human,":cur_agent"),	#agent is a horse
	     (agent_get_rider,":cur_rider", ":cur_agent"),
		  (try_begin),
	        (lt, ":cur_rider", 0),	#horse does not have a rider
		    (agent_play_sound,":cur_agent","snd_speeder_noise_idle"),
		    (agent_set_animation, ":cur_agent", "anim_speeder_stationary"),	#so the horse doesn't move, must include module_animations at the top
		  (try_end),
	  (try_end),
      ], [])

Code:
sw_common_battle_kill_underwater = (
	# code concept from http://forums.taleworlds.com/index.php/topic,68852.0.html and http://forums.taleworlds.com/index.php/topic,58880.15.html
  5, 0, 1, [],	#one second refresh to allow sound time to complete
	[	
		(try_for_agents,":agent"),
			(agent_is_alive,":agent"),
			(agent_get_position,pos1,":agent"),
			(position_get_z, ":pos_z", pos1),
			#(assign, reg1, ":pos_z"), #debug only
			#(display_message, "@agent z-position is {reg1}"),	#debug only
			(try_begin),
				(le, ":pos_z",-150),	#agent is about 6ft underwater
				(store_agent_hit_points,":hp",":agent",1),
				#(val_sub,":hp",7),
				(val_sub,":hp",10),
				(try_begin),
					(le, ":hp", 0),
					(agent_set_hit_points,":agent",0,0),
				(else_try),
					(agent_set_hit_points,":agent",":hp",1),
				(try_end),				
				#(play_sound,"snd_man_grunt"),
				(agent_play_sound,":agent","snd_man_grunt"),
				(agent_deliver_damage_to_agent,":agent",":agent"), 
			(try_end),
		(try_end),
	])
 
Any armor becomes invisible when there are problems with mesh.
Beasts should be on enemy side only. Else it would be strange if they listen to any of your orders, like follow, hold etc
 
You could write a script to change any beast troops to be an ally.  That way they would run around doing their own thing as a beast should.  And you wouldn't be able to tell them to dismount then.
 
Berserker Pride said:
You could write a script to change any beast troops to be an ally.  That way they would run around doing their own thing as a beast should.  And you wouldn't be able to tell them to dismount then.

Can't the player occasionally order allies? If that is the case, that wouldn't work.
 
Yes, the player can order allies from same faction if the player is a marshal. So may be before the battle, the beast from main party should be scripted tobe removed and spawned as a friendly faction too.
Alternative way: beast can't be recruited to main party, but make beast parties like cattle parties. The difference, the beast parties owned by player should follow the player like friendly hero parties or escorted merchant.
 
There are operations to make troops of a certain type change team.  Simply change all beast style troops to team ally and bingo you can't control them.  You will have to check the template to see which team is ally.
 
there is one problem :/
they will be aiming for the rider, which means the damage wont go to the animal unless you miss the rider himself :/
so we need to find a solution to it... making animals double times the size of the people...(it will be funner attacking them) and every hit will go to the animal and not to the rider... and you can set the amount of health lost from falling from a horse like 100 times stronger so it kills anything riding it... (because if you are riding or just standing and your steed dies... you fall instead of dismount :grin:)
but ofcourse... this is an idea which might work unless the speed of falling off a horse has to do with normal jumping too ( that would make you die whenever you jump :/)
 
Back
Top Bottom