Jump to content
gavc

Using createVehicle to make a graveyard

Recommended Posts

Hi Folks,

 

Need a little help with something. In order to add a little bit of realism I wanted to make a graveyard, so after our mission we could see just how many we lost. 

 

So I was going to use onPLayerRespawn.sqf to run a createVehicle command to dump a bodybag or grave within a certain area of the base.

 

I'm brutal at scripting anything from scratch, i've really only looked at other peoples work and editing it.

 

Is this correct? (Needs to be MP/JIP dedi compatible) 

createVehicle ["GraveCross1", getMarkerPos "Graveyard", 0, "none"]; //where graveyard in the marker name.

How do i randomise the placement of the graves withing the graveyard? Also how  would i orientate the graves all to be at the same angle? I've looked over the random function on the  wiki  but not sure how to integrate it with the above,  

 

And one final thing, Will running a random number generator in onPlayerRespawn.sqf take into account another players random number on a different client? Assume this might need to be run on the servers  side to make sure of no overlapping graves.

 

Gav

Share this post


Link to post
Share on other sites


addMissionEventHandler ["EntityKilled",{

if (isPlayer (_this select 0)) then {

[] call fnc_spawnGrave;

};

}];

fnc_getRandMkrLocs = {

//by twirly

private ["_mkr","_num","_obj","_grd","_mkrsiz","_mkrszx","_mkrszy","_mkrpos","_minx","_miny","_mkrdir",

         "_locs","_flatpt","_colr","_i","_ranx","_rany","_mrkr","_m","_stepx","_stepy","_newx","_newy"];

_fnFindFlat = {

    private ["_pos2chec","_objsize","_maxigrad","_flatpt"];

    _pos2chec = _this select 0;

    _obj2plac = _this select 1;

    _maxigrad = _this select 2;

    _flatpt = (_pos2chec) isflatempty [(sizeof typeof _obj2plac) / 2,0,_maxigrad,(sizeof typeof _obj2plac),0,false,_obj2plac];

    _flatpt

};

_mkr = _this select 0;

_num = _this select 1;

_obj = if (count _this >2) then {_this select 2};

_grd = if (count _this >3) then {_this select 3};

_mkrsiz = markersize _mkr;

_mkrszx = _mkrsiz select 0;

_mkrszy = _mkrsiz select 1;

_mkrpos = getmarkerpos _mkr;

_minx =  0 - (_mkrszx/2);

_miny =  0 - (_mkrszy/2);

_mkrdir    = (markerDir _mkr) * -1;

_mkrdir    = _mkrdir mod 360;

_locs = [];

_flatpt =[0,0,0];

_colr = "colorYELLOW";

if ((count _num) ==1) then {

    _cnt = _num select 0;

    for "_i" from 0 to (_cnt-1) do {

        _ranx = _minx + random _mkrszx;

        _rany = _miny + random _mkrszy;

        _newx = 2 * ((_ranx * cos(_mkrdir)) - (_rany * sin(_mkrdir)));

        _newy = 2 * ((_ranx * sin(_mkrdir)) + (_rany * cos(_mkrdir)));

        _newx = (_mkrpos select 0) + (_newx);

        _newy = (_mkrpos select 1) + (_newy);

        if (count _this >2) then {

            _flatpt = [[_newx,_newy],_obj,_grd] call _fnFindFlat;

            _colr = "colorRED";

        };

        if ((not surfaceiswater [_newx,_newy]) and (count _flatpt >0)) then {

            _locs set [count _locs,[_newx,_newy]];

        };

    };

};

if ((count _num) ==2) then {

    _stepx = (_mkrszx/(_num select 0));

    _stepy = (_mkrszy/(_num select 1));

    for [{_i=_minx},{_i<=(_minx+_mkrszx)},{_i=_i+_stepx}] do {

        for [{_j=_miny},{_j<=(_miny+_mkrszy)},{_j=_j+_stepy}] do {

            _newx = 2 * ((_i * cos(_mkrdir)) - (_j * sin(_mkrdir)));

            _newy = 2 * ((_i * sin(_mkrdir)) + (_j * cos(_mkrdir)));

            _newx = (_mkrpos select 0) + (_newx);

            _newy = (_mkrpos select 1) + (_newy);

            if (count _this >2) then {

                _flatpt = [[_newx,_newy],_obj,_grd] call _fnFindFlat;

                _colr = "colorRED";

            };

            if ((not surfaceiswater [_newx,_newy]) and (count _flatpt >0)) then {

                _locs set [count _locs,[_newx,_newy]];

            };

         };

    };

};

_locs

};

fnc_spawnGrave = {

private ["_locs", "_grave"];

_locs = ["Graveyard",[10,10]] call fnc_getRandMkrLocs;

_grave = createVehicle ["Land_Grave_V3_F", selectRandom _locs, [], 0, "NONE"];

_grave setDir (markerDir "Graveyard");

};

  • Like 1

Share this post


Link to post
Share on other sites
addMissionEventHandler ["EntityKilled",{

 

Very cool. Not too sure about "EntityKilled" but I'm guessing you could pass the dead player into fnc_spawnGrave and get their name. Then add an action to the grave with just the player name so others can see who is "buried" there.

Share this post


Link to post
Share on other sites

thanks for the quick reply - i'll implement this tomorrow into my alive mission and test it out. 

 

Gav

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

×