Jump to content
Sign in to follow this  
mech79

random hostage placement once intel is found

Recommended Posts

/i have searched and found a couple of good Hostage scripts I wanna try, but how would I place the script to activate and place a random hostage or two only after a laptop or intel was found that is also random to find. Basically I want to place multiple intel or Laptops around different camps. A team must enter the camp and locate these different intel to find the location of the hostages(s). At the time the right intel is found I want a hostage placed randomly on the map by using markers in a script that places a hostage within the radius of the marker I placed so they are not in the same building every time. I would like this to work on a dedicated server since I play online a lot. Can anybody help? I have tried searching but was unable to find anything close to what I am looking for, just random hostage placement scripts.

Share this post


Link to post
Share on other sites

I did read your script and it was going to use it, but what I am trying to accomplish is at start of game having laptops that are placed at different camps. You have to find them and randomly one will provide the locations of the hostages. To keep the game dynamic I want the hostage placement to be random as well with like 5 to 10 different possible markers. This way the hostage is not always in the same location or town. I have found a script for the laptops which you have to download information HERE. What I would like is to use his trigger that detect download complete and randomly place a hostage or two at different location(s) on the map. You could have one hostage or 3 at one location or 3 different locations to rescue.

Edited by mech79

Share this post


Link to post
Share on other sites

Well it's pretty simple to throw in a random marker line, and you could probably delete quite a bit of this considering that it also creates a rescue hostage task. But then in your trigger waiting for download of info, just execute this script in onAct, one of the earlier iterations had a random number of hostages instead of a defined number.

By perfect I meant that there was a lot of the stuff you were looking for, you may have to add in a randomization for the locations or even a for loop to execute the script multiple times for multiple locations, it's not an exact solution.

Share this post


Link to post
Share on other sites

If you want to utilize a good randomization with predictable but not too repetitive results you should really look into selectBestPlaces.

That's my go-to command if I want to pick a random location that's not predefined on the map, it's extremely reliable and quick if you pick a high enough area to be scanned.

Further information here.

Quick example using world center position and world size to safely search the entire map for a fitting location:

_centerpos = getarray (configfile >> "CfgWorlds" >> worldName >> "centerPosition");
_size = getnumber (configfile >> "CfgWorlds" >> worldName >> "mapSize");
_randompos = selectBestPlaces [_centerpos, _size,"(3 + meadow) * (1 + houses) * (1 - sea)",250,8];

This would return up to 8 places on the entire map that are near a good amount of meadows, some houses and away from any water.

250 is, as I understand it the area in m² that is being scanned, setting this to a smaller value might return more accurate results but would also result in a significant fps drop.

Leaving it at 250, I never noticed this script, even going as low as 80 should be safe.

I use it to spawn ambient animals, outposts and other random stuff that shouldn't be spawned within towns.

Works on every map, no need to place markers.

Cheers

Share this post


Link to post
Share on other sites

JShock and Grumpy thanks for the info. I am not the greatest scripter and have stepped away from making a mission for awhile since Zeus came out. The select best places would be awesome. I know using selectbestplace for placing a marker with a specific name then running this script after for that marker name, but I have to ask how would I do that and could I be more specific for placement like camps? Jshock is this the latest script you made. It looks like the last one in the post, but want to make sure no new modifications were made.

_marker = [_this,0,"",[""]] call BIS_fnc_param;
_numHostages = [_this,1,1,[0]] call BIS_fnc_param; 

