Jump to content
Sign in to follow this  
mr_shadow

Tracer Line script

Recommended Posts

Hello guys, I'm trying to make a script which will basically dewlete the bullet and draw a green tracer line to the cursortarget.

 

So far as I know, all the scripts were based on the bullet tracing, and I was wondering if it is possible just to draw line for 5-7 sec which will be created about 100m distance or something like that.

 

Any help please?

Share this post


Link to post
Share on other sites

Hello guys, I'm trying to make a script which will basically dewlete the bullet and draw a green tracer line to the cursortarget.

 

So far as I know, all the scripts were based on the bullet tracing, and I was wondering if it is possible just to draw line for 5-7 sec which will be created about 100m distance or something like that.

 

Any help please?

 

its possible. drawLine3D

Share this post


Link to post
Share on other sites

Let me show I want to make, its incorrect code:
 
init.sqf

[] execVM 'scripts\tracer.sqf';



Player addEventhandler ["Fired", {  
     _bullet = (_this select 6);   
_target = cursorTarget; 
dist_1=player distance _target;    
     if (primaryweapon player== "impulseg") then     
  {   
  deletevehicle _bullet; 
 
if (_target isKindOf "Man") and (if (dist_1 < 50))then {

[player, [1,0,0,1], 3, 2, nil, 3] call hyp_fnc_traceFire; 
_target setdamage 1;
}; 
 };  
 
}];  

 
tracer.sqf

/*
General init for the tracer function
*/
hyp_var_tracer_tracedUnits = [];
 
addMissionEventHandler ["Draw3D", {
    {
        private["_unit"];
        _unit = _x;
        {
            private["_positions","_color","_muzzleVelocity"];
            _positions = _unit getVariable [format["hyp_var_tracer_projectile_%1", _x], []];
            _color     = _unit getVariable ["hyp_var_tracer_color", [1,0,0,1]];
            _muzzleVelocity = _positions select 0 select 1;
                       
            for "_i" from 0 to (count _positions) - 2 do {

                //Variant of Dslyecxi's awesome color tracking modification
                if (_unit getVariable ["hyp_var_tracer_trackVel", false]) then {
                    private["_velocity"];
                    _velocity = (_positions select _i) select 1;
                    _color = switch true do {
                        case (_velocity / _muzzleVelocity >= .75) : {[1,0,0,1]};
                        case (_velocity / _muzzleVelocity >= .50) : {[.5,.5,0,1]};
                        case (_velocity / _muzzleVelocity >= .25) : {[0,1,0,1]};
                        case (_velocity / _muzzleVelocity >= .10) : {[0,0,1,1]};
                        case (_velocity / _muzzleVelocity >= 0.0) : {[1,1,1,1]};
                        default {_color};
                    };
                };
                 if((player getVariable "scout") == 1) then
{               
                drawLine3D [_positions select _i select 0, _positions select (_i + 1) select 0, _color];
           }; };
        } forEach ( _unit getVariable["hyp_var_tracer_activeIndexes", []] );
    } forEach hyp_var_tracer_tracedUnits;
}];
 
//Adding of the option to manually clear lines.  If you don't want the addaction, simply remove these 4 lines

 
/*
Syntax:
    [_unit, _color, _lifetime, _interval, _maxDistance, _maxDuration, _trackVel] call hyp_fnc_traceFire;
Params:
    _unit:        Either a vehicle or unit.  (Default player)
    _color:       Color array for the lines. (Default [1,0,0,1])
    _lifetime:    Duration after firing to keep the line drawn.  (Default -1, for indefinite duration)
    _interval:    Number of frames to wait between recording locations (Default 0 for record on every frame)
    _maxDistance: Maximum Distance from origin point to record positions (Default -1, for no max)
    _maxDuration: Maximum Duration from time of firing to record posiitons (Default -1, for no max)
    _trackVel:    If true, _color is overriden by the a color indicative of velocity at that moment.  Thanks to Dslyecxi for this parameter! (Default false)
Return Value:
    Scalar: The ID of the "fired" EventHandler that was added.
*/
 
hyp_fnc_traceFire = {
    private["_this","_unit","_color","_lifetime","_interval","_maxDistance","_maxDuration","_eventHandle"];
    _unit        = [_this, 0, player, [objNull]] call BIS_fnc_param;
    _color       = [_this, 1, [1,0,0,1], [[]], [4]] call BIS_fnc_param;
    _lifetime    = [_this, 2, -1, [0]] call BIS_fnc_param;
    _interval    = [_this, 3, 0, [0]] call BIS_fnc_param;
    _maxDistance = [_this, 4, -1, [0]] call BIS_fnc_param;
    _maxDuration = [_this, 5, -1, [0]] call BIS_fnc_param;
    _trackVel    = [_this, 6, false, [false]] call BIS_fnc_param;
 
    _unit setVariable ["hyp_var_tracer_color", _color];
    _unit setVariable ["hyp_var_tracer_lifetime", _lifetime];
    _unit setVariable ["hyp_var_tracer_interval", _interval];
    _unit setVariable ["hyp_var_tracer_trackVel", _trackVel];
    _unit setVariable ["hyp_var_tracer_maxDistance", _maxDistance];
    _unit setVariable ["hyp_var_tracer_maxDuration", _maxDuration];
    _unit setVariable ["hyp_var_tracer_currentIndex", 0];
    _unit setVariable ["hyp_var_tracer_activeIndexes", []];
    _unit setVariable ["hyp_var_tracer_initialized", true];

    _eventHandle = _unit addEventHandler ["fired", {
        [_this, (position(_this select 6)),(velocity (_this select 6)) distance [0,0,0]] spawn hyp_fnc_traceFireEvent;
    }];
    _unit setVariable ["hyp_var_tracer_eventHandle", _eventHandle];
    hyp_var_tracer_tracedUnits set [count hyp_var_tracer_tracedUnits, _unit];
};  
 
hyp_fnc_traceFireEvent = {
    private["_this","_params","_initialPos","_unit","_projectile","_color","_lifetime","_interval","_maxDistance",
            "_maxDuration","_startTime","_skippedFrames","_positions","_projIndex","_activeIndexes","_initialVel"];
    _params        = _this select 0;
    _initialPos    = _this select 1;
    _initialVel    = _this select 2;
    _unit          = _params select 0;
    _projectile    = _params select 6;
    _color         = _unit getVariable "hyp_var_tracer_color";
    _lifetime      = _unit getVariable "hyp_var_tracer_lifetime";
    _interval      = _unit getVariable "hyp_var_tracer_interval";
    _maxDistance   = _unit getVariable "hyp_var_tracer_maxDistance";
    _maxDuration   = _unit getVariable "hyp_var_tracer_maxDuration";
    _startTime     = diag_tickTime;
    _skippedFrames = _interval; //Number of frames since last full operation.  Starts at interval value to record first position
    _positions     = [[_initialPos,_initialVel]];
    _projIndex     = -1;
    _activeIndexes = [];
 
    _projIndex     = _unit getVariable "hyp_var_tracer_currentIndex"; //Get the index to assign to the bullet
    _unit setVariable ["hyp_var_tracer_currentIndex", _projIndex + 1]; //Increment index for next bullet
 
    //Initialize final array into which all positions for the current projectile will be stored...
    _unit setVariable [format["hyp_var_tracer_projectile_%1", _projIndex], _positions];
    //...Then update the activeIndexes to indicate that the projectile is active
    _activeIndexes = _unit getVariable "hyp_var_tracer_activeIndexes";
    _activeIndexes set [count _activeIndexes, _projIndex];
    _unit setVariable ["hyp_var_tracer_activeIndexes", _activeIndexes];
    _activeIndexes = nil; //Completely nil this variable just as a safety measure, as the data it holds may be outdated now
 
    //Loop to run as long as the projectile's line is being updated
    waitUntil {
       
        //First, handle skipping frames on an interval
        if (_interval != 0 && _skippedFrames < _interval) exitWith {_skippedFrames = _skippedFrames + 1; false}; //Check and handle if frame should be skipped
        if (_interval != 0) then {_skippedFrames = 0;}; //Reset skipped frame counter on recording a frame
        //Next, check if the bullet still exists
        if (!alive _projectile) exitWith {true};
        //Finally, handle the duration and distance checks
        if (_maxDuration != -1 && ((diag_tickTime - _startTime) >= _maxDuration)) exitWith {true}; //Break loop if duration for tracking has been exceeded
        if (_maxDistance != -1 && ((_initialPos distance _projectile) >= _maxDistance)) exitWith {true}; //Break loop if distance for tracking has been exceeded
       
        //Now, checks have all been run, so let's do the actual bullet tracking stuff
        _positions set [count _positions, [position _projectile, (velocity _projectile) distance [0,0,0]]];
        _unit setVariable [format["hyp_var_tracer_projectile_%1", _projIndex], _positions];
    };
 
    //Now, if a lifetime is specified, wait until it has elapsed, then delete all data for that projectile
    if (_lifetime != -1) then {
        waitUntil {(diag_tickTime - _startTime) >= _lifetime};
        //Remove the current projectile's index from the activeIndexes...
        _activeIndexes = _unit getVariable "hyp_var_tracer_activeIndexes";
        _activeIndexes = _activeIndexes - [_projIndex];
        _unit setVariable ["hyp_var_tracer_activeIndexes", _activeIndexes];
        //... Then delete the data for the projectile itself
        _unit setVariable [format["hyp_var_tracer_projectile_%1", _projIndex], nil]; //Delete the projectile's data
    };
};

//Clears all lines created by a given unit manually
hyp_fnc_traceFireClear = {
    private["_this","_unit"];
    _unit = _this select 0;
    {
        _unit setVariable [format["hyp_var_tracer_projectile_%1", _x], nil];
    } forEach (_unit getVariable ["hyp_var_tracer_activeIndexes", []]);
    _unit setVariable ["hyp_var_tracer_activeIndexes", []];
};
 
//Completely removes this script from a unit
hyp_fnc_traceFireRemove = {
    private["_this","_unit"];
    _unit = _this select 0;
 
    _unit removeEventHandler ["fired", (_unit getVariable ["hyp_var_tracer_eventHandle", 0])];
    {
        _unit setVariable [format["hyp_var_tracer_projectile_%1", _x], nil];
    } forEach (_unit getVariable ["hyp_var_tracer_activeIndexes", []]);
    _unit setVariable ["hyp_var_tracer_color", nil];
    _unit setVariable ["hyp_var_tracer_lifetime", nil];
    _unit setVariable ["hyp_var_tracer_interval", nil];
    _unit setVariable ["hyp_var_tracer_maxDistance", nil];
    _unit setVariable ["hyp_var_tracer_maxDuration", nil];
    _unit setVariable ["hyp_var_tracer_currentIndex", nil];
    _unit setVariable ["hyp_var_tracer_activeIndexes", []];
    _unit setVariable ["hyp_var_tracer_eventHandle", nil];
};

[
    60, // seconds to delete dead bodies (0 means don't delete)
    5*60, // seconds to delete dead vehicles (0 means don't delete)
    3*60, // seconds to delete immobile vehicles (0 means don't delete)
    2*60, // seconds to delete dropped weapons (0 means don't delete)
    10*60, // seconds to deleted planted explosives (0 means don't delete)
    0 // seconds to delete dropped smokes/chemlights (0 means don't delete)
] execVM 'scripts\repetitive_cleanup.sqf';



_switchLocality = {
	if ((_this select 1) isKindOf "Building") then {
		[_this, "RTS_fnc_onObjectPlaced", false, false] spawn BIS_fnc_MP;
	};
};

if (!hasInterface) exitwith {};
waitUntil {!isNull player && (player == player) && !(isNull (findDisplay 46))};
diag_log "Assigning eventhandlers and removing side specific AddOns";
BluFor_CURATOR addEventHandler ["CuratorObjectPlaced", _switchLocality];
BluFor_CURATOR removeCuratorAddons ["A3_Air_F_Heli_Light_01", "A3_Air_F_Beta_Heli_Attack_01", "A3_Air_F_Beta_Heli_Transport_01", "A3_Air_F_EPC_Plane_CAS_01", "A3_Armor_F_Panther", "A3_Armor_F_Slammer", "A3_Armor_F_EPC_MBT_01", "A3_Armor_F_AMV", "A3_Characters_F_BLUFOR", "A3_Characters_F_Gamma", "A3_Characters_F_Beta", "A3_Data_F_Curator_Characters", "A3_UAV_F_Characters_F_Gamma", "A3_Characters_F_EPA", "A3_Soft_F_Crusher_UGV", "A3_Air_F_Gamma_UAV_02", "ModuleLightning_F"];

OPFOR_CURATOR addEventHandler ["CuratorObjectPlaced", _switchLocality];
OPFOR_CURATOR removeCuratorAddons ["A3_Air_F_Heli_Light_02", "A3_Air_F_Beta_Heli_Attack_02", "A3_Air_F_EPC_Plane_CAS_02", "A3_armor_f_beta_APC_Tracked_02", "A3_Armor_F_T100K", "A3_Soft_F_Crusher_UGV", "A3_Air_F_Gamma_UAV_02", "A3_Characters_F_OPFOR", "A3_Characters_F_Gamma", "A3_UAV_F_Characters_F_Gamma", "A3_Data_F_Curator_Characters", "ModuleLightning_F"];

INDEPENDENT_CURATOR addEventHandler ["CuratorObjectPlaced", _switchLocality];
INDEPENDENT_CURATOR removeCuratorAddons ["A3_Air_F_Beta_Heli_Transport_02", "A3_Air_F_EPB_Heli_Light_03", "A3_Air_F_Gamma_Plane_Fighter_03", "A3_Air_F_EPC_Plane_Fighter_03", "A3_Armor_F_EPB_APC_tracked_03", "A3_Armor_F_EPB_MBT_03", "A3_Armor_F_APC_Wheeled_03", "A3_Soft_F_Crusher_UGV", "A3_Air_F_Gamma_UAV_02", "A3_Characters_F_INDEP", "A3_Characters_F_Gamma", "A3_Characters_F_Civil", "A3_UAV_F_Characters_F_Gamma", "ModuleLightning_F"];
diag_log "Completed assigning eventhandlers and removing side specific AddOns";

RTS_ENABLE_FOW = true;
[] spawn {
        while {RTS_ENABLE_FOW} do {
                {
                        if ((side _x) != (side player)) then {
                                _list = (position _x) nearEntities [["CaManBase", "Air", "Car", "Motorcycle", "Tank"], 1000];
                                _found = false;
                                _unit = _x;
                                {
                                        if ((side _x) == (side player)) exitwith {
                                                _unit hideObject false;
                                                _found = true;
                                        };
                                }foreach _list;
                                if (!_found) then {
                                        _x hideObject true;
                                };
                        };
                }foreach allUnits;
               
                {
                        if ((side _x) != (side player)) then {
                                _list = (position _x) nearEntities [["CaManBase", "Air", "Car", "Motorcycle", "Tank"], 2000];
                                _found = false;
                                _unit = _x;
                                {
                                        if ((side _x) == (side player)) exitwith {
                                                _unit hideObject false;
                                                _found = true;
                                        };
                                }foreach _list;
                                if (!_found) then {
                                        _x hideObject true;
                                };
                        };
                }foreach vehicles;
        };
};
Edited by mr_shadow

Share this post


Link to post
Share on other sites

Hello guys, I'm trying to make a script which will basically dewlete the bullet and draw a green tracer line to the cursortarget.

 

So far as I know, all the scripts were based on the bullet tracing, and I was wondering if it is possible just to draw line for 5-7 sec which will be created about 100m distance or something like that.

 

Any help please?

A quick search suggests that you described exactly this.

 

Edit:

You should consider rather posting on the already existing thread.

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  

×