Перейти к содержимому


Фотография

Повторно не срабатывает скрипт


  • Авторизуйтесь для ответа в теме
Сообщений в теме: 4

#1 OFFLINE   GobStar

GobStar

    Рядовой

  • Пользователи
  • 2 сообщений

Отправлено 07 November 2014 - 12:01

Хочу добавить на полигон скрипт, включающий-выключающий трассерные-линии.

 

Подключал скрипт через init, но функцию вкл\выкл как приклеить, без понятия(т.е работает постоянно).

 

Подключал скрипт отдельно через sqf, в init.sqf прописал:

player addaction [("<t color=""#CCAA44"">" + "Bullet line" + "</t>"), "fnc_bullet_line.sqf", "", 0, false, false];

итого:

Через Скрол - Включается, выключается. Но не включается во второй раз.

 

Итак, знатоки, вопрос. Что добавить, да бы скрипт включался повторно?


  • 0

#2 OFFLINE   SteelRat

SteelRat

    Полковник

  • Пользователи
  • 3241 сообщений
  • Откуда:РФ

Отправлено 07 November 2014 - 17:21

1

Включаете и выключаете одним и тем же экшеном?

 

2

Не желаете нам показать содержимое этого

fnc_bullet_line.sqf

  • 0

#3 OFFLINE   SteelRat

SteelRat

    Полковник

  • Пользователи
  • 3241 сообщений
  • Откуда:РФ

Отправлено 07 November 2014 - 17:48

Как вариант, в инит игрока

this addaction [("<t color=""#CCAA44"">" + "Bullet line" + "</t>"), {

	if (isNil "BulletLine") then {BulletLine = false};
	
	switch BulletLine do {
		
		case true: {
			[player, 0] call BIS_fnc_traceBullets;
			BulletLine = false;
		};
		
		default {
			[player, 10] call BIS_fnc_traceBullets;
			BulletLine = true;
		};
	};

}, "", 0, false,true];

  • 0

#4 OFFLINE   GobStar

GobStar

    Рядовой

  • Пользователи
  • 2 сообщений

Отправлено 07 November 2014 - 20:33

 

1

Включаете и выключаете одним и тем же экшеном?

 

2

Не желаете нам показать содержимое этого

fnc_bullet_line.sqf

Одним и тем же.

 

собственно, этот скрипт нужно через скрол включать\выключать

fnc_bullet_line.sqf

/*
General init for the tracer function
*/
enableSaving [false,false];
hyp_var_tracer_tracedUnits = [];
hyp_var_tracer_currentMode = "Quality";

//Syntax for a mode Option:
//[_name, _paramsForTraceFire, _description]
hyp_var_tracer_modeOptions = [
    ["Quality", [nil, nil, nil, nil, nil, true], 
" - Quality - \n This is the highest quality tracking of projectiles this script can offer.  
It records every bullet's positions every frame until the bullet lands, and the lines are never automatically cleaned up."
    ], 
    ["Close-Range Quality", [nil, nil, nil, 200, nil, true], 
"- Close-Range Quality - \n This is a bit of an interesting mix: it will record the positions of every bullet fired as fast as it can, however it will only do so up to 200m away.  
For close-range testing, this is the recommended choice, as bullets richocheting off into the sky can cause massive performance hits if tracked."
    ], 
    ["Balanced", [nil, nil, 3, 1000, 8, true], 
"- Balanced - \n This is a bit of a compromise to help performance.  It records every bullet's positions every few frames until it is either 1km away from it's origin point, 
or 8 seconds have elapsed and it hasn't landed.  This is meant for testing higher volumes of bullets at one time."
    ],
    ["Performance", [nil, nil, 8, 700, 6, true], 
"- Performance - \n This mode is designed for tracking bullets on a large scale; if you want to strafe buildings with a Pawnee and still have the framerate to admire it, this is meant for you.  
If records every bullet's position every 8 frames, and no further than 700m from, or 6 seconds after it firing point."
    ],
    ["Super Performance", [nil, 8, 10, 700, 8, true], 
"- Super Performance - \n This is mostly for messing around more than anything else.  Each bullet's position is recorded every 10 seconds, for up to 700m or 6 seconds.  Further, each line will 
only persist for 8 seconds; after that, the line will be deleted."
    ]
];

