Roaming Trader script.

Inkko

Valued Member!
I was thinking about creating a script for epoch/overpoch to make a trader that changes locations every X amount of time. It would be setup as so:

All server side:
Trader skin is randomly selected from an array, and text for traders marker is selected based on skin. Then the trader is spawned with buildings around them and a marker added to the map. Sleep timers occur afterwards till they're done and everything gets deleted. Then another sleep timer occurs and the whole process starts over again. Title text notifications for when a trader spawns, about to leave, and leaves.

Is anyone interested in this idea or think there could be a better way to do it? Pretty much just want a random trader that spawns for a while around the map.
 

Inkko

Valued Member!
Nice idea maca134 did something like this a while back maybe yo could use his as a base.

http://epochservers.com/viewtopic.php?f=14&t=33
I have my entire script done now actually haha, just working on making a semi-decent looking trader area... kinda hard to do when you suck at the editor. That link looks like it just randomizes where the traders are on restarts, I kinda just wanted one trader to randomly move about while the server was up selling different things each time it moves.
 

Inkko

Valued Member!
Here is what my code looks like for what I've done... the trader looks god awful... but its working haha. Anything I should do to cleanup the code a bit?
Code:
/*-----------------------------------
|Roaming Trader (RT) Script by Inkko |
[] execVM "script.sqf"; bottom of server_functions.sqf
-----------------------------------*/
//Config
RT_TraderArray = ["Functionary2","RU_Functionary1","CIV_EuroMan02_EP1","GUE_Soldier_MG","RU_WorkWoman5","RU_Citizen1","menu_CIV_EuroMan01_EP1","RU_Profiteer4","Woodlander3","Doctor","GUE_Woodlander2","HouseWife1"]; // list of traders that are randomly chosen
RT_MaxDistance = 6000; // Max distance away from center of map to look for safe spot
RT_CloseObject = 30; // Max distance to closest object; BIS_fnc_findSafePos
RT_Timer = 900; // random number between 0-900, added to RT_Timer2 for fluctuating times.
RT_Timer2 = 300; // Base wait time.
RT_Wait = 120; // delay for warning that trader will move soon.
RT_Wait2 = 360; // Time till new trader shows up once previous trader has been deleted. Random number between 0-360.
RT_Color = "ColorBlack"; // Color of marker
RT_SpawnedMessage = "Roaming trader has setup on the map."; // message broadcast when trader spawns
RT_LeaveSoonMessage = "The roaming trader is about to travel to a new location."; // warning that trader will move soon.
RT_MovedMessage = "Roaming trader has packed up and is looking for a new spot."; // Broadcasts that trader has moved and looking for new spot.

//Config End
RT_Counter = 0;
uisleep 200; //intial delay before trader sets up.