JSHK_fnc_hostageRescue = 
{ 
   private ["_marker","_numHostages","_civTypes","_pos","_grp","_task"]; 
   _marker = (_this select 0);
   _numHostages = (_this select 1);
   _civTypes = ["C_man_1", "C_man_pilot_F", "C_scientist_F", "C_man_w_worker_F", "C_man_p_fugitive_F_afro"]; 

   //uncomment the next two lines if you want random building position 
   //_pos = [_marker,100] call JSHK_fnc_buildingPositions; 
   //_posNew = _pos call BIS_fnc_selectRandom; 

   //comment out the following line if the two above are uncommented 
   _posNew = (getMarkerPos _marker); 

   _grp = createGroup CIVILIAN; 
   JSHK_hostageArr = []; 

   if (_numHostages <= 0) then
   {
       _numHostages = 1;
       systemChat "Number of Hostages undefined, used 1 instead.";
   };

   for "_i" from 0 to (_numHostages) step 1 do 
   { 
       _rndType = _civTypes call BIS_fnc_selectRandom; 

       _unit = _grp createUnit [_rndType, _posNew, [], 1, "NONE"]; 

       _unit addAction ["Capture/Rescue",{call JSHK_captureAddAction},[],6,true,true,"","_this distance _target < 2 && alive _target"]; //added alive _target 

       _unit addEventHandler ["Killed", "['Hostage', 'Failed', true] call BIS_fnc_taskSetState; ['Hostage',['A Hostage was killed','Hostage Rescue', _marker]] call BIS_fnc_taskSetDescription"]; 

       _unit setCaptive true; 

       _unit setUnitPos "DOWN"; 

       _unit disableAI "MOVE"; 

       JSHK_hostageArr pushBack _unit; 
   }; 

   _task = ["Hostage", WEST, ["Rescue the Hostages", "Hostage Rescue", _marker], (getMarkerPos _marker), "AUTOASSIGNED", 5, true, true] call BIS_fnc_setTask; 

   capturePoint setTriggerStatements [ 
                                       "({_x in ([thisList] call LALA_fnc_ConvertArray2StringCopy)} count ([JSHK_hostageArr] call LALA_fnc_ConvertArray2StringCopy)) isEqualTo (count ([JSHK_hostageArr] call LALA_fnc_ConvertArray2StringCopy))", 
                                       ((triggerStatements capturePoint) select 1), 
                                       ((triggerStatements capturePoint) select 2) 
                                     ]; 
   while {true} do 
   { 
       sleep 3; 
       if ([_task] call BIS_fnc_taskState isEqualTo "Failed") exitWith 
       { 
           capturePoint setTriggerStatements [ 
                                               "this", 
                                               ((triggerStatements capturePoint) select 1), 
                                               ((triggerStatements capturePoint) select 2) 
                                             ]; 
           missionNameSpace setVariable ["haveHostagesBeenRescued",false]; 
       }; 

       if (!isNil {missionNameSpace getVariable "haveHostagesBeenRescued"}) exitWith 
       { 
           [_task, "Succeeded", true] call BIS_fnc_taskSetState; 
           capturePoint setTriggerStatements [ 
                                               "this", 
                                               ((triggerStatements capturePoint) select 1), 
                                               ((triggerStatements capturePoint) select 2) 
                                             ]; 
           missionNameSpace setVariable ["haveHostagesBeenRescued",nil]; 
       }; 

   }; 
_hostageArr; 
}; 

LALA_fnc_ConvertArray2StringCopy = { 
   //converts everything inside the array to a string (does not replace original) 
   // THIS SELECT 0: ARRAY 
   private "_array"; 
   _array = + _this select 0; 
   { 
       if (typeName _x != "STRING") then { 
           _array set [_foreachindex,str _x]; 
       }; 
   }forEach _array; 
   _array 
}; 

JSHK_fnc_buildingPositions = 
{ 
   private ["_center","_radius","_houses","_insideHousePos","_singlePosArray"]; 

   _center = [_this,0,objNull,["",objNull,[]],[3]] call BIS_fnc_param; 
   _radius = [_this,1,200,[0]] call BIS_fnc_param; 

   switch (typeName _center) do 
   { 
       case "OBJECT": { _center = getPos _center; }; 
       case "STRING": { _center = getMarkerPos _center; }; 
       case "ARRAY": { _center; }; 
       default { diag_log "Center position undefined >> JSHK_garrison\fn_buildingPositions.sqf"; }; 
   }; 

   _houses = nearestObjects [_center, ["House"], _radius]; 

   _insideHousePos = []; 

   { 
       if ([_x] call BIS_fnc_isBuildingEnterable) then 
       { 
           _buildPos = [_x] call BIS_fnc_buildingPositions; 
           _insideHousePos pushBack _buildPos; 
       }; 
   }forEach _houses; 

   _singlePosArray = []; 

   for "_i" from 0 to ((count _insideHousePos) - 1) step 1 do 
   { 
       _singleHouse = _insideHousePos select _i; 

       for "_a" from 0 to ((count _singleHouse) - 1) step 1 do 
       { 
           _singlePos = _singleHouse select _a; 
           _singlePosArray pushBack _singlePos; 
       }; 
   }; 
_singlePosArray; 
}; 

