Jump to content

Trader Convoy


Schalldampfer

Recommended Posts

This script creates a caravan of traders who travel around the map - open a small market somewhere  for a while, and they leave away to next city.
(it's like "Traders In Move" in 1.0.5.1)

Install:

1. in your dayz_server.pbo, add a sqf file named "TraderConvoy.sqf" contains below:
 

Spoiler
//Trader convoy Script by Schalldampfer 2017/6/2
private ["_typeCar","_typeDriver","_typeCargo","_StayTime","_TradePosition",
"_spawn_pos","_groupSide","_unitGroup","_vehicle","_driver","_turretCount","_cargo","_Traders",
"_pos_wp","_wp","_msg","_out",
"_objTrader","_objTr","_pos"
];
if (!isServer) exitWith{};
////////////////////////////////////////////////////////
//Config//
_typeCar = "HMMWV_Ambulance"; //The convoy vehicle
_typeDriver = "UN_CDF_Soldier_Pilot_EP1"; // Vehicle crew
_typeCargo = ["GUE_Woodlander2","RU_Citizen4","Woodlander3"]; //Array of trader units
_StayTime = 1200; //How long they open trader city in seconds
_TradePosition = [ //Where they open trader city
[12465.473, 12545.1, 0],//NEAF
[2830.8259, 9782.0029,0],//Lopatino
[12934.999, 8396.3926,0],//Nizhnoye
[9975.8164, 5998.436,0],//Oreshka
[7879.2554, 3325.0015,0],//Prigorodki
[5143.7515, 2350.385, 0],//Balota
[7439.4507, 5146.8184,0],//Mogilevka
[4703.6274,4696.1729,0]//Kozlovka
];

////////////////////////////////////////////////////
//Variables//
DZTR_TraderInMove = true;
if (isNil "wai_radio_announce") then {wai_radio_announce = false;};
//Spawn traders//
_spawn_pos = [getMarkerPos 'center',0,((getMarkerSize "center") select 1) / 2,20,0,0.2,0] call BIS_fnc_findSafePos;
 
//create group
_groupSide = createCenter civilian;
_unitGroup = createGroup _groupSide;
//spawn Car
_vehicle = createVehicle [_typeCar, _spawn_pos, [], 0, "NONE"];
_vehicle setFuel 1;
_vehicle setVehicleAmmo 1;
_vehicle engineOn true;
_vehicle setVariable ["unitGroup",_unitGroup];
_vehicle setVariable ["ObjectID","1",true];
_vehicle setVariable ["CharacterID","0",true];
_vehicle allowDamage false;
_vehicle removeAllEventHandlers "handleDamage";//
_vehicle addEventHandler ["handleDamage", {false}];//
_vehicle setcaptive true;
clearWeaponCargoGlobal _vehicle;
clearMagazineCargoGlobal _vehicle;
if (isNil "dayz_serverObjectMonitor") then {dayz_serverObjectMonitor = [];};
dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_vehicle];
_vehicle lock false;
diag_log format["TraderConvoy: Spawned %1 %2",_typeCar,_vehicle];
//spawn driver
_driver = _unitGroup createUnit [_typeDriver, _spawn_pos, [], 1, "NONE"];
[_driver] joinSilent _unitGroup;
removeAllItems _driver;
removeAllWeapons _driver;
_driver disableAI "AUTOTARGET";
_driver disableAI "TARGET";
_driver setBehaviour "CARELESS";
_driver allowDamage false;
_driver removeAllEventHandlers "handleDamage";//
_driver addEventHandler ["handleDamage", { false }];//
_driver setcaptive true;
if (!(_driver hasWeapon "NVGoggles")) then {
 _driver addweapon "NVGoggles";
};
_driver setVariable ["isDriver",true];
_driver setVariable ["bodyName",(name _driver)];
_unitGroup selectLeader _driver;
_driver assignAsDriver _vehicle;
//_driver moveInDriver _vehicle;
diag_log format["TraderConvoy: Spawned %1 %2 as driver",_typeDriver, name _driver];
//spawn cargo
_Traders = [];
_i = 0;
{
 _cargo = _unitGroup createUnit [_x, _spawn_pos, [], 1, "NONE"];
 //_cargo = createAgent [_x, [0,0,0], [], 1, "NONE"];
 [_cargo] joinSilent _unitGroup;
 _cargo setVariable ["bodyName",(name _cargo)];
 removeAllItems _cargo;
 removeAllWeapons _cargo;
 _cargo disableAI "AUTOTARGET";
 _cargo disableAI "TARGET";
 _cargo setBehaviour "CARELESS";
 _cargo setCombatMode "BLUE";
 _cargo allowDamage false;
 _cargo removeAllEventHandlers "handleDamage";//
 _cargo addEventHandler ["handleDamage", { false }];//
 _cargo setcaptive true;
 if (!(_cargo hasWeapon "NVGoggles")) then {
  _cargo addweapon "NVGoggles";
 };
 _cargo assignAsCargo _vehicle;
 //_cargo moveInCargo _vehicle;
 diag_log format["TraderConvoy: Spawned a Trader %1 %2",_x, name _cargo];
 _Traders set[count _Traders,_cargo];
 _i = _i + 1;
} foreach _typeCargo;
//Set group status
_unitGroup setBehaviour "CARELESS";
_unitGroup setCombatMode "BLUE";
(units _unitGroup) allowGetIn true;//
(units _unitGroup) orderGetIn true;//
_pos_wp = _TradePosition select 0;
{if ((_pos_wp distance _vehicle) > (_x distance _vehicle)) then {_pos_wp = _x;};} foreach _TradePosition;
diag_log format["TraderConvoy: %1",_Traders];
 
//Monitor//
[_vehicle,_driver] spawn {
 private["_vehicle","_driver","_marker"];
 _vehicle  = _this select 0;
 _driver = _this select 1;
 while {true} do {
  //Refuel,Repair,Reassign
  if (fuel _vehicle < 0.2) then { _vehicle setfuel 1; };
  if (damage _vehicle > 0.3)then{
   _vehicle setDamage 0;
  };
  _vehicle setVectorUp surfaceNormal position _vehicle;
  if(driver _vehicle != _driver) then {
   moveOut driver _vehicle;//
   _driver assignAsDriver _vehicle;
   _driver moveInDriver _vehicle;
  };
  //Create Marker
  _marker = createMarker ["TraderConvoy", getPos _vehicle];
  _marker setMarkerColor "ColorBlue";
  _marker setMarkerText "Trader Convoy";
  if (!DZTR_TraderInMove) then { // Deployed
   _marker setMarkerType "mil_circle";
   sleep 25;
  } else { // Convoy
   _marker setMarkerType "mil_dot";
   sleep 10;
  };
  deleteMarker _marker;
 };
};
///////////////////////////////////////////////////////////////////////////////////
//Start Convoy//
while {true} do {
 //Search next city//
 if (isNil "_pos_wp") then {_pos_wp = _TradePosition call BIS_fnc_selectRandom;};
 while {_pos_wp distance _vehicle < 500} do {
  _pos_wp = _TradePosition call BIS_fnc_selectRandom;
 };
 _pos_wp = [_pos_wp,0,150,10,0,1.0,0] call BIS_fnc_findSafePos; //select safe position
 
 //Move//
 //set waypoint
 diag_log ("TraderConvoy: Adding waypoints");
 _wp = _unitgroup addWaypoint [_pos_wp,0];
 _wp setWaypointType "MOVE";
 _wp setWaypointBehaviour "CARELESS";
 _wp setWaypointCombatMode "BLUE";
 _unitgroup setCurrentWaypoint [_unitgroup, 0];
 

 //call

 diag_log format["TraderConvoy: Moving to %2 %1",_pos_wp , mapGridPosition _pos_wp];
 _msg = format["[Trader Convoy] The convoy is moving to %1",mapGridPosition _pos_wp];
 if (wai_radio_announce) then {
  RemoteMessage = ["radio",_msg];
  publicVariable "RemoteMessage";
 } else {
  [nil,nil,rTitleText,_msg,"PLAIN",10] call RE;
 };

 
 //Wait for arrival //
 waitUntil {sleep 10;(_vehicle distance _pos_wp < 25)};
 diag_log ("TraderConvoy: Trader has arrived");

 //Deploy Trader//
 //get out
 _vehicle engineOn false;
 _vehicle lock false; //unlock car
 _Traders orderGetIn false;
 _Traders allowGetIn false;
 DZTR_TraderInMove = false;
 sleep 5;
 diag_log ("TraderConvoy: Now lock vehicle");
 {moveOut _x;} forEach (crew _vehicle);
 _driver assignAsDriver _vehicle;
 _driver moveInDriver _vehicle;
 sleep 0.1;
 _vehicle engineOn false;
 _vehicle lock true; //lock car
 //deploy things
 _objTrader = [];
 _objTr = objNull;
 //Info board
 _objTr = createVehicle ["Info_Board_EP1", _pos_wp, [], 0, "NONE"];
 _objTr setDir (random 360);
 _objTrader set [count _objTrader, _objTr];
 //Light pole
 _objTr = createVehicle ["ASC_EU_LHVOld", getpos _vehicle, [], 0, "NONE"];
 _objTr setDir (random 360);
 _objTrader set [count _objTrader, _objTr];
 _objTr = createVehicle ["Misc_cargo_cont_net1", getpos (_Traders select 0), [], 0, "NONE"];
 _objTr setDir (random 360);
 _objTrader set [count _objTrader, _objTr];
 _objTr = createVehicle ["Pile_of_wood", getpos (_Traders select 0), [], 0, "NONE"];
 _objTr setDir (random 360);
 _objTrader set [count _objTrader, _objTr];
 //Walls
 for "_i" from 1 to 12 do {
  _objTr = createVehicle ["Misc_concrete_High",
   [((getpos _vehicle) select 0)+10*cos(_i*30),
   ((getpos _vehicle) select 1)+10*sin(_i*30),
   0],[], 0, "NONE"];
  _objTr setDir (_i*30 + 90);
  _objTrader set [count _objTrader, _objTr];
 };
 //Helipad
 if (true) then {
  _pos = [_pos_wp,10,40,4,0,2000,0] call BIS_fnc_findSafePos;
  _objTr = createVehicle ["HeliHCivil", _pos, [], 0, "NONE"];
  _objTrader set [count _objTrader, _objTr];
 };
 //call
 _msg = format["[Trader Convoy] The convoy has opened a trader city at %1",mapGridPosition _vehicle];
 if (wai_radio_announce) then {
  RemoteMessage = ["radio",_msg];
  publicVariable "RemoteMessage";
 } else {
  [nil,nil,rTitleText,_msg,"PLAIN",10] call RE;
 };

 //Wait//
 sleep _StayTime;

 //Finish Trader//
 //call
 diag_log format["TraderConvoy: Leaving %2 %1",_pos_wp , mapGridPosition _vehicle];
 _msg = format["[Trader Convoy] The trader convoy is leaving %1",mapGridPosition _vehicle];
 if (wai_radio_announce) then {
  RemoteMessage = ["nradio",_msg];
  publicVariable "RemoteMessage";
 } else {
  [nil,nil,rTitleText,_msg,"PLAIN",10] call RE;
 };
 
 //delete things
 {deleteVehicle _x;} foreach _objTrader;

 //get in
 DZTR_TraderInMove = true;
 _vehicle lock false; //unlock
 _driver action ["Eject", _vehicle];// eject once
 _driver assignAsDriver _vehicle;
 {_x assignAsCargo _vehicle;} foreach _Traders;
 (units _unitGroup) allowGetIn true;
 (units _unitGroup) orderGetIn true;
 
 //check crews in and lock
 waitUntil {(_vehicle emptyPositions "DRIVER" == 0)}; // Wait until driver gets inside vehicle
 {
  if (!(_x in crew _vehicle)) then {
   _x moveInCargo _vehicle;
  };
 } foreach _Traders;
 diag_log ("TraderConvoy: Everyone's in");
 _vehicle lock true; //lock
 _vehicle engineOn true;
};
/////////////////////////////////////////////////////////////////////////////////////////

2. in the bottom of dayz_server\init\server_functions.sqf , add a line to spawn TraderConvoy.sqf that you added like this:

Spoiler

//TraderConvoy
[] execVM "\z\addons\dayz_server\TraderConvoy.sqf";

this file must be run by "execVM," not "call compile bra-bra-brah"

---

Nown Issue:

The traders get deleted in safezones by AI remover of SafeZone script.

Edited by Schalldampfer
fixed a bug that traders do not move, fix radio bug, fix traders not invincible
Link to comment
Share on other sites

Hi got some questions about that script.

When i change the citys (coordinates) i can use this script for any map?

do i need the servertrader.sqf entry for normal traders, because they will delete by savezone script.

 

sry for my bad english

Link to comment
Share on other sites

@Schalldampfer you can try something like this in your safezone

Spoiler

if (USE_AI_REMOVER) then
            {
			private ["_typeCargo"];
			_typeCargo = ["UN_CDF_Soldier_Pilot_EP1","GUE_Woodlander2","RU_Citizen4","Rita_Ensler_EP1","Dr_Annie_Baker_EP1"]; 
                {
                    if ((!isNull group _x) && (getPlayerUID _x == '') && (!_typecargo)) then
                    {
					
                        deleteVehicle _x;
                    };
                } forEach (player nearEntities ['Man',100]);

 

 

Link to comment
Share on other sites

6 hours ago, juandayz said:

@Schalldampfer you can try something like this in your safezone

  Reveal hidden contents


if (USE_AI_REMOVER) then
            {
			private ["_typeCargo"];
			_typeCargo = ["UN_CDF_Soldier_Pilot_EP1","GUE_Woodlander2","RU_Citizen4","Rita_Ensler_EP1","Dr_Annie_Baker_EP1"]; 
                {
                    if ((!isNull group _x) && (getPlayerUID _x == '') && (!_typecargo)) then
                    {
					
                        deleteVehicle _x;
                    };
                } forEach (player nearEntities ['Man',100]);

 

 

thanks, I'll try it:)

 

 

9 hours ago, Kimarik said:

Hi got some questions about that script.

When i change the citys (coordinates) i can use this script for any map?

do i need the servertrader.sqf entry for normal traders, because they will delete by savezone script.

 

sry for my bad english

Of course, you can use it for any map if you change the coordinates. 

----

I edited TraderConvoy.sqf a bit to work correctly... sometimes traders were camping in the vehicle...

Edited by Schalldampfer
Link to comment
Share on other sites

  • 2 months later...

hey i increased the amount of traders in the convoy so I upgraded to the Kamaz to accommodate. However, I found that someone is able to jump into the back, and switch to the driver's seat and steal the truck. How can I make it so that players cannot get into the vehicle?

Link to comment
Share on other sites

46 minutes ago, Runewulv said:

hey i increased the amount of traders in the convoy so I upgraded to the Kamaz to accommodate. However, I found that someone is able to jump into the back, and switch to the driver's seat and steal the truck. How can I make it so that players cannot get into the vehicle?

Replace any instance of: 

_vehicle lock false;

with:

_vehicle setVehicleLock "UNLOCKED";

And any instance of: 

_vehicle lock false;

with:

_vehicle setVehicleLock "LOCKED";

 

Link to comment
Share on other sites

Your fix is working good, mate thanks. I increased the amount of Traders to about double. Any idea which parameter I can adjust so that 4 of them don't crowd together? Original script had three so the first two traders spread out and then the last four all hang almost inside of one another. I'm assuming there is some place I have to either add off center positions too, or increase the amount available. I'm not seeing anything jump out at me though.

Link to comment
Share on other sites

So I backed off to 3 traders like the script has originally because I thought the Kamaz may have been too big for the AI to properly navigate. So I gave them the swat police car. They drive very well. Except for in Pogorevka. For some reason when they get into the middle of Pog, on a straight empty piece of road before the curve at the gas station, the AI have one hell of a time getting through this section. It literally accelerates for all it's worth without actually going some where. And when they do move forward, they stop, and rubber band backwards a few feet. I've tried to keep them from actually going in that direction to no avail. They still seem to head that way any how. Does anyone have any clue how I can fix this? For now I'm going to just keep them patrolling the coast. Any help would be great.

Link to comment
Share on other sites

  • 4 months later...
1 hour ago, BetterDeadThanZed said:

Cool script but I have a small graphical issue that is bothering me.

20180104072141_1.jpg

Also, it seems if you get into the vehicle, even though it boots you out, the traders stop driving. The driver gets back in the driver's seat, but the truck doesn't move.

the graphical glich is bug of arma or epoch,as I'm not using attachto command, just moveInCargo.

The trader sometimes stops moving at all, whether you got in or not, and I have no solution for it.

Link to comment
Share on other sites

On 1/10/2018 at 6:01 AM, Kimarik said:

Hello. Is it possible to integrate a Portable Safezone in the script? So that the traders are in a safe zone, and when they are on the move again the safe zone is gone?

It's possible but hard. This code is on server-side, but safezone script is on client side.

Link to comment
Share on other sites

  • 3 months later...

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
  • Discord

×
×
  • Create New...