#### Start of On-hit trigger test
(ti_on_agent_hit, 0, 0, [],
[
#First store the involved agents and damage .
(store_trigger_param_1, ":victim"),
(store_trigger_param_2, ":inflictor"),
(store_trigger_param_3, ":damage"),
#Assign to registers for output.
(assign,reg1,":victim"),
(assign,reg2,":inflictor"),
(assign,reg3,":damage"),
(display_message, "@{reg1} was hit by {reg2} for {reg3} damage.",0x6495ed),
#Following stuff only on human targets.
(agent_is_human,":victim"),
(try_begin),
#store hit position for output
(position_get_x, ":xposition", pos0),
(assign,reg4,":xposition"),
(position_get_y, ":yposition", pos0),
(assign,reg5,":yposition"),
(position_get_z, ":zposition", pos0),
(assign,reg6,":zposition"),
#(display_message, "@Item {reg0} hit at absolute positions {reg4}x | {reg5}y | {reg6}z.",0xFF95ed),
#Calculate relative position of the blow on victim and put it on screen.
(agent_get_position, pos1,":victim"),
(position_get_x, ":xposition_victim", pos1),
(val_sub,":xposition",":xposition_victim"),
(assign,reg4,":xposition"),
(position_get_y, ":yposition_victim", pos1),
(val_sub,":yposition",":yposition_victim"),
(assign,reg5,":yposition"),
(position_get_z, ":zposition_victim", pos1),
(val_sub,":zposition",":zposition_victim"),
(assign,reg6,":zposition"),
(display_message, "@Item {reg0} hit at relative positions {reg4}x | {reg5}y | {reg6}z.",0x1015ed),
#Show absolute rotation of the blow.
(position_get_rotation_around_x, ":xrotation", pos0),
(assign,reg4,":xrotation"),
(position_get_rotation_around_y, ":yrotation", pos0),
(assign,reg5,":yrotation"),
(position_get_rotation_around_z, ":zrotation", pos0),
(assign,reg6,":zrotation"),
#(display_message, "@Absolute direction of the blow is {reg4}x | {reg5}y | {reg6}z.",0x00FFed),
#Calculate relative rotation of the blow compared with victim.
(agent_get_position, pos1,":victim"),
(position_get_rotation_around_x, ":xrotation_victim", pos1),
(val_sub,":xrotation",":xrotation_victim"),
(assign,reg4,":xrotation"),
(position_get_rotation_around_y, ":yrotation_victim", pos1),
(val_sub,":yrotation",":yrotation_victim"),
(assign,reg5,":yrotation"),
(position_get_rotation_around_z, ":zrotation_victim", pos1),
(val_sub,":zrotation",":zrotation_victim"),
(assign,reg6,":zrotation"),
(display_message, "@Relative direction of the blow is {reg4}x | {reg5}y | {reg6}z.",0x0055ed),
#Heal victim.
(agent_set_hit_points,":victim",100 ,1),
#Slow victim down
#(agent_set_speed_limit,":victim",0.01),
#Guess if head was hit.
(try_begin),
(gt, ":zposition", 150),
(try_begin),
(display_message, "@The head was hit!",0x3315ed),
#(agent_set_look_target_agent, ":victim", ":inflictor"),
(try_end),
(try_end),
#Guess if front was hit
(try_begin),
(is_between,":zrotation",90,180),
(try_begin),
(display_message, "@The front was hit.",0x3344ed),
(try_end),
(try_end),
(try_end),
]),
#### End of On-hit trigger test