RT_Fnc_Trader = {

RT_Location = [getMarkerPos "Center",0,RT_MaxDistance,RT_CloseObject,0,2,0] call BIS_fnc_findSafePos; //finds safe location
RT_TraderType = RT_TraderArray call BIS_fnc_selectRandom; // Selects trader type

// Locates correct text for trader skin selected. Change text based on what your traders are setup for.
if (RT_TraderType == "Functionary2") then  {RT_Text="Gem Trader";};
if (RT_TraderType == "RU_Functionary1") then  {RT_Text="Hero Trader";};
if (RT_TraderType == "CIV_EuroMan02_EP1") then  {RT_Text="Ammunition Trader";};
if (RT_TraderType == "GUE_Soldier_MG") then  {RT_Text="Bandit Trader";};
if (RT_TraderType == "RU_WorkWoman5") then  {RT_Text="Supply Trader";};
if (RT_TraderType == "RU_Citizen1") then  {RT_Text="Wholesaler";};
if (RT_TraderType == "menu_CIV_EuroMan01_EP1") then  {RT_Text="Weapon Trader";};
if (RT_TraderType == "RU_Profiteer4") then  {RT_Text="Vehicle Trader";};
if (RT_TraderType == "Woodlander3") then  {RT_Text="Building Supply Trader";};
if (RT_TraderType == "Doctor") then  {RT_Text="Medical Trader";};
if (RT_TraderType == "HouseWife1") then  {RT_Text="Special Trader";};
if (RT_TraderType == "GUE_Woodlander2") then  {RT_Text="Black Market Weapons";};

// creating mini-trader; trader, table, pad.
RT_CreateTrader = createAgent [RT_TraderType, [(RT_Location select 0)-18.6689,(RT_Location select 1)-13.2617, 0], [], 0, "CAN_COLLIDE"];
RT_CreateTrader setDir 233.79846;
RT_CreateTrader setVehicleInit "this allowDammage false; this disableAI 'FSM'; this disableAI 'MOVE'; this disableAI 'AUTOTARGET'; this disableAI 'TARGET'; this setBehaviour 'CARELESS'; this forceSpeed 0;";
RT_CreateTrader setUnitAbility 0.60000002;
RT_CreateTrader allowDammage false; RT_CreateTrader disableAI 'FSM'; RT_CreateTrader disableAI 'MOVE'; RT_CreateTrader disableAI 'AUTOTARGET'; RT_CreateTrader disableAI 'TARGET'; RT_CreateTrader setBehaviour 'CARELESS'; RT_CreateTrader forceSpeed 0;RT_CreateTrader enableSimulation false;

RT_CreatePad = createVehicle ["HeliHCivil",  [(RT_Location select 0),(RT_Location select 1), 0], [], 0, "CAN_COLLIDE"];
RT_CreatePad setDir -29.372313;
RT_CreatePad setPos [(RT_Location select 0),(RT_Location select 1), 0];

RT_CreateObject1 = createVehicle ["MAP_Fortress_01", [(RT_Location select 0)-17.3696,(RT_Location select 1)+10.497, 0], [], 0, "CAN_COLLIDE"];
RT_CreateObject1 setDir 150.883755;
RT_CreateObject1 setPos [(RT_Location select 0)-17.3696,(RT_Location select 1)+10.497, 0];

RT_CreateObject2 = createVehicle ["MAP_Misc_cargo_cont_net3", [(RT_Location select 0)-14.1455,(RT_Location select 1)+3.2548, 0], [], 0, "CAN_COLLIDE"];
RT_CreateObject2 setDir 56.260017;
RT_CreateObject2 setPos [(RT_Location select 0)-14.1455,(RT_Location select 1)+3.2548, 0];

RT_CreateObject3 = createVehicle ["MAP_HBarrier5", [(RT_Location select 0)-16.8638,(RT_Location select 1)-4.3334, 0], [], 0, "CAN_COLLIDE"];
RT_CreateObject3 setDir -123.68772;
RT_CreateObject3 setPos [(RT_Location select 0)-16.8638,(RT_Location select 1)-4.3334, 0];

RT_CreateObject4 = createVehicle ["MAP_HBarrier5", [(RT_Location select 0)-13.5845,(RT_Location select 1)-9.1324, 0], [], 0, "CAN_COLLIDE"];
RT_CreateObject4 setDir -123.68772;
RT_CreateObject4 setPos [(RT_Location select 0)-13.5845,(RT_Location select 1)-9.1324, 0];

RT_CreateObject5 = createVehicle ["MAP_HBarrier5", [(RT_Location select 0)-10.2895,(RT_Location select 1)-13.9164, 0], [], 0, "CAN_COLLIDE"];
RT_CreateObject5 setDir -123.68772;
RT_CreateObject5 setPos [(RT_Location select 0)-10.2895,(RT_Location select 1)-13.9164, 0];

RT_CreateObject6 = createVehicle ["MAP_CamoNet_EAST_var1", [(RT_Location select 0)-17.6933,(RT_Location select 1)+13.2617, 0], [], 0, "CAN_COLLIDE"];
RT_CreateObject6 setDir -122.872;
RT_CreateObject6 setPos [(RT_Location select 0)-17.6933,(RT_Location select 1)+13.2617, 0];

// start timer functions, broadcasts, and logs
_mapgrid = mapGridPosition RT_Location;
diag_log format["Roaming Trader: Spawned at grid %1, trader type selected as %2 trader type %3", _mapgrid, RT_TraderType, RT_Text];
[nil,nil,rTitleText,RT_SpawnedMessage,"PLAIN",10] call RE;
RT_Active = true;
// marker loop to keep marker active while trader is around
[] spawn {
    while {RT_Active} do {
        _mrk = createmarker ["Special_Trader",RT_Location];
        _mrk setmarkertype "mil_dot";
        _mrk setMarkerSize [1, 1];
        _mrk setmarkercolor RT_Color;
        _mrk setMarkerText RT_Text;
        sleep 30;
        deletemarker "Special_Trader";
    };
};
_cleanuptimer = round (random RT_Timer);
_cleanuptimer = _cleanuptimer + RT_Timer2;

diag_log format["Roaming Trader: (%5) Spawned at grid %1, trader type selected as %2 trader type %3 for %4 seconds", _mapgrid, RT_TraderType, RT_Text,_cleanuptimer,RT_Counter];

uisleep _cleanuptimer;

[nil,nil,rTitleText,RT_LeaveSoonMessage,"PLAIN",10] call RE;

uisleep RT_Wait;

[nil,nil,rTitleText,RT_MovedMessage,"PLAIN",10] call RE;

// timer up, removes trader and objects.
deletevehicle RT_CreateTrader;deletevehicle RT_CreatePad;deletevehicle RT_CreateObject1;RT_Active = false;deletemarker "Special_Trader";
deletevehicle RT_CreateObject2;deletevehicle RT_CreateObject3;deletevehicle RT_CreateObject4;deletevehicle RT_CreateObject5;deletevehicle RT_CreateObject6;
// wait time till next trader spawns
RT_Wait2 = round (random RT_Wait2);
diag_log format["Roaming Trader: Spawning in %1 seconds.", RT_Wait2];
uisleep RT_Wait2;

RT_Counter = RT_Counter+1;

call RT_Fnc_Trader; // starts function all over again.

};