JSHK_captureAddAction = 
{ 
   private ["_unit","_player","_actionID","_civGroup"]; 
   _unit = (_this select 0); 
   _player = (_this select 1); 
   _actionID = (_this select 2); 

   ["Hostage", (getPos capturePoint)] call BIS_fnc_taskSetDestination; 
   _civGroup = units (group _unit); 
   _civGroup joinSilent (group _player); 

   { 
       _x removeAction _actionID; 
       _x setUnitPos "UP"; 
       _x enableAI "MOVE"; 
   } forEach _civGroup; 
}; 

[_marker,_numHostages] call JSHK_fnc_hostageRescue;

Share this post


Link to post
Share on other sites

Yes that is the final version, but if you want the random number of hostages, look at post #16 of that thread.

And could you be a bit more clear on what your asking about selectBestPlaces? Are you asking how to use it to spawn camps, or something else?

Edited by JShock

Share this post


Link to post
Share on other sites

Sorry I was asking how to attach selectBestPlace to work with your script at random locations. I was also asking is there a way to zone in more on camps versus cities?

So I guess this is what I want to happen-

After team locates random placed Laptop they must download information to locate position of Hostages. This will set trigger to perform script that places random location(s) on map where Hostage(s) is/are place(d) in random buildings. Task is started for rescue of hostages and trigger is placed back at base to end mission when all hostages are retrieved. Maybe loop this sequence to get multiple task positions and hostages. I also want to place AI in those locations at that time so they are not clogging space before hand just roaming the map. I know most of it is just a matter of running scripts but it must all be started with placement of a marker(s) using selectBestplace.

I hope that is better to understand. I have AI script just need to place your hostage script and was wondering how to start it all with select script to place marker with name.

Share this post


Link to post
Share on other sites

Well after you've executed the selectBestPlaces command and gotten a return, you can move/create a marker like the following, then execute my script:

_pos = selectBestPlaces [blah...];

"MarkerName" setMarkerPos ((_pos select 0) select 0);

["MarkerName",(floor(random 2)+2)] execVM "JSHK_hostage.sqf";

As far as preference of camps over cities, I'm not quite sure how to do that (I've actually never used selectBestPlaces so...).

Edited by JShock

Share this post


Link to post
Share on other sites

Grumpy I have done something wrong Help...lol. I placed this code which did place a marker and executed the script, but it was on the corner of the map out in the ocean. What do I need to change to get it to work? I am trying to get it to locate places where bases or camps might be in the hills or mountains. Since most of them are out of the meadows.

_centerpos = getarray (configfile >> "CfgWorlds" >> worldName >> "centerPosition");
_size = getnumber (configfile >> "CfgWorlds" >> worldName >> "mapSize");
_pos = selectBestPlaces [_centerpos, _size,"(1 + hills) * (1 - meadow) * (1 + houses) * (1 - sea)",250,8];

"mrk1" setMarkerPos ((_pos select 0) select 0);

["mrk1",(floor(random 2)+2)] execVM "JSHK_hostage.sqf";

Share this post


Link to post
Share on other sites

Ok so another idea is this place "X" amount of markers grouped to an object like a pencil and have that object run the script. I have been trying to get your script to work with just a marker or an object and can not. It creates a task and places a task marker in lower left corner of the map out in the ocean. I don't understand why it wont work. I used null = ["mrk1"] execVM "JSHK_hostages.sqf"; naming the object or marker "mrk1". I also tried it this way null = [mrk1] execVM "JSHK_hostages.sqf";

NVM

It was working with quotations with a marker but it is placing the hostages under the floor and behind the building. Is there a way to get an object to work since I can place multiple markers and group to object for random placement

Edited by mech79

Share this post


Link to post
Share on other sites

Change line 1 to:

[_this,0,objNull,[objNull]] call BIS_fnc_param;

And line 16:

_posNew = (getPosATL _marker);

Share this post


Link to post
Share on other sites
If you want to utilize a good randomization with predictable but not too repetitive results you should really look into selectBestPlaces.

