landmine script problem

Users who are viewing this thread

EmielRegis

Sergeant Knight at Arms
Hello. I trying to make simple landmine that shoots arrows in every direction when enemy agent is close enough. Everything works well apart position of "explosion".
It doesn't explode in position of mine,  but instead start's on agent who is defined as "shooter" in "add_missile" command. In whole script position of "shooter" isnt even stored in any variable so Im really confused. Someone can help me?

Code:
  (0, 0, 3, [],     #emiel
       [
         (try_for_prop_instances, ":prop", "spr_wood_a"),	
			(prop_instance_get_position, pos1, ":prop"),
			(try_for_agents, ":agent"),
								
				(agent_get_player_id, ":player", ":agent"),
				(neq, "$owner", ":player"),
				(agent_get_position, pos2, ":agent"),
				(get_distance_between_positions, ":distance", pos1, pos2),
				(lt, ":distance", 400),
				
				(position_get_distance_to_ground_level, ":distance", pos1),
				(try_begin),
					(lt, ":distance", 0),
					(position_set_z_to_ground_level, pos1),
					(position_move_z, pos1, 200),
				(try_end),		
				
				
				
				(agent_play_sound, ":agent", "snd_cow_moo"),
				
				(player_get_agent_id, ":owner", "$owner"),
				
				(try_for_range, ":unused", 1, 50),
					(copy_position, pos2, pos1),
					(store_random_in_range, ":x_offset", 1, 361),#Random Rotation of X
					(position_rotate_x, pos2, ":x_offset"),	
					(store_random_in_range, ":y_offset", 1, 361),#Random Rotation of Y
					(position_rotate_y, pos2, ":y_offset"),	
					(store_random_in_range, ":z_offset", 1, 361),#Random Rotation of Z
					(position_rotate_z, pos2, ":z_offset"),					
					(add_missile, ":owner", pos2, 1500, "itm_sniper_crossbow", 0, "itm_heavy_throwing_axes", 0),
				(try_end),	
				(particle_system_burst,"psys_dummy_smoke_big",pos1,40),
				#(init_position, pos1),
				#(prop_instance_set_position, pos1, ":prop"),
		  (try_end),
		(try_end),

Here is init trigger in module_scene_props that set's owner.

Code:
(ti_on_init_scene_prop,   
      [
    			
	   (store_trigger_param_1, ":prop"),
       (prop_instance_get_position, pos1, ":prop"),
	   (try_for_agents, ":agent"),
			(agent_get_position, pos2, ":agent"),
			(get_distance_between_positions, ":distance", pos1, pos2),
			(lt, ":distance", 50),
			(agent_get_player_id, "$owner", ":agent"),
			
			
		(try_end),		
	  
	  ]),
 
First, if you can deploy more than one mine, a single global variable "owner" isn't going to work. And, on a whole, it makes more sense to use a scene prop slot to store who deployed the mine (and that should likely be set by whatever mechanism spawns the mine in the first place, if it is a player or player-action). If you are testing with more than one mine deployed, that might be causing issues.

Additionally and possibly important, your init script will also not ensure you get the closest agent as the owner, and your explosion script doesn't check if the target is friend or foe.
 
Thanks for advices, but more important for me at the moment is why explosion isnt where it should be. Time for other fixes will be later.

edit: I checked with only  one mine, still explosion is on owner.
 
I'm not sure exactly how the add_missile operation works. Is the position you give relative to the 'shooter'/owner agent, or absolute? If it is supposed to be absolute, I'd think that assigning the owner agent appropriately would help to ensure that's not part of the problem.

A few things other things I would check, though I don't believe any of them are your problem: use different/higher range position numbers (it is very slightly possible that pos1 somehow gets used in the add_mission operation and that screws up your copy command from pos1 to pos2? so try a different pos) (edit: you could also move your copy command out of the loop--all you're doing is shifting the rotation randomly, so there really isn't a need to re-center it each iteration); don't reuse pos numbers throughout (again, I don't see a problem, but bug testing this way could help confirm) ; I'm almost positive that a local variable and global variable with the same name are fine, but you could always switch the agent to ":eek:wner_agent" to confirm there's no funny business there.
 
What exactly does not work, where does it "stop working". Like what is the last thing what happens?
+ which position doesn't get stored. You are sure the agent is active and the pos doesn't get overwrite?

OT: A land mine normally only explodes with an interruption like a nearby explosion or something which gets on it.
 
Ok, I followed advice from Caba`drin and changed "pos" index numbers to higher. It works, explosion is now in right place. Thx for help guys.

domipoppe I want something like proximity mine.
 
Ok if that was the problem then it was probably because the position got overwritten from some other script.
 
Back
Top Bottom