Jump to content
MoXiSt_Epshtein

Iron Dome Script not working

Recommended Posts

i got a script from this guy i did all he said and some how my script does not work.

 

this is the script for each sqf file 

FILE 1

init.sqf

call compile preprocessFileLineNumbers "IronDome.sqf"; if(isServer)then{ { if (_x isKindOf "B_SAM_System_02_F")then{ [_x,4000]call addToIronDome; }; } forEach vehicles; };

 

 

FILE 2

IronDome.sqf

if(isServer)then{ addToIronDome = { params["_launcher", "_detectionrange"]; _null = [_launcher, _detectionrange]spawn{ private ["_launcher","_detectionrange", "_incoming","_destination","_interceptor"]; _launcher = _this select 0; _detectionrange = _this select 1; _mag = weaponState [_launcher, [0]]; _ammo = getText (configFile ˃˃ "CfgMagazines" ˃˃ magazines _launcher select 0 ˃˃ "ammo"); while {alive _launcher}do{ _incoming = _launcher nearObjects ["RocketBase", _detectionrange]; _incoming = _incoming + (_launcher nearObjects["MissileBase", _detectionrange]); _incoming = _incoming + (_launcher nearObjects["ShellBase", _detectionrange]); if (count _incoming ˃ 0) then{ _target = selectRandom _incoming; _fromTarget = _target getDir _launcher; _dirTarget = direction _target; _destination = position _target; _launcher lookAt _destination; _tracked = _target getVariable "engaged"; if((typeOf _target != _ammo) && (_dirTarget ˂_fromTarget + 60) && (_dirTarget ˃_fromTarget - 60) && (alive _target) && (isNil "_tracked")) then { _target setVariable ["engaged", 123,true]; [_launcher, _mag select 1] call BIS_fnc_fire; sleep 0.1; _interceptor = position _launcher nearObjects [_ammo, 100] select 0; _fails = 0; while {alive _interceptor} do { _minDist = _target distance _interceptor; _velocity = (velocityModelSpace _interceptor) vectorMultiply 1.01; _velocityTrue = velocityModelSpace _interceptor; _dirHor = [_interceptor, _target] call BIS_fnc_DirTo; _interceptor setDir _dirHor; _dirVer = acos ((_target distance2D _interceptor) /(_target distance _interceptor)); [_interceptor, _dirVer, 0] call BIS_fnc_setPitchBank; _interceptor setVelocityModelSpace _velocity; sleep 0.002; if (_minDist ˂ _target distance _interceptor) then { _fails = _fails + 1; } else {_fails = 0}; if (_fails ˃ 3) then { "HelicopterExploBig" createVehicle (getPos _interceptor); deleteVehicle _interceptor; }; if (_interceptor distance _target ˂ 60) then { "HelicopterExploBig" createVehicle (getPos _interceptor); deleteVehicle _interceptor; sleep 0.5; "HelicopterExploBig" createVehicle (getPos _target); deleteVehicle _target; }; }; }; }; if (count _incoming == 0) then { sleep 0.5; }; }; }; }; };

 

 

 

 

If some one can help me with that on discord i will be very glad.

Share this post


Link to post
Share on other sites

What are you using to create your .sqf files? If the formatting in them is the same as what you pasted above, that's a problem. You can't flatten code like that and expect it to run. Your files should look something like this:

 

Spoiler

call compile preprocessFileLineNumbers "IronDome.sqf";

if (isServer) then {
    {
        if (_x isKindOf "B_SAM_System_02_F") then {
            [_x, 4000] call addToIronDome;
        };
    } forEach vehicles;
};

 

 

Spoiler

