Editors Depot - Mission Editing and Scripting > Arma2 - Editing/Scripting Multiplayer

Moving Object Script Network issues (Pop up target range)

(1/1)

Brone:
Hello, I have been trying to add moveable objects, in my case Pop up targets to my shooting range. I came across a script which moved objects, I modified it to let the object move from left to right back left and loop as many times as I want. This has been working wonderful in the editor or until one of my friends joins my multiplayer hosted game. Once someone joins my game the targets start flickering and become very jerky. Unfortunately I am not much of a scripter and I am hoping someone can help me get this script working in Multiplayer. Here are the instructions on how I have been using the script.

To use this script you put an object down in the Arma 2 editor that you want to move (in my case a pop up target). Then you add two Markers, one Marker where the object will start and a second where the object will move to before it proceeds back to the first marker.

Heres the Inizialization code used in the Arma 2 editor in the selected object.

--- Code: ---nul = [this,"StartingMarker","EndMarker",0.04,0.02,1000] execVM "move_obj.sqf";

StartingMarker = the name of the first Marker and where the object will start
EndMarker = the name of the second Marker where the object will move to before heading back to the Starting Marker
0.04 = the speed of the object
.02 = the sleep delay in the scripts For loop
1000 = the number of times the object will move side to side
--- End code ---

Here is the script I modified to allow moveable objects. I named it "move_obj.sqf"

--- Code: ---private ["_obj","_mkr1","_mkr2","_step","_timg","_loop","_x ","_y","_i","_dis","_dir"];

_obj = _this select 0;
_mkr1 = _this select 1;
_mkr2 = _this select 2;
_step = _this select 3;
_timg = _this select 4;
_loop = _this select 5;

_obj setPos getMarkerPos _mkr1; //sets the object to the first marker position

for "_s" from 1 to _loop do {

_x = ((getMarkerPos _mkr2 select 0)-(getMarkerPos _mkr1 select 0));
_y = ((getMarkerPos _mkr2 select 1)-(getMarkerPos _mkr1 select 1));

//trig
_dir = _x atan2 _y;
if (_dir < 0) then {_dir = _dir+360}; //direction from mkr1 to mkr2

//pythagoras
_dis = sqrt(_x^2+_y^2); //distance from mkr1 to mkr2

for [{_i=0},{_i<_dis},{_i=_i+_step}] do {
_x = sin(_dir)*_i;
_y = cos(_dir)*_i;
_obj setPos [(getMarkerPos _mkr1 select 0) + _x,(getMarkerPos _mkr1 select 1) + _y,0];
sleep _timg;
};

_x = ((getMarkerPos _mkr1 select 0)-(getMarkerPos _mkr2 select 0));
_y = ((getMarkerPos _mkr1 select 1)-(getMarkerPos _mkr2 select 1));

//trig
_dir = _x atan2 _y;
if (_dir < 0) then {_dir = _dir+360}; //direction from mkr1 to mkr2

//pythagoras
_dis = sqrt(_x^2+_y^2); //distance from mkr1 to mkr2


for [{_i=0},{_i<_dis},{_i=_i+_step}] do {
_x = sin(_dir)*_i;
_y = cos(_dir)*_i;
_obj setPos [(getMarkerPos _mkr2 select 0) + _x,(getMarkerPos _mkr2 select 1) + _y,0];
sleep _timg;
};
};
--- End code ---

If anyone can help me this will be GREATLY appreciated.

Navigation

[0] Message Index

Go to full version