Jump to content
Sign in to follow this  
kibaBG

Spawn script trader who buy specific object

Recommended Posts

Hi guys, I am trying to do a script, which allow me to spawn a "fuel smuggler" (trader) who buys fuel crates only and gives the player 500 cash for every fuel barrel he buys. After 10 min he will disappear only to show 20 minutes later on another place.  
Monetary system is Grad Money Menu.  
 

while {true} do {
sleep 1200;
_pos1 = [1323.44,7742.14,0];
_pos2 = [11845.7,7733.76,0];
_pos3 = [2177.42,10840.1,0];
_pos4 = [2936.97,3438.3,0];
_rpos = [_pos1,_pos2,_pos3,_pos4] call BIS_fnc_selectRandom;   
_smugveh = "C_Truck_02_fuel_F" createVehicle _rpos;
_smugveh setFuel 0;
_spos = [_rpos, 3, 15, 3, 0, 0.5, 0] call BIS_fnc_findSafePos;
private _grp = createGroup [civilian,true];  
_smuggler = _grp createUnit ["CUP_C_TK_Man_02",_spos];
_smuggler enableAI "PATH"; 
_smugtrig = createTrigger ["EmptyDetector",_spos];
_smugtrig setTriggerArea [5,5,0,false];
_smugtrig setTriggerActivation ["STATIC","PRESENT",true];
_smugtrig setTriggerStatements ["{_x isKindOf "CargoNet_01_barrels_F"} count thisList == 1",
"_delete = nearestObjects [_smuggler, ["CargoNet_01_barrels_F"],50];
{deleteVehicle _x;} forEach _delete;
[player, 500] call grad_moneymenu_fnc_addFunds;",""]; 
_marker = createMarker ["Smuggler present!", _rpos]; 
_marker setMarkerType "loc_LetterS";
_marker setMarkerColor "colorCivilian";
sleep 600;
deleteMarker "Smuggler present!"
deleteVehicle _smugtrig;
deleteVehicle _smugveh; 
deleteVehicle _smuggler; 
};

No luck so far, nothing spawns. ¯\_(ツ)_/¯
I wonder where my mistake is ... 

Share this post


Link to post
Share on other sites

Well, there is a 20-minute sleep to get through before anything happens...

Share this post


Link to post
Share on other sites
1 hour ago, Harzach said:

Well, there is a 20-minute sleep to get through before anything happens...

I waited more than 20 minutes. 🙂 
 

Ok, I got it working with preplaced objects in the editor. Trigger activation by player, on activation
 

_nobj = nearestObject [smuggler,"CargoNet_01_barrels_F"];
deleteVehicle _nobj; 
[player,500] call grad_moneymenu_fnc_addFunds;

The fuel crate disappears and the player receives 500 Cr.    
But I think it will better with addAction on the smuggler itself instead of a trigger.  
 

Share this post


Link to post
Share on other sites
2 hours ago, kibaBG said:

I waited more than 20 minutes. 🙂 

 

You don't have to, you can change those values for testing, you know 😉

 

So, a few issues.

 

The set of positions is being defined unnecessarily every iteration, so we can move that outside the loop:

_posArray = [[1323.44,7742.14,0],[11845.7,7733.76,0],[2177.42,10840.1,0],[2936.97,3438.3,0]];

while {true} do {
	sleep 1200;
	private _rpos = _posArray call BIS_fnc_selectRandom;

Let's use the full syntax of createUnit, as sometimes it just wants you to:

private _smuggler = _grp createUnit ["CUP_C_TK_Man_02", _spos, [], 0, "NONE"];

You are using enableAI (which is doing nothing) instead of disableAI, I think, assuming you want the smuggler to not move around:

_smuggler disableAI "PATH"; 

Your trigger statements array has line breaks where it shouldn't*. Also there are nested double quotes - use single quotes when you are inside double quotes (aka: strings inside of strings). While we're here, we'll get rid of the setTriggerActivation line and just use the custom condition, which we we change to look for the barrels in the area of the trigger instead. Speaking of which, we'll also change the triggerArea to match the nearestObjects radius:

_smugtrig setTriggerArea [50, 50, 0,false];
_smugtrig setTriggerStatements [
	"getPos thisTrigger nearestObject 'CargoNet_01_barrels_F' inArea thisTrigger;",  //condition
	"{deleteVehicle _x;} forEach nearestObjects [SMUGGLER, ['CargoNet_01_barrels_F'], 50]; [player, 500] call grad_moneymenu_fnc_addFunds;",  //activation
	""  //deactivation (empty)
]; 

*(you can expand arrays vertically, with each element or groups of elements on each line - above, the elements are the condition, activation, and deactivation of the trigger statements)

 

There's a semicolon missing after the deleteMarker line:

deleteMarker "Smuggler present!";

There are likely locality issues with the local variables in the trigger statements, but that's easy enough, with a rewrite of the deleteVehicle expression and assigning the smuggler a global variable instead.  Full script:

_posArray = [[1323.44,7742.14,0],[11845.7,7733.76,0],[2177.42,10840.1,0],[2936.97,3438.3,0]];

while {true} do {
	sleep 1200;  //you can change these sleep values for testing...
	private _rpos = _posArray call BIS_fnc_selectRandom;   
	private _smugveh = "C_Truck_02_fuel_F" createVehicle _rpos;
	_smugveh setFuel 0;
	private _spos = [_rpos, 3, 15, 3, 0, 0.5, 0] call BIS_fnc_findSafePos;
	private _grp = createGroup [civilian,true];  
	private SMUGGLER = _grp createUnit ["CUP_C_TK_Man_02", _spos, [], 0, "NONE"];
	SMUGGLER disableAI "PATH"; 
	private _smugtrig = createTrigger ["EmptyDetector", _spos];
	_smugtrig setTriggerArea [50, 50, 0,false];
	_smugtrig setTriggerStatements [
		"getPos thisTrigger nearestObject 'CargoNet_01_barrels_F' inArea thisTrigger;",
		"{deleteVehicle _x;} forEach nearestObjects [SMUGGLER, ['CargoNet_01_barrels_F'], 50]; [player, 500] call grad_moneymenu_fnc_addFunds;",
		""
	];   
	private _marker = createMarker ["Smuggler present!", _rpos]; 
	_marker setMarkerType "loc_LetterS";
	_marker setMarkerColor "colorCivilian";
	sleep 600;  //you can change these sleep values for testing...
	deleteMarker "Smuggler present!";
	deleteVehicle _smugtrig;
	deleteVehicle _smugveh; 
	deleteVehicle SMUGGLER; 
};

 

Seems to be working in my tests, at least.

  • Like 1

Share this post


Link to post
Share on other sites
Quote

The set of positions is being defined unnecessarily every iteration, so we can move that outside the loop:

Quote

 Also there are nested double quotes - use single quotes when you are inside double quotes (aka: strings inside of strings)

Quote

(you can expand arrays vertically, with each element or groups of elements on each line - above, the elements are the condition, activation, and deactivation of the trigger statements)

 

I didn't know any of this! Thank you so much. I will report back when I test it.   

Share this post


Link to post
Share on other sites

Unfortunately it doesn't spawn anything on my side. 
Maybe I am not executing it as it should? I simply use this line in initServer: 

[] execVM "smuggler.sqf";

 

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
Sign in to follow this  

×