addMissionEventHandler ["Draw3D", {
    {
        private["_unit"];
        _unit = _x;
        {
            private["_positions","_color","_muzzleVelocity"];
            _positions = _unit getVariable [format["hyp_var_tracer_projectile_%1", _x], [[[0,0,0],0]]];
            _color     = _unit getVariable ["hyp_var_tracer_color", [1,0,0,1]];
            _muzzleVelocity = (_positions select 0) select 1;
            
            //Step through every bullet fired by the current unit
            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};
                    };
                };

                drawLine3D [_positions select _i select 0, _positions select (_i + 1) select 0, _color];
            };
        } forEach ( _unit getVariable["hyp_var_tracer_activeIndexes", []] );

        //Check if the given unit is still to be tracked.  If not, set it to objNull to prep it for cleanup
//        if !(_unit getVariable ["hyp_var_tracer_initialized", false]) then {
//            hyp_var_tracer_tracedUnits set [_forEachIndex, objNull];
//        };
    } forEach hyp_var_tracer_tracedUnits;

    //Cleanup of unwanted/null units:
//    if (objNull in hyp_var_tracer_tracedUnits) then {
//        hyp_var_tracer_tracedUnits = hyp_var_tracer_tracedUnits - [objNull];
//        //Not the best solution, but works for now.  Should not need to run "too" frequently
//    };
}];
 
/*
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", "_isChange"];
    _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;
 
    //Check to see if the unit has already been initialized. If so, reassign the values, but don't re-add the event handler,
    //or push the unit to the tracedUnits array again.  
    _isChange = (_unit getVariable ["hyp_var_tracer_object", objNull] == _unit);
    if (_isChange) then {
        [_unit] call hyp_fnc_traceFireClear;
    };

    _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];
    _unit setVariable ["hyp_var_tracer_object", _unit];

    //If this unit has yet to be initialized, do so now
    if (!_isChange) then {
        _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];
    };
};

//Code spawned by the Fired EventHandler.  Does the nitty-gritty of the tracking
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 (isNull _projectile) exitWith {true};
        //Finally, handle the duration and distance checks
        
        //hintsilent format["%1 - %2\n%3 - %4", _maxDistance, (_initialPos distance _projectile), _maxDuration, (diag_tickTime - _startTime)];

        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 (NOT OPERATING 100% UP TO STANDARDS ATM)
hyp_fnc_traceFireRemove = {
    private["_this","_unit"];
    _unit = _this select 0;
 
    _unit removeEventHandler ["fired", (_unit getVariable ["hyp_var_tracer_eventHandle", -1])];
    {
        _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];
    _unit setVariable ["hyp_var_tracer_initialized", nil];
};

/*********************************************************************
EXTRA FUNCTIONS CURRENTLY NOT COMMITTED TO FINAL VERSION
*********************************************************************/

//Additional function to make setting adjustment by laptop more convenient
hyp_fnc_traceFireByPreset = {
    private["_unit","_mode"];
    _unit = _this select 0;
    _mode = _this select 1;

    {
        if (_mode == _x select 0) exitWith {
            ([_unit] + (_x select 1)) call hyp_fnc_traceFire;
        };
    } forEach hyp_var_tracer_modeOptions;
};

//Changes the settings of all currently traced units uniformly
hyp_fnc_traceFireChangeMode = {
    private["_newMode"];
    _newMode = (_this select 3) select 0;
    {
        if (_newMode == _x select 0) exitWith {
            hyp_var_tracer_currentMode = _newMode;
            {
                [_x, hyp_var_tracer_currentMode] call hyp_fnc_traceFireByPreset;
            } forEach hyp_var_tracer_tracedUnits;
            hint (_x select 2);
        };
    } forEach hyp_var_tracer_modeOptions;
};

