Obtaining agent ID

Users who are viewing this thread

Johnny Morphine

Knight at Arms
Real quick:

Anybody know how I can get the agent_id for a soldier using a particular weapon after ti_on_weapon_attack?

This is so the soldier using the weapon will get the experience he deserves for anybody he kills with a special effect on the weapon.
 
something similar to this came up a short while ago.  If you look at items like the pistol, you will see that it makes it's particle affect near to pos1.  No where in the code block is pos1 defined, so I would assume that when you strike with a weapon, pos1 will be the one using the weapon.  I would, in that same code block, find the closest agent to pos1 when the weapon is used.  This should give that agent.
 
Thanks, that's what I've been working on. I was wondering about the nature of pos1 (Actually using the pistol as a reference) myself and came to a similar conclusion. I've been working on how to find the nearest troop to pos1 for almost an hour now and each time I ran another try_for_agents it has led to strange results. Could you recommend any codes that can help me find that agent?

Code:
["flamethrower_axes",         "Flamethrower Axes", [("francisca",0)], itp_type_thrown |itp_merchandise|itp_primary ,itcf_throw_axe, 1 ,
  weight(4)|difficulty(0)|spd_rtng(97) | shoot_speed(30) | thrust_damage(11 ,  blunt)|max_ammo(18)|weapon_length(8),imodbit_large_bag,
  [(ti_on_weapon_attack,
  
	[(play_sound,"snd_fire_woosh"),
	(copy_position,pos3,pos1),
	(particle_system_burst, "psys_torch_fire_sparks", pos1, 15),(particle_system_burst, "psys_torch_fire", pos1, 5),
	(position_move_y, pos1,195),(position_move_z, pos1,57),(particle_system_burst, "psys_village_fire_big", pos1, 100),
	(position_move_y,pos1,-260),(position_move_z,pos1,-90),(particle_system_burst, "psys_torch_fire_sparks", pos1, 20),
	(position_move_z,pos1,-37),(particle_system_burst, "psys_torch_fire_sparks", pos1, 20),	#begin trail of sparks
	(position_move_z,pos1,-37),(particle_system_burst, "psys_torch_fire_sparks", pos1, 25),
	(position_move_z,pos1,-37),(particle_system_burst, "psys_torch_fire_sparks", pos1, 30),
	(position_move_z,pos1,-37),(particle_system_burst, "psys_torch_fire_sparks", pos1, 35),
	(position_move_z,pos1,-37),(particle_system_burst, "psys_torch_fire_sparks", pos1, 40),
	(position_move_z,pos1,-37),(particle_system_burst, "psys_torch_fire_sparks", pos1, 45),


	#identify thrower --This is the segment in progress (just imagine it's not here if you have to)
	(try_for_agents,":thrower"),
		#had been trying various different parameters here.
		(try_end),
	
	 
	(try_for_agents,":agent"),

		(agent_get_position,pos2,":agent"),
		(get_distance_between_positions,":dist",pos3,pos2),
		(lt,":dist",325),
		(neg|agent_has_item_equipped,":agent",434),					   
						   
		#delivering damage
		(agent_set_hit_points,":agent",0,0),	#change to real damage later					   
		(agent_deliver_damage_to_agent,":thrower",":agent"),
	        (try_end)]),
  
]],
]

What it does, minus the section trying to locate the thrower, is put up a "force field" around the thrower that will do damage to nearby soldiers or oncoming horses.

( yes I know "flamethrower axes" is a retarded name. It's going to be something else later once I get back to modeling. Notice it was stones before, but the animation didn't fit)
 
I would do something like:
Code:
(assign,":attacker",-1),
(try_for_agents,":agent")
    (agent_get_position,pos2,":agent"),
    (get_distance_between_positions,":dist",pos3,pos2),
    (try_begin),
        (le,":dist",80),                ##don't know the length of an arm, but should be less than 80cm
        (assign,":attacker",":agent"),
    (try_end),
(try_end),

:attacker should be the agent you are looking for.  You can double check if that agent is wielding the weapon.  I assume this is after you copy pos1 to pos3.
 
Thanks a ton. I ended up figuring that out myself after some effort. I was looking for a command like assign for awhile - the most basic of all operations, yet it took me forever to find it in the header. Once I finally figured out how Python uses loops to check for conditions I knew I'd have to trap an agent in another variable with an a=b type statement.

Surprisingly, the distance for a weapon thrown like an axe was surprisingly high - it didn't find anything at all at distances 150 or less (Perhaps troop positions are taken from their feet?). Kept returning agent ID -1 til I gradually ramped it up to 180 to get around 99% consistent results. After a dozen tests involving two hundred+ soldiers apiece 99% accuracy (one reported error and three noted falsely-credited casualties) wasn't too bad. What I'm going to do is, like you said, check to be sure the attacker is using the weapon, but I'm also going to make at least three or four near clones of the thing to further reduce the miscredited casualty rate. That, plus being sure it won't damage the attacker's allies should reduce the error rate to one 6th its current frequency, which is more acceptable than most of the buggy quests in Native (haha)

Oh, and one other interesting thing I noticed. I had to check to be sure that the attacker was human, because apparently on horseback a thrown axe is closer to your horse than you are. Not that you'd want to throw this thing from horseback anyway, since it kills your horse (and oftentimes returns an error). So I'm making it another exclusively ground weapon for my mod's update.

Thanks for all your help jik
 
You could try finding the closest agent instead of just any old agent inside a 150 radius.

 
fisheye said:
You could try finding the closest agent instead of just any old agent inside a 150 radius.

how else can you do that?  is there a special operation for that?
 
jik said:
fisheye said:
You could try finding the closest agent instead of just any old agent inside a 150 radius.

how else can you do that?  is there a special operation for that?

Nope. Mirathei's code:

        (assign,":chosen",-1),(assign,":mindist",99999),
        (try_for_agents,":agent"),
          (agent_get_position,pos2,":agent"),
          (get_distance_between_positions,":dist",pos1,pos2),
          (lt,":dist",":mindist"),
          (assign,":mindist",":dist"),
          (assign,":chosen",":agent"),
        (end_try),
 
NIce looking code. That would work, except I found that the user of a weapon is not always the closest agent to it.

However if I were to add the exclusion of equipped weaponry, etc. before the distance it may actually improve the agent search. Thanks fisheye. I'll try this out after work.
 
To jik:
    The pos1 thing is explained in header_triggers.py:
                  ti_on_weapon_attack      = -51.0 #can only be used in module_items triggers
                  # Position Register 1: Weapon Item Position

    Though having no other ideas, I would say looping all agents for this single simple effect would cause much load on player's machine.
 
Well, I thought of a compromise.
Considering how native has done to calculate weekly wage: by the end of a week count how many days player has spent in town/castle and set up weight, multiplying the current party size of player. So the process won't care if someone comes in or leaves party during the week. But it's already a good estimation.
Similarly, you can check every agent by the end of a battle, see if the agent is wielding that weapon, and use agent_get_kill_count to get number of enemies the agent has slain.
 
Back
Top Bottom