Jump to content
Sign in to follow this  
gnarly_rider

Randomising the location of the createmarker (or getpos?) command a little?

Recommended Posts

As always, searched and found lots of ways of randomising say the placement of a AA unit to 5 different marker locations, using grouping.

Players have to find the AA, but need to talk to civis to do so. Eventaully civis give the location away, using this code (the AA unit is called AA2):

_AA2pos = getpos AA2;
_marker = createMarker ["AA2mark", _AA2pos];
_marker setMarkerShape "ELLIPSE";
"AA2mark" setMarkerSize [200, 200];
"AA2mark" setMarkerColor "ColorRed";
"AA2mark" setMarkerText "AA in this area";

Problem is that the ellipse is centred on the AA2 placement. How do I randomly alter the X and Y coordinates of _AA2pos by say +/- 100m? So ellispe still encompasses AA2 position, but the players still have to search the ellipse marker area to find it (not just beeline for the centre)?

Edit: I don't want to have to place another 5 say markers around the AA2 site, and then randomise the setmarker to these, as my intial AA2 marker's location is already randomised in the same way! ie for 4 random AA sites, I do not want ot end up with 20 total marker locations!

Edited by gnarly_rider

Share this post


Link to post
Share on other sites

Something like :

_dis = 100;
_cooX = (getpos AA2 select 0);
_cooY = (getpos AA2 select 1);
_wheX = random (_dis*2)-_dis;
_wheY = random (_dis*2)-_dis;
_AA2RandomPos = [_cooX+_wheX,_cooY+_wheY,0];
_marker = createMarker ["AA2mark", _AA2RandomPos];
_marker setMarkerShape "ELLIPSE";
"AA2mark" setMarkerSize [200, 200];
"AA2mark" setMarkerColor "ColorRed";
"AA2mark" setMarkerText "AA in this area";

Share this post


Link to post
Share on other sites

Awesome Prof, glad I didn't try researching that all myself, I'll give it a go!

Edit: Sweet as, works bewdifully!

Edited by gnarly_rider

Share this post


Link to post
Share on other sites

ProfTournesol your solution works great as well when tying createVehicle at randomized marker. However I'm adding isFlatEmpty so the newly created Radar tower at the randomized marker doesn't spawn in trees on Chenarus.

I have place an invisible Helipad in the center of the map and named it "makemarker".

In the Initialization field I have: nul = [] execVM "Scripts\RandomMarker.sqf";

//RandomMarker.sqf
//Create Random marker in empty flat area used for placement of tower within 4200 meters of invisible Helipad named "makemarker"
//if !(isServer) exitwith {};	
//Syntax: position isFlatEmpty [float minDistance,float precizePos,float maxGradient,float gradientRadius,float onWater,bool onShore,object skipobj]

_dis = 4200;
_cooX = (getPos makemarker select 0);
_cooY = (getPos makemarker select 1);
_wheX = random (_dis*2)-_dis;
_wheY = random (_dis*2)-_dis;
_TskmarkerRandomPos = [_cooX+_wheX,_cooY+_wheY,0];
_newPos = (getPos _TskmarkerRandomPos) isFlatEmpty[50, 1, 0.7, 5, 0, false, player]; //isFlatEmpty when given position _pos should return a flat and empty area close by if it can. If it cannot it returns an empty variable presumably. You may want to alter the values inside the square brackets.
while {(count _newPos) < 1} do {//Loop the following code so long as isFlatEmpty cannot find a valid position near the current _TskmarkerRandomPos.
_newPos = (getPos _TskmarkerRandomPos) isFlatEmpty[50, 1, 0.5, 10, 0, false, player];
};
_marker = createMarker ["varimarker", _newPos];
_marker setMarkerShape "ELLIPSE";
"varimarker" setMarkerSize [1, 1];
"varimarker" setMarkerShape "ICON";
"varimarker" setMarkerType "DOT";
"varimarker" setMarkerColor "ColorRed";
"varimarker" setMarkerText "Tower is here";
publicVariable "varimarker";
sleep 0.5;

//Create Tower at random marker "varimarker"

_Target = createVehicle ["RU_WarfareBAntiAirRadar",  (getMarkerPos "varimarker"), [], 0, "NONE"]; 

sleep 0.5;