if (isServer) then {
     addToIronDome = {
        params ["_launcher", "_detectionrange"];
        _null = [_launcher, _detectionrange] spawn {
            private ["_launcher","_detectionrange","_incoming","_destination","_interceptor"];
            _launcher = _this select 0;
            _detectionrange = _this select 1;
            _mag = weaponState [_launcher, [0]];
            _ammo = getText (configFile >> "CfgMagazines" >> magazines _launcher select 0 >> "ammo");
            while {alive _launcher} do {
                _incoming = _launcher nearObjects ["RocketBase", _detectionrange];
                _incoming = _incoming + (_launcher nearObjects["MissileBase", _detectionrange]);
                _incoming = _incoming + (_launcher nearObjects["ShellBase", _detectionrange]);
                if (count _incoming > 0) then {
                    _target = selectRandom _incoming;
                    _fromTarget = _target getDir _launcher;
                    _dirTarget = direction _target;
                    _destination = position _target;
                    _launcher lookAt _destination;
                    _tracked = _target getVariable "engaged";
                    if ((typeOf _target != _ammo) && (_dirTarget < _fromTarget + 60) && (_dirTarget > _fromTarget - 60) && (alive _target) && (isNil "_tracked")) then {
                        _target setVariable ["engaged", 123,true];
                        [_launcher, _mag select 1] call BIS_fnc_fire;
                        sleep 0.1;
                        _interceptor = position _launcher nearObjects [_ammo, 100] select 0;
                        _fails = 0;
                        while {alive _interceptor} do {
                            _minDist = _target distance _interceptor;
                            _velocity = (velocityModelSpace _interceptor) vectorMultiply 1.01;
                            _velocityTrue = velocityModelSpace _interceptor;
                            _dirHor = [_interceptor, _target] call BIS_fnc_DirTo;
                            _interceptor setDir _dirHor;
                            _dirVer = acos ((_target distance2D _interceptor) / (_target distance _interceptor));
                            [_interceptor, _dirVer, 0] call BIS_fnc_setPitchBank;
                            _interceptor setVelocityModelSpace _velocity;
                            sleep 0.002;
                            if (_minDist < _target distance _interceptor) then {
                                _fails = _fails + 1;
                            }
                                else {
                                _fails = 0;
                            };
                            if (_fails > 3) then {
                                "HelicopterExploBig" createVehicle (getPos _interceptor);
                                deleteVehicle _interceptor; 
                            }; 
                            if (_interceptor distance _target < 60) then {
                                "HelicopterExploBig" createVehicle (getPos _interceptor);
                                deleteVehicle _interceptor;
                                sleep 0.5;
                                "HelicopterExploBig" createVehicle (getPos _target);
                                deleteVehicle _target;
                            };
                        };
                    };
                };
                if (count _incoming == 0) then {
                    sleep 0.5;
                };
            };
        };
    };
};

 

 

There were also a few instances where whitespace was removed and operators were prepended to variable names, breaking things rather well.

Share this post


Link to post
Share on other sites

Just tested, and it sort of works. When a launcher runs out of ammo, it throws an undefined variable error for "_interceptor," so maybe a check needs to be made for that somewhere.

Share this post


Link to post
Share on other sites

Yes, as I mentioned previously:
 

On 2/17/2020 at 6:54 PM, Harzach said:

Just tested, and it sort of works. When a launcher runs out of ammo, it throws an undefined variable error for "_interceptor," so maybe a check needs to be made for that somewhere.


Open my mission in the editor:

uBeuoLk.png

Share this post


Link to post
Share on other sites

Don't know what to tell you, other than to ask you again to share your simple repro mission. The mission I shared is working as described on my end, and throws no errors when turrets are given infinite ammo.

Share this post


Link to post
Share on other sites

maybe can you help me via teamviewer and talk with me because it is really hard for me to understand all of this and i am doing wrong, btw i launched your mission and it showing me the error

Share this post


Link to post
Share on other sites

Yes, the error will appear until you place the given code in the launcher.

I am actually in the middle of work, so I can't help other than via messages here.

Share this post


Link to post
Share on other sites

The script itself still has issues, the main one being the occasional missile fired in a seemingly random direction (though I suspect it's actually firing at [0,0,0] in lieu of a valid position).

Honestly, I'm not likely to be of much help outside this forum (and of limited help within, to be sure).

 

As far as it is capable, the script works. There is something wrong on your end. Please share your simple repro mission.

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

×