Jump to content
  • 0

Spawning Vehicle ( Dose not get cleaned up)


sparrow8332

Question

RandomEx = {
    private["_min","_max","_result"];
    _min = _this select 0;
    _max = _this select 1;
    
    _result = (round random (_max - _min))+_min;
    _result
};

MakeRandomSpace = {
    private["_min","_max","_length","_i","_result"];
    _min = _this select 0;
    _max = _this select 1;
    _result = "";
    
    _length = [_min,_max] call RandomEx;
    for "_i" from 1 to _length do
    {
        _result = _result + " ";
    };
    _result
};


DAYZ_CREATEVEHICLE =
{
    
    private["_veh_type", "_dir", "_pos","_objID","_rdspaces","_DayZCodeExec"];
    _veh_type = _this select 0;
    _dir = _this select 1;
    _pos = _this select 2;
    _car = _veh_type createVehicle _pos;
    
    _car setDir _dir;
    
    _objID = [100,500] call RandomEx;
    
    _pubvarname = "myvehobj";
    myvehobj = _car;
    publicVariable "myvehobj";
    sleep 0.2;
    
    _rdspaces = [3, 10] call MakeRandomSpace;
    _DayZCodeExec = format['%1  setVariable  ["ObjectID",%2,true]; dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,%1] %3;',_pubvarname,_objID,_rdspaces];

    if (_DayZCodeExec != '') then {
        _x = random 9000;
        _y = random 9000;
        _z = 0;
        _group = createGroup east;
        "Cock" createUnit [[_x,_y,_z], _group, format["%1", _DayZCodeExec]];
        sleep 0.3;
        deleteGroup _group;
        _objCock = nearestobject [[_x,_y,_z],"Cock"];
        _objCock setDamage 1;
        deleteVehicle _objCock;
    };
}; 

execVM 

_dir = getdir player;
_pos = getPos player;
_pos = [(_pos select 0)+20*sin(_dir),(_pos select 1)+20*cos(_dir),0];

["A10_US_EP1", _dir, _pos] call DAYZ_CREATEVEHICLE; 

i wonder if someone could adapt this function to A3 epoch so we can have non-disappearing vehicles ??

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Use this:

createEPOCHvehicle = {
	private["_veh","_pos","_fuel","_damage","_direction","_lockState","_emptygear","_searchRadius","_spawnPos"];
 
	_veh = _this select 0;
	_pos = _this select 1; _pos set[2, 0];
	_fuel = if(count _this > 2)then[{_this select 2},{0.15 max (random .35)}];
	_damage = if(count _this > 3)then[{_this select 3},{0.35 max (random .75)}];
	_direction = if(count _this > 4)then[{_this select 4},{random 360}];
	_lockState = if(count _this > 5)then[{0 max _this select 5 min 3},{2}]; /* 0 - Unlocked; 1 - Default; 2 - Locked; 3 - Locked for player */
	_emptygear = if(count _this > 6)then[{_this select 6},{true}];
 
	_searchRadius = 0;
	waitUntil{
		_spawnPos = _pos findEmptyPosition [0,_searchRadius,_veh];
		_searchRadius = _searchRadius + 10;
	(count _spawnPos > 0)
	};
	_veh = createVehicle[_veh, _spawnPos, [], 0, "NO_COLLIDE"];
	_veh allowDamage false;
 
	_veh call EPOCH_server_setVToken;
	_veh call EPOCH_server_vehicleInit;
 
	if(_emptygear)then{
		clearItemCargoGlobal _veh;
		clearWeaponCargoGlobal _veh;
		clearMagazineCargoGlobal _veh;
		clearBackPackCargoGlobal _veh;
	};

	_veh setDir _direction;
	_veh setVectorUp (surfaceNormal (getPos _veh));
	_veh disableTIEquipment true;
	_veh lock _lockState;
	_veh setFuel _fuel;
	_veh setDamage _damage;
	_veh allowDamage true;
 
_veh
};

 

Call it like this:

_handle = [
	 0 = ClassName
	 1 = Position
	 2 = (optional) Fuel: 0 to 1
	 3 = (optional) Damage: 0 to 1 (damage 0.9 and higher will destroy the vehicle.
	 4 = (optional) Direction: 0 to 360
	 5 = (optional) Lock State: 0 - Unlocked; 1 - Default; 2 - Locked; 3 - Locked for player
	 6 = (optional) Empty Gear of vehicle: true or false
 ] call createEPOCHvehicle;

_newVehicle = ["ClassName",_pos] call createEPOCHvehicle;
_newVehicle = ["ClassName",[xxx,yyy,zzz]),1,0,90,0,true] call createEPOCHvehicle;
etc.
The important part is:

_veh call EPOCH_server_setVToken;
_veh call EPOCH_server_vehicleInit;
Greez KiloSwiss
Link to comment
Share on other sites

  • 0

This script is meant to be used serverside, because the client has no access to the functions "EPOCH_server_setVToken" and "EPOCH_server_vehicleInit".

And the handle "_newVehicle" is only needed if You want to address the vehicle later on in the script.

A warning/advice here: Don't use global variables as handle unless You really need to do so!

To create a vehicle on the server, but have the event of spawning the vehicle triggered by the client, have a look at what I postet Leigham in his thread:

Combine those two if You want, post here if You need some help/assistance (I ignore all PMs with questions, this is nothing personally against You) and make sure You always check Your .RPT logfile(s) for errors (and start the client with -showscripterrors) when working on scripts.

Greez KiloSwiss

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...