Jump to content
Sign in to follow this  
nuxil

Need a helping hand with my AA script.

Recommended Posts

Hi all.. im still working on my AA script trying to improve it everyday.. i found it a nice way to learn this scripting language..

The script plots helis and planes on the map.

and when clicking close to the marker. the AA veheicle is suppose to shoot at the aircraft.. dosent work if the unit is flying verry fast.. i think its Besauce i use nearestObjects and it seems to be slow as ....!

however, i gotten stuck with some issues here..

1st.. how can i use the ingame icons.. "heli plain" you see in cadet mode.

* i have installed the spectaing client script..

so can i use thouse classes ?

_icon = "KEGsPlane" ; MarkerX setMarkerTypeLocal _icon?

if so how.. besauce i tryed it and cant get that to work..

2nd.. how can i exit a camera proberly.. in my fire.sqf script. i follow the missile by camera.. as long as the enemy units dies the camera exits fine. But if the missile hits a mountan or something else.. it dosent exit.

Here are the code so far.. i use it in 3 scripts.

main script

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_Me = _this select 0;

myarray=[];

checkE=[];

publicvariable "myarray";

publicvariable "checkE";

publicvariable "pad";

_Dunit=[];

nil=[_Me] execvm "scripts\triggerarea.sqf";

sleep 3;

checkE = myarray;

_a=0; // going to use as a exit variable when the AA dies later on..

while {(_a < 1)} do {

_nrm = count myarray;

_nrc = count checkE;

// get the pos from the map

onMapSingleClick "pad =+ _pos";

if (pad select 0 > 0) then {

_px=pad select 0;

_py=pad select 1;

// This is real SLOW.. need a fixup

_only = nearestObjects [[_px,_py,100],["Air"], 200];

_now = _only select 0;

nil=[_now,_Me] execvm "scripts\fire.sqf";

pad=[0,0,0];

};

sleep 0.5;

if (_nrm > _nrc) then { checkE = myarray;};

if ((_nrm < _nrc) || (_nrm == 0)) then {

_index=0;

for [{_i=0},{_i < _nrc},{_i=_i+1}] do {

_unit = checkE select _i;

if (!alive _unit) then {

_Dunit set [_index, _unit];

_index = _index +1;

_Dunit resize _index;

_Ename = format["%1", _unit];

};

};

{_Ename = format["%1", _x]; deletemarker _Ename;} foreach _Dunit;

checkE = myarray;

};

if ((_nrm == _nrc) && (_nrm != 0)) then {

{

_unit = _x;

_Ename = format["%1", _x];

createMarker [_Ename, (position _x)];

//_Ename setMarkerTypeLocal _icon;

_Ename setMarkerType "Dot";

_Ename setMarkerDir (getdir _x);

_Ename setMarkerText (format["%1 sp:%2",(typeOf _x),(round speed _x)]);

_Ename setMarkerPos (position _x);

} foreach checkE;

};

sleep 0.3;

};

triggerarea.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_Me = (_this select 0);

while {true} do {

_myarray=[];

WestTriggerOne = createTrigger ["EmptyDetector", position _Me];

WestTriggerOne setTriggerActivation ["EAST", "PRESENT", true];

WestTriggerOne setTriggerType "NONE";

WestTriggerOne setTriggerArea [50000, 50000, 0, false ];

//update the publicalvariable each sec

sleep 1;

_whohere = list WestTriggerOne;

_nr = {alive _x} count (_whohere);

_index=0;

for [{_a=0},{_a < _nr },{_a=_a+1}] do {

_unit = _whohere select _a;

if ((_unit isKindOf "AIR")) then {

_myarray set [_index, _unit];

_index = _index +1;

_myarray resize _index;

};

};

myarray = +_myarray;

};

fire.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_unit = _this select 0;

_AAvehicle = _this select 1;

_Ename = name _unit;

_missil = "M_Ch29_AT" createVehicle [0,0,0];

_missil setpos [(getpos _AAvehicle select 0),(getpos _AAvehicle select 1),(getpos _AAvehicle select 2)+ 3.5];

sleep 0.1;

_camera = "camera" camcreate (position _missil);

while {(getdammage _unit < 0.9) && (getdammage _missil < 1)} do {

_vel = velocity _missil;

_dir = direction _missil;

_speed = 20;

_missil setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+(cos _dir*_speed),(_vel select 2)];

_Pm = getpos _missil;

_Pu = getpos _unit;

_Pmu = [((_Pu select 0) - (_Pm select 0)), ((_Pu select 1) - (_Pm select 1)),((_Pu select 2) - (_Pm select 2))];