That's my go-to command if I want to pick a random location that's not predefined on the map, it's extremely reliable and quick if you pick a high enough area to be scanned.

Further information here.

Quick example using world center position and world size to safely search the entire map for a fitting location:

_centerpos = getarray (configfile >> "CfgWorlds" >> worldName >> "centerPosition");
_size = getnumber (configfile >> "CfgWorlds" >> worldName >> "mapSize");
_randompos = selectBestPlaces [_centerpos, _size,"(3 + meadow) * (1 + houses) * (1 - sea)",250,8];

This would return up to 8 places on the entire map that are near a good amount of meadows, some houses and away from any water.

250 is, as I understand it the area in m² that is being scanned, setting this to a smaller value might return more accurate results but would also result in a significant fps drop.

Leaving it at 250, I never noticed this script, even going as low as 80 should be safe.

I use it to spawn ambient animals, outposts and other random stuff that shouldn't be spawned within towns.

Works on every map, no need to place markers.

Cheers

You could move a game logic around in a loop and have it search lots of smaller areas so you'll get more variety.

_num = 0;
logic = myLogic;
_centerpos = getarray (configfile >> "CfgWorlds" >> worldName >> "centerPosition");
while{_num < 15} do
{
  _Centerpos = [(getpos logic select 0) + random 100 - random 100,(getpos logic select 1) + random 100 - random 100,0]; //move it to a random spot
    _randompos = selectBestPlaces [_centerpos, 50,"(3 + meadow) * (1 + houses) * (1 - sea)",250,8]; //sample 50 meter areas
   _num = _num + 1;
   sleep 5;
};

Share this post


Link to post
Share on other sites

Ok this is slowly moving forward. I was able to group and object and have it randomly spawn in different locations. I then use a program that allows me to download intel and once done it activates a trigger which then runs both hostage script and AI spawn script.

Three things...

First- Jshock the new task is not appearing now that I am using an object. It was when using marker during testing phases any ideas?

Second- can I just change hostage name in script and have it loop for second object so a name conflict doesnt happen or is there an easier way to run our script twice for two different objects. I have setup a total of 12 possible places for Hostage to be, so I split that amount between two objects to make the mission a little longer. Any thoughts? Again thank you all for the info.

Third- The hostages are not always spawning in the buildings so I would like them to be seated instead of laying down unless you can think of why they are not always spawning in a buildings or houses

Share this post


Link to post
Share on other sites
You could move a game logic around in a loop and have it search lots of smaller areas so you'll get more variety.

That's weird. Why would you want to set the scan area to 50m while the selectBestPlaces is set to scan 250m?

By moving the position with random 100 - random 100 you'd achieve exactly nothing.

This would be totally counterproductive to the use of selectBestPlaces, since it already scans large areas for certain aspects.

If you want more variety in the results just run another selectBestPlaces command with a different expression parameter.

No need for spawning game logics, running while do loops with sleeps (good luck on waiting for a result there).

Edited by Grumpy Old Man

Share this post


Link to post
Share on other sites

Grumpy I couldn't get that script to work do you have like a sample mission or something. I can usually figure things out better once I see them in action of what they are supposed to do. Currently I have an object grouped to lots of markers for randomness. I tried using your code, but what is to supposed to produce exactly. I read that other link you sent but nothing there matched what you wrote so was a little confused. Thanks

Share this post


Link to post
Share on other sites
Grumpy I couldn't get that script to work do you have like a sample mission or something. I can usually figure things out better once I see them in action of what they are supposed to do. Currently I have an object grouped to lots of markers for randomness. I tried using your code, but what is to supposed to produce exactly. I read that other link you sent but nothing there matched what you wrote so was a little confused. Thanks

Paste this into the editors debug console and play around with it, you'll figure it out on your own, I'm sure.

_centerpos = getarray (configfile >> "CfgWorlds" >> worldName >> "centerPosition");
_size = getnumber (configfile >> "CfgWorlds" >> worldName >> "mapSize");
_result = selectBestPlaces [_centerpos, _size,"(3 + meadow) * (1 + houses) * (1 - sea)",250,1];player setpos ((_result select 0) select 0);

selectBestplaces always returns a nested array with position and precision value, that's why you need the ((_result select 0) select 0) part.

Cheers

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  

×