//Make Tower Destroyable by bombs and rockets only
//_Target allowDamage false;
_Target addEventHandler ["handleDamage", {
if ((getText(configFile >> "CfgAmmo" >> (_this select 4) >> "simulation") in ["shotMissle", "shotRocket"]) then {_Target setdamage .4} else {_Target setdamage 0};
hint "The radar tower objective has moved";

By adding the isFlatEmpty, it seams the script never completes.

What to do?

Share this post


Link to post
Share on other sites

isFlatempty can on occassion return nothing if there just isn't a space in the assigned radius where it should look.

You've only allowed it to look in the space of 1 meter I think and you've asked for it to have a minimum distance of 50 meters from any object which is unlikely in a forest:

_newPos = (getPos _TskmarkerRandomPos) isFlatEmpty[50, 1, 0.5, 10, 0, false, player];

Try:

_newPos = (getpos _TskmarkerRandomPos) isflatempty [2,50,1,2,0,false,player];

Share this post


Link to post
Share on other sites

Thank you Rejenorst

You helped clarify isFlatEmpty. I wound up with 20 float minDistance (Minimal distance from another object) and 200 for float precisePos (select new position within 200 meters).

The fisrt check is:

_newPos = (getPos _TskmarkerRandomPos) isFlatEmpty [20,50,0.7,2,0,false,player]

The second check if 0 is returned is:

_newPos = (getPos _TskmarkerRandomPos) isFlatEmpty [20,200,1,2,0,false,player]

I was missing a space between isFlatEmpty and [.

This is working great for Chernarus. It places the tower in an open area every time making it easier to find by player aircraft. Now need to figure out how to let the server handle event handler for alive "TowerObjective" and let the clients do syncing of the new tower position maybe. There is a new problem now. When the tower is destroyed it does not respawn to a new location like it was before adding isFlatEmpty. Randomization is gone. If I add this to the end of the script:

if !(alive _Target) then loop=true else loop=false;

Then the tower responds in the same place give or take a couple of meters.

Edited by Jigsor

Share this post


Link to post
Share on other sites

Nevermind, I've figured it out

I Removed nul = [] execVM "Scripts\RandomMarker.sqf"; from Invisible Helipad.

I then made a triger to start script once at game start.

Axis a: 0
Axis b: 0
Activation: anybody, once, Not Present
Type: none
Name: rantowertrig,
Condition: this;
On Act: nul = [] execVM "Scripts\RandomMarker.sqf"

I made a second trigger

Axis a: 1
Axis b: 1
Activation: none, repeatedly
Type: none
Condition: this; !alive TowerObjective;
On Act: targetsdead=true; publicVariable "targetsdead"; Hint "Radar Tower Destroyed";
deleteMarker "varimarker"; deleteVehicle rantowertrig; nul = [] execVM 	"Scripts\RandomMarker.sqf"

I ended up with is slightly modified script although localization is untested.

//Create Random marker in empty flat area used for placement of tower within 5000 meters of invisible Helipad "makemarker"
//Syntax: position isFlatEmpty [float minDistance,float precizePos,float maxGradient,float gradientRadius,float onWater,bool onShore,object skipobj]
sleep 0.2;
if !(isServer) exitwith {};	
_dis = 5000;
_cooX = (getPos makemarker select 0);
_cooY = (getPos makemarker select 1);
_wheX = random (_dis*2)-_dis;
_wheY = random (_dis*2)-_dis;
_TskmarkerRandomPos = [_cooX+_wheX,_cooY+_wheY,0];
_newPos = _TskmarkerRandomPos isFlatEmpty [20,50,0.7,2,0,false,player]; //isFlatEmpty when given position _pos should return a flat and empty area close by if it can. If it cannot it returns an empty variable presumably. You may want to alter the values inside the square brackets.
while {(count _newPos) < 1} do {//Loop the following code so long as isFlatEmpty cannot find a valid position near the current _TskmarkerRandomPos.
_newPos = _TskmarkerRandomPos isFlatEmpty [20,200,1,2,0,false,player];
};
_marker = createMarker ["varimarker", _newPos];
_marker setMarkerShape "ELLIPSE";
"varimarker" setMarkerSize [1, 1];
"varimarker" setMarkerShape "ICON";
"varimarker" setMarkerType "DOT";//make marker invisible later maybe
"varimarker" setMarkerColor "ColorRed";
"varimarker" setMarkerText "Tower in this area";
publicVariable "varimarker";
sleep 0.5;

//Create Tower at random marker "varimarker"
_Target = createVehicle ["RU_WarfareBAntiAirRadar", (getMarkerPos "varimarker"), [], 0, "NONE"];
sleep 0.5;
//Assign a variable to an object and be able to refer to that object using the variable, in both single and multi player.
_VarName="TowerObjective";
_Target SetVehicleVarName _VarName;
_Target Call Compile Format ["%1=_This ; PublicVariable ""%1""",_VarName];
sleep 0.2;
//Make Tower Destroyable by bombs and rockets only
_Target addEventHandler ["handleDamage", {
if ((getText(configFile >> "CfgAmmo" >> (_this select 4) >> "simulation") in ["shotMissle", "shotRocket"]) then {_Target setdamage .4}, (_Target allowDamage true) else {_Target setdamage 0}, (_Target allowDamage false);
{
if (!alive _Target) then
{
exitwith[];

This way the script runs once every time the tower is destroyed.

Thanks again.

Edited by Jigsor

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  

×