call RT_Fnc_Trader; //initial call of function
 
ah, from the title, I thought you were going to make the trader 'roaming' around the map. be in his rusted out Ural driving around selling high value items. If a player was lucky enough to find him (and not kill him on sight) then he could buy some good rare stuff.
good idea there .. I have a total of 4 traders remaining on my server. I think I will make them 'roam' .. and of course my traders are not invulnerable .. if someone kills them, then no more trader until restart.

... yeah, I like it ...
Each one is driving a vehicle, and you can buy that vehicle then they walk. So there are only 4 vehicles for sale each restart (one from each trader) . After you buy the vehicle, the trader will be on foot .. maybe pushing a wheelbarrow.
And each restart each trader gets a random set of 2 cities to go between as waypoints and just keep going from one to the other.

I gave all my traders just normal gear .. shotguns, pistols, maps, watches etc. .. not much food or medical. I like the idea of earning stuff, not buying it. But if the traders were actually moving from one random city, to another random city so you had to actually track them down and find them, then you did earn the right to buy some better gear.
 
Last edited:

Inkko

Valued Member!
ah, from the title, I thought you were going to make the trader 'roaming' around the map. be in his rusted out Ural driving around selling high value items. If a player was lucky enough to find him (and not kill him on sight) then he could buy some good rare stuff.
good idea there .. I have a total of 4 traders remaining on my server. I think I will make them 'roam' .. and of course my traders are not invulnerable .. if someone kills them, then no more trader until restart.

... yeah, I like it ...
Each one is driving a vehicle, and you can buy that vehicle then they walk. So there are only 4 vehicles for sale each restart (one from each trader) . After you buy the vehicle, the trader will be on foot .. maybe pushing a wheelbarrow.
And each restart each trader gets a random set of 2 cities to go between as waypoints and just keep going from one to the other.

I gave all my traders just normal gear .. shotguns, pistols, maps, watches etc. .. not much food or medical. I like the idea of earning stuff, not buying it. But if the traders were actually moving from one random city, to another random city so you had to actually track them down and find them, then you did earn the right to buy some better gear.
That was something I was actually thinking of doing, making them drive around then get out in each city and they could sell stuff. But I lack the skill to do so xD.
 
" But I lack the skill to do so :)" .. <- that IS laughable .. You have provided some pretty valuable scripts and advice here.

I just looked quickly and the issue with a normal server would be the number of traders. To provide each trader moving individually between points they would have to have their own group as waypoints are assigned to groups, not units. On my system with a smaller number of traders (4) I would have 4 groups, not a problem. On a normal epoch with 20-ish traders it would require 20 groups and that might cause some AI lag issues. So the solution would be to create a caravan of traders. Put like 5 traders in a group and they travel together. maybe the car trader can tow a few cars to sell.
In the dayz_server/missions you would edit the mission.sqf to add the groups and waypoints. Would have to change createagent to createunit. And maybe have some logic to make them stop if a player is within 100m. When they get to their waypoint, they all get out and wait for 10 minutes, then get back into the vehicles and go to the next waypoint.

I have a few other things I am working on right now, but unique traders are a priority for my server so I will work on this tonight .. hopefully.
 

Inkko