_missil setVectorUp _Pmu;

_missil setVectorDir _Pmu;

if ((_unit distance _missil) <= 14) then {

_missil setpos [(getpos _unit select 0),(getpos _unit select 1),((getpos _unit select 2)+1.6)];

};

camUseNVG set;

_camera cameraeffect ["internal", "FRONT"];

_camera camsettarget _missil;

_camera camPrepareFOV 1.100;

_camera camsetrelpos [0,-10,5];

_camera camcommit 0;

sleep 0.01;

}; //end the while

_camera cameraEffect ["Terminate", "FRONT"];

camDestroy _camera;

im no expert with this camera thingy so i could use some help.

now before you start arguing about using publicvariables as array.. try this test http://pastebin.ca/412031

if you wish to test this script.

place a stryker on the map.. and in its init feald put. nil= [this] execvm "main.sqf"

script lacks functions and is verry unfinished.

allenp0.th.jpg

Share this post


Link to post
Share on other sites

I hope u understand that i'm not trying to correct you, only my own 'way of think' about that script and the way you are thinking it.

As you noticed, you have a (health player AND health missil) problem. health player is not giving you problems. Then... hum... health missil yeps, right? I think, the problem of the missing missil is that condition.

"nearestOb..." and 'distance' commands is not slow by itself. ArmA is not being 'reduced' in terms of performance.

I think at reverse way. ArmA is giving a reduced attention to that commands, because that kind of commands, i suppose, needing a lot of checks, making ArmA, really reduce its performance when this commands is being 'launched'. So, ArmA is preventing his lacks of performance not paying all the possible attention in that 'level' of commands. Just only i suppose it. Then, i can understand why is not useful some commands of "nearestOb's" because it seems that ArmA is 'blocking' it own attention in these commands, till not being the radius 50 or less meters.

Another idea about your arrays inside the nearestObjects command.

I think that, if you 'giving to ArmA' arrays with not 'exact' values in nearestObjects, you will cause ArmA (and not your script) will spend more time to collect the info you wanting.

Probably, the first array declared in nearestObjects, its nearly impossible to be 'changed', but... ["Air"]... i'm thinking really if you declare all kind of vehicles you wanting to be checked... it will help to avoid 'more reducing performance to ArmA'.

["Air"], obviously is shorter than all air vehicles being declared one by one. Yep. But if you declare it all, ArmA will not search in its 'classes' which vehicles meeting the criteria "Air".

I think it last is only "probably". It's an idea. Not a fact.

Remember: parachute is "Air" too... and i'm really thinking, you don't want to launch missil/missils to parachutes... as an example.

And remember too... there is 4 or 5 parachutes, so, as 5 air vehicles that you dont want ArmA checking it.

Now we are 'reducing' things to be checked by ArmA... so... maybe, reducing that 'slow' issue. Reducing, but not doing it still enough fast. Ok.

I think that the map in ArmA has not one of the highest priorities to be checked by ArmA while playing. In MP, i noticed a lot of times (yeah a looooot) that the map is 'ploting' the 'icons' a little bit delayed.

Well, not all. As example, when you playing a mission, your own coordinates will be more accurate than others one. But only in your Map, not in the rest of the players. I think that this last is because 'your ArmA' is not sending you your own coordinates by Internet. More or less, is like your coordinates being sent by a better bandwidth-performance machine... your own computer. Maybe this is called 'locality'.

And not only its a matter of accurate, refreshing time too. Your ArmA can refresh your own 'icon' in your map much more faster than any other 'icon' from other computers... because (sigh! ) all computers are being connected as a lot of 'brains', but all computers is not forming one brain.

So, as we can't put a turbo in all computers playing ArmA in the same server... at least we must to reduce all delays that the scripts, or just scripts+ArmA, is adding.

Don't know if the nearestObject is the 'fastest' way to check what you wanting to check. But at least, if you can't think in another way more, try to reduce at maximum the work that ArmA has to do to give you the results that you are waiting for.

So, please, test it if you want, try to declare it all vehicles that really you wanting to check.

And too, try to make the first array declared inside nearestObject, more 'lessConsumingCpuUsage' as you can think.

Well, i have no enough skill to understand 100% your .sqf function "Fire".

But i'll try anyway to think about this ideas.

- _unit is the enemy inside the air vehicle.

_ if _unit is the air vehicle, i suppose "name _unit" will give you an error if not named.

Maybe, the script of camera of missil, can't exit, because:

- When the missil explodes against a mountain, the missil will dissapear in terms of 'object'. So is too complicated to check his 'damage' because now it doesnt exist. And, if your group of scripts can't detect that (getdammage _missil <1) when the missil is 'exploding-but-still-alive' (just like reducing 99% the speed of the 'movie'wink_o.gif... then is like the missil was stolen from your computer hehehe. So i can understand if i'm not wrong, why when the missil is hitting a mountain, never the function will exit.

If still i'm not wrong at this point...

How can we fix 'the crashing missil' event?.

Remember too, that if the missil is not hitting a 'thing'... like the missil aiming the heaven... it crashes past certain time? have the missil, fuel?

Maybe you can test the nearest surface of the missil to exit just a few seconds after the missil crashed, + if the missil is aiming heaven (vectorDir? vectorUp?)

If you doing something like:

 - More or less like a eclypse concept. Always, before you launching the missil, you have in the space, the AA vehicle, and in another place, the 'enemy' air vehicle.

It means easily graphically explained:

       AA   -   Enemy Air vehicle (EAV)

 - Now, when you are launching the missil, geographically, the missil is 'flying' between the AA vehicle and the 'enemy' air vehicle.

       AA - Missil - EAV

 - Then, if the missil misses...

       AA - EAV - Missil

and/or even:

       EAV - AA - Missil (because the speed of the chopper/plane)

I don't know if the missil you launching is always 'flying' in a straight line or even if your missil can 'turn' (correct his direction).

Obviously, AA - Missil - EAV is not a perfect straight line, in terms of direction, in any of its combinations.

So, my idea to you, is: if you can 'catch' that moment when the missil is missing its target... you can handle, the exit of the script when you want (maybe making it a little bit of delay to ensure you will not exit the camera-missil script till a certain seconds or meters away from the target).

I hope this method, not too complicated to script.

Well, another idea. Is too tricky:

As i can't to understand all the piece of script when you are checking that 200 meters of radius... i can say you this:

- if you seeing 'delays' at the time you need an air vehicle (probably the main problem is a plane, its speed, huh?) being 'detected' by the nearestObject command... why not increase the radius?

As example: the time that is spending ArmA to found your 'enemy air vehicles' in the given radius by nearestObjects

is 'X' when a plane is entering that radius at 400km/h, as example. Then if the same plane is entering tha 'radius' at 500km/h, X will be... ? i think yep, is greater than in 400km/h. Because at 500km/h, the plane is changing the value of the coordinates faster than in 400km/h. So nearestObjects will receive from internal code of ArmA a slower-in-time solution (array with 'trustable' info). I think this issue i noticed when i was testing distance-nearestOb's commands with choppers and planes in one of my rearming script-tests.

Probably, if the enemy air vehicle is a chopper, entering that 200 meters radius at a speed of 60km/h... i think that ArmA will give a real info faster than planes at 300km/h as example.

Because the chopper is changing his coordinates slower.

Or at least ArmA can 'pursuit' that chopper coordinates inside the radius, faster.

So, this is my stupid-tricky solution. Increase the radius if you are trying to detect planes and choppers. You will have to reach your 'magic number' where is more or less balanced the time that nearestObjects is giving you the 'target' to be shot.

Increasing the radius... the chopper will be detected before 200 meters... but planes ... planes... hum... planes... speed... delay... i think it can work. Yep, not perfect, but maybe can help you. Try 250 meters, or 300. Just test it, if you want.

Catching the concept?

smile_o.gif

I will give you a solution about your problem with the missil in 15 minutes.

EDITED THIS A LOT. Maybe must check if you reading while me editing it. Sry bout this extralarge post. =(

Share this post


Link to post
Share on other sites

the problem with nearestobjects in the way you want to use it is , the speed of air type vehicles.

you have to remember that when nearest objects searches say 200meters , it starts at 0 meters does a 360 degrees sweep at _x meter inervals . lets say.001 meters until it reaches the param you have set . so it will have done nearly (ok give me some artistic lisence here), 30 - 40 thousand sweeps of 360 degrees before it reaches a plane at the end of 200 meters , in other words it dosent

just ingnore space ,it actually searches space .

how i know this , well when i blew walls up in arma in early days

i would use a hit evenbthandler on a "hitbrick" in a wall

and it would then say delete nearestobjects ["hitbrick,["brick"],random_x] and huess waht in high settings and big value of _x you could see the circles being drawn as it searched and deleted . wink_o.gif

Share this post


Link to post
Share on other sites

Missil Problem:

i think that the _missil variable has the fault.

What do you have inside the variable _missil when the missil explodes and then, this 'object' is not an 'object' now?

Checking his damage is not the solution.

I'm supposing:

- The variable _missil is 'directly' the 'object' missil.

- Maybe you must check if is alive the missil or not, not its damage.

- If the missil is not alive, is because 'it died', crashed, exploded, etc or even if launched towards the heaven... 'crashed' in a mathematical form by ArmA... because, surely, ArmA has a limit of altitude... and ArmA doesn't want to track internally all the time, if the missil is at 30000 meters altitude etc. IT MAY HAVE A LIMIT.

I encourage you to think a little more time in the condition of (damage _unit with damage _misil).

Do 'Camera' While... hum... hum... banghead.gif  hum... hum...  banghead.gif hum... hum...

(getDammage _unit) AND (alive _missil)

if _missil = the object missil exactly.

Maybe you have to add the condition (alive _unit) to that line.

Well, this is my final solution:

((getDammage _unit < 0.9) AND (getDammage _missil < 1) AND (alive _unit) AND (alive _missil))

In the moment that only one condition is not true... camera going to the deepest of the hells. Right?

Still i'm thinking that if the variable _missil is not being checked with more refreshing... when the object missil is 'died'... still the variable is having his 'memory' but not the object missil.

Share this post


Link to post
Share on other sites

yea..

while {(getdammage _unit < 0.9) && (getdammage _missil < 1) && (alive _unit) && (alive _missil)} do

worked fine. now the camera exits. smile_o.gif i also managed to get the icons thats in the spectating cilent addon to work on the map biggrin_o.gif

Share this post


Link to post
Share on other sites
Quote[/b] ]i follow   the missile by camera.. as long as the enemy units dies the camera exits fine. But if the missile hits a mountan or something else

Still i'm thinking that the solution was in your mind.

You wrote it first.

Cheers!!!    wink_o.gif

Note: i think that is more powerful to think only with images inside the brain than to think with words, maths, etc. Just 'be' a camera. If you can analyze what you seeing in that camera... but without words...  

Freeze your camera, rotate the angle of the objects, mentally, more or less like some scenes in 'Matrix'. That movie, in some scenes, is a good 'graphical' and 'mental' comparison.

Still i don't like Matrix.

Be a camera... 'Lynx Eye' , has this concept inside.

Gooooood Nights mate

Share this post


Link to post
Share on other sites

Nuxil,

I hope you dont mind, but something has been bothering me about this part of your script:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Pm = getpos _missil;

_Pu = getpos _unit;

_Pmu = [((_Pu select 0) - (_Pm select 0)), ((_Pu select 1) - (_Pm select 1)),((_Pu select 2) - (_Pm select 2))];

_missil setVectorUp _Pmu;

_missil setVectorDir _Pmu;

Mainly setVectorUp, as it only accepts unit vectors i.e numbers from 0..1.

Also according to the wiki:

Quote[/b] ]Syntax: object setVectorUp [x, z, y]

Notice how for this command the positions of the Z and Y vectors have been swaped round. This isn't a typo, it works that way in game to.

So I tried creating a simplified version of the code to test it out. Instead of creating a missile, I've created a Spowith Camel. It's easier to check it's pitch bank if you use an aircraft.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Pos=GetPos Player;

_Dir=GetDir Player;

_XPos=(_Pos Select 0)+((Sin _Dir)*10);

_YPos=(_Pos Select 1)+((Cos _Dir)*10);

_missil="Camel" createVehicle [_XPos,_YPos,10];

_missil SetPos [_XPos,_YPos,10];

WaitUntil

     {

     _missil SetPos [_XPos,_YPos,10];

     

     _Pm = getpos _missil;

     _Pu = getpos Player;

     _Pmu = [((_Pu select 0) - (_Pm select 0)), ((_Pu select 1) - (_Pm select 1)),((_Pu select 2) - (_Pm select 2))];

     _missil setVectorUp _Pmu;

     _missil setVectorDir _Pmu;

     };

If you run that script in the editor you see it does not work exactly as expected.

Change the code to this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">WaitUntil

     {

     _missil SetPos [_XPos,_YPos,10];

     

     _Pm = getpos _missil;

     _Pu = getpos Player;

     _Pmu = [((_Pu select 0) - (_Pm select 0)), ((_Pu select 1) - (_Pm select 1)),((_Pu select 2) - (_Pm select 2))];

     _missil setVectorDir _Pmu;

     };

Now the aircraft does point directly at the player, so setVectorDir on it's own will work that way. But setVectorUp will skew the object. I tried converting the vectors to unit vectors and swapping the Z and Y vectors around. But I still cant get setVectorUp to point directly at the player?

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
Sign in to follow this  

×