Jump to content
Guest

Setting up moving targets

Recommended Posts

Guest

Hello everyone!

 

How can I set up moving targets, like those that are on rails in various firing drills? My search so far about the topic has yielded no results.

Share this post


Link to post
Share on other sites

I can't seem to find the threads I used months ago, so I'm picking up here...

 

I found this nice little function (I can't recall who posted it) way back:

fn_MovingTargetOnce =
{
	private ["_target","_distance","_speed","_dir"];
	if (!isServer) exitWith {};

	_target = _this select 0;
	_dir = _this select 1; // direction of travel (and opposite)
	_distance = _this select 2; // how far to travel in each direction (meters)
	_speed = _this select 3; // target movement speed
	_pause = _this select 4; // seconds to pause at either end

	sleep _pause;
	for "_i" from 0 to _distance/_speed do
	{
		_target setPos
		[
			(position _target select 0) + ((sin (_dir)))*_speed,
			(position _target select 1) + ((cos (_dir)))*_speed,
			0
		];
		sleep 0.01;
	};
	sleep 0.05;
};

I'm calling it from a script like this:

[tar2,((direction tar2) + 0),10,0.1,.3] spawn fn_MovingTargetOnce;

Where tar2 is the name of the moving target.

 

This works fine in single player, but it gives odd results in MP. I'm guessing something along the lines of remoteExec needs to be used, but I'm not sure how to do it. It would be awesome if one of the better coders in the community could make a simple explanation of how to make this work on a dedicated box!

Share this post


Link to post
Share on other sites

I had really hoped to get some help with this before now :)

 

Any ideas on whether this code should be working or, if not, how to do it right?

Share this post


Link to post
Share on other sites

I had really hoped to get some help with this before now :)

 

Any ideas on whether this code should be working or, if not, how to do it right?

 

Anyone? Anyone? Buehler??

Share this post


Link to post
Share on other sites

Please describe "odd results".

 

Maybe it could help to use reveal. Read the comments of doolittle and kju there!

 

I dont know much about remoteExec but derived from example 8 u could use something like

{player reveal _target;} remoteExec ["bis_fnc_call", 0];
EDIT: I think _target is unknown for the Client so the code above wont work. but i dont know how to do that correct, sorry.

Share this post


Link to post
Share on other sites
Guest

I have an idea witch may be way more MP friendly.

I need to try it out but what about moving the targats with setVelocity ? Arma will do the whole setPos work and i'll be smoother.

Share this post


Link to post
Share on other sites

{player reveal _target;} remoteExec ["bis_fnc_call", 0];

 

Should be

 

[player,_target] remoteExec ['reveal',0];

Share this post


Link to post
Share on other sites
{player reveal _target;} remoteExec ["bis_fnc_call", 0];
Should be

[player,_target] remoteExec ['reveal',0];

That cant be the solution cause player is not known at server... it has to be a solution where _target is send from server to client and player is used client side.

Share this post


Link to post
Share on other sites

Sorry my bad, was a little bit to quick. Replace the 0 with -2 then it's alright ;)

Share this post


Link to post
Share on other sites

Sorry my bad, was a little bit to quick. Replace the 0 with -2 then it's alright ;)

Thats not the point. What I mean is locality.

I think if u execute this on server:

[player,_target] remoteExec ['reveal',-2];

then u send player and _target as params to all clients. but the server doesnt know the correct object of player. if u call player at dedi then u get just null. with the above command u send the content of _target and null to all clients. 

As I said its necessary that u send _target as param to all clients but u have to call the player command at each client itsself.

 

Its possible that i completly misunderstand remoteExec but i dont think so...

Share this post


Link to post
Share on other sites

Yeh your right, and that's actually the solution to a problem I am currently having. Seems I completely misunderstood how remoteExec works in this regard. Going to delete my post to prevent confusion. Thanks for the headsup.

Share this post


Link to post
Share on other sites

r3vo just a thing about forum integrity ... I (almost) never delete posts, cause u cant see why other people answered as they did. I use the strike function to strike out things I said wrong. Maybe u think about to do so in future. 

Share this post


Link to post
Share on other sites

r3vo just a thing about forum integrity ... I (almost) never delete posts, cause u cant see why other people answered as they did. I use the strike function to strike out things I said wrong. Maybe u think about to do so in future. 

 

I restored the org. posts.

  • Like 1

Share this post


Link to post
Share on other sites

Okay solution is found by openening a specific topic for it here:

remoteExec-topic

 

And here is KKs given solution:

[_target, {player reveal _this}] remoteExec ["call", 0];
I hope that helps to solve ur problem.

Share this post


Link to post
Share on other sites

Okay solution is found by openening a specific topic for it here:

remoteExec-topic

 

And here is KKs given solution:

[_target, {player reveal _this}] remoteExec ["call", 0];
I hope that helps to solve ur problem.

 

 

EDIT: I'm starting a new thread in Mission Editing and Scripting because I think it will help others once this is straightened out.

 

 

Thanks for the effort, all.

 

If I understand right, reveal is no help, though. That's for giving information about a uni/object to another unit. I'm talking about targets like "target_popup_moving_90deg_f" and "target_popup2_moving_f", for rifle ranges and shoot houses.

 

The "odd results" I described is that the moving target doesn't move or instead of moving smoothly it "snaps" to the end point, in MP, while it does fine in SP. That's why I am guessing that remoteExec is going to help.

 

I'm a noob with remoteExec, though. Here's a guess at what I would think it should be. Using the function defined in my first post, this:

[tar2,((direction tar2) + 0),10,0.1,.3] remoteExec ["fn_MovingTargetOnce"];

But that doesn't work in MP either.

 

Let me clarify a few things. In the init.sqf, I'm running this to initialize the function fn_MovingTargetOnce:

execVM "scripts\movTarOnce1.sqf"; // set up the function for moving targets (1x)

And, to put it all in once place, that function looks like this:

fn_MovingTargetOnce =
{
	private ["_target","_distance","_speed","_dir"];
	if (!isServer) exitWith {};

	_target = _this select 0;
	_dir = _this select 1; // direction of travel (and opposite)
	_distance = _this select 2; // how far to travel in each direction (meters)
	_speed = _this select 3; // target movement speed
	_pause = _this select 4; // seconds to pause at either end

	sleep _pause;
	for "_i" from 0 to _distance/_speed do
	{
		_target setPos
		[
			(position _target select 0) + ((sin (_dir)))*_speed,
			(position _target select 1) + ((cos (_dir)))*_speed,
			0
		];
		sleep 0.01;
	};
	sleep 0.05;
}; 

 I've been up and down in remoteExec, but I can't see a way to fix this so it works for properly for all clients. That's what the issue is that I'm looking for help with.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×