Valued Member!
Haha, I've never really done anything AI related in regards to spawning them and getting them to do what I want. But I was thinking about having just 1 ural that would travel around and when the trader stops at a city upon getting out the skin would change to a new one so as to make each stop a different trader. At the moment it is kinda like how I want it, just not actual roaming going on just tping.
 
okay, you could do that. what I would do is have a driver and when he gets to the waypoint just spawn the trader outside the truck. Dont mess with the driver getting in and out.
 

Inkko

Valued Member!
Do AI automatically try to avoid colliding with things while driving? and do they tend to stick to roads? or would I have to make a bunch of pre-defined waypoints for them to follow so that they would stick more closely to the road?
 
if you set their combatmode to SAFE they will stay on the roads. if combatmode is combat or alert they will use the cover of offroad bushes, walls etc.
They will TRY to avoid debris but what I have noticed is that they dont look far enough forward. So driving down the road at full speed, only seeing directly in front of them its inevitable they hit stuff. What I have seen is that they try to avoid things at the last moment, which is how I came to the theory they dont see far enough ahead. So if they go slower (speed "limited") they will have more time to react. And if you want to set signaturefilechecks to zero in your server.cfg then the server can use http://www.armaholic.com/page.php?id=6882 this PBO on your server which tweaks the ai driving skills.
 

Inkko

Valued Member!
Spawned a vehicle and an ai, moved them into the vehicle and created a waypoint randomly and told the ai to drive to it. On the way the ai would randomly halt, run into trees/road debris/fences. When stuck on an object the ai would back up then run straight back into what they had just hit. So I'm thinking I might have to make some kind of randomized waypoint list for different routes it can take, so when the server starts it selects one route and has several stops along the way of the route so as to hopefully avoid the awful driving of the ai. Maybe I should also try a smaller vehicle other then a ural.
 
Spawned a vehicle and an ai, moved them into the vehicle and created a waypoint randomly and told the ai to drive to it. On the way the ai would randomly halt, run into trees/road debris/fences. When stuck on an object the ai would back up then run straight back into what they had just hit. So I'm thinking I might have to make some kind of randomized waypoint list for different routes it can take, so when the server starts it selects one route and has several stops along the way of the route so as to hopefully avoid the awful driving of the ai. Maybe I should also try a smaller vehicle other then a ural.
LOL... Classic.
I think that sakudriver pbo does make a difference. But there are some settings that will help the AI drive .. just cant think of it off the top of my head. They should NEVER get out of the vehicle until at the waypoint and told to. I had that occur on my bus route. I think its something with the courage setting. If they get 'scared' they run to hide. So try setting the AI skills all to 1 https://community.bistudio.com/wiki/setSkill_array and maybe the spotdistance and spottime would also increase the distance they see objects (doubtful).

We know the AI can drive because of the Bus route scripts. I used that and had AI teammates that would drive as well as 'taxi' drivers. It just takes some tweaking. Do a test, start the editor and create an AI, Vehicle and then a waypoint in another city (waypoint type 'move') (first waypoint has to be "getin nearest"). Get in the vehicle with them and actually watch them drive. put some debris in the roads and see how they react, change their settings and see the differences. When you got it all working so they can get from A to B (put some enemy AI of various factions along side the road too) without getting out .. then save your mission and extract the AI sqf settings.
 

Inkko

Valued Member!
Okay I fooled around with the settings a little and found that the large 2 lane roads seem to work the best. The 1 lane/ dirt roads the ai seem to have trouble following. Also setting the AI to "hate" all other factions seemed to make it not stop as frequently (I noticed that zombies nearby were causing the AI to stop for a short period of time). Using a smaller vehicle, like a hatchback, and limiting the speed of the vehicle also helped the AI getting around object it would hit; such as wrecks. They would still get stuck on the objects but they were not stuck forever like when I tested the ural with no speed limiting on the vehicle.

Is there a function to find a safe spot on the road possibly?
 
there is a function to find actual stuff on the road you have to look in one of the scripts for an IED. I'm not really sure what you're trying to find by a safe area on the road. As for the zombies making the vehicle stopped yes, on mine I added a script to the vehicle that would delete any zombies that were 10 meters in front of the vehicle.
right so if you set the AI to be unfriendly to other factions and then you would also have to set their combat mode I forget what it is called so that they never shoot otherwise they may want to get out and shoot a deer AI
 
if you are not in the vehicle monitoring the AI there will be no zombies spawn so that won't be an issue. But a zombie shield is not a bad idea since the traders stops he's going to be basically a safe zone.
 
Top