//Passed one object, an offset, and a number, and will that many duplicates of that object at a relative offset.
hyp_fnc_createRow = {
    private["_offset","_object","_direction","_number","_lastPos","_type"];
    _object    = _this select 0;
    _offset    = _this select 1;
    _number    = _this select 2;
    _lastPos   = getPosATL _object;
    _type      = typeOf _object;
    _direction = getDir _object;
    for "_i" from 1 to _number do {
        private["_current"];
        _current = _type createVehicle _lastPos;
        _current setPosATL [(_lastPos select 0) + (_offset select 0), (_lastPos select 1) + (_offset select 1), (_lastPos select 2) + (_offset select 2)];
        _current setDir _direction;
        _lastPos = getPosATL _current;
    };
};

/*********************************************************************
SERVER SPECIFIC SCRIPTS
*********************************************************************/
if(isServer) then {

    //Generate those lined up walls for penetration testing
    [wall0, [0,-2,0], 30] call hyp_fnc_createRow;
    [wall1, [0,-3,0], 10] call hyp_fnc_createRow;
    [wall2, [0,-5,0], 8]  call hyp_fnc_createRow;

    //Configuration Laptop setup
    CFG_Laptop attachTo [CFG_Table, [0,-0.1,0.6]];  
    CFG_Laptop setVectorDir [-1,0,0];

};

/*********************************************************************
CLIENT SCRIPTS
*********************************************************************/

//Minor additional script to trace the fire for all players and their vehicles
//Super lazy solution I know, I'll revise it to be event-based later on down
//the road.  
[] spawn {
    while {true} do {


        //The player has not been initialized properly
        //The player does not have the addAction
        if ( (player getVariable ["hyp_var_tracer_object", objNull] != player) || !(player getVariable ["hyp_var_tracer_clearLinesAdded", false]) ) then {

            //Adding of the option to manually clear lines.  If you don't want the addaction, simply remove these 4 lines
            (player) addAction["<t color='#ffff00'>Clear Lines</t>", {
                {
                    [_x] call hyp_fnc_traceFireClear;
                } forEach hyp_var_tracer_tracedUnits;
            }, nil, -100]; //Clears the lines of all drawn projectiles
            player setVariable ["hyp_var_tracer_clearLinesAdded", true];
        };

        {
            if ((vehicle _x) getVariable ["hyp_var_tracer_object", objNull] != (vehicle _x)) then {
                [(vehicle _x), hyp_var_tracer_currentMode] call hyp_fnc_traceFireByPreset;
            };
        } forEach (playableUnits + switchableUnits);
        sleep 4;
    };
};





//Add the actions to the laptop
{
    private["_mode"];
    _mode = _x select 0;
    CFG_Laptop addAction [format["Set Tracer Mode: <t color='#99ff99'>%1</t>", _mode], hyp_fnc_traceFireChangeMode, [_mode, hyp_var_tracer_currentMode]];  
} forEach hyp_var_tracer_modeOptions; //Add actions for changing tracer mode to the laptop
CFG_Laptop addAction ["<t color='#1d94a6'>Enabke Time Manipulation Actions</t>", {
    if !(player getVariable ["hyp_var_tracer_hasTimeActions", false]) then {
        (player) addAction["<t color='#1d94a6'>Slow Time to x0.1 Speed</t>", {
            setAccTime 0.1;
        }, nil, -98]; 
        
        (player) addAction["<t color='#1d94a6'>Return to Normal Speed</t>", {
            setAccTime 1;
        }, nil, -99];
        (player) setVariable ["hyp_var_tracer_hasTimeActions", true];
    };
    
    hint "You've enabled the time manipulation functions!  You can now slow time to one tenth it's normal speed with via your action menu, 
and revert it at any time!  Note that these only works in single player.";
}];


  • 0

#5 OFFLINE   SteelRat

SteelRat

    Полковник

  • Пользователи
  • 3241 сообщений
  • Откуда:РФ

Отправлено 07 November 2014 - 23:09

Всё понял, весь этот дремучий лес, только ради того, что бы полюбоваться на разноцветный чёрточки в мультиплеере!

Не обессудьте Сударь, но мне не очень интересно разгребать эту кашу, все вопросы к автору!)


Сообщение отредактировал SteelRat: 07 November 2014 - 23:13

  • 0




Яндекс.Метрика