Jump to content
Sign in to follow this  
A-SUICIDAL

Need help checking for specific objects near player

Recommended Posts

In my mission the leader can deploy a Rally Point, which is used so other players can teleport to the Rally Point from base flag. When the Leader chooses the action to deploy the Rally Point, a dialog appear asking "Deploy Rally Point?" with "Yes" and "No" choice buttons to choose from. This prevents the leader from accidentally choosing the action to deploy the Rally Point in an area that he or she would rather not have, which is very helpful considering that there is also a 10 minute wait time before the leader can deploy a new rally point. I have already added a system that checks to make sure certain conditions are met before the Rally Point can be deployed. These are as follows:

if (alive s1 and rallyCountdownActive) exitWith {

hint rallyTimerMsg; // for example "Rally Point Unavailable (line break) 00:08:42 remaining before a new Rally Point can be deployed."
rallyDeployAttempt=false;
publicVariable "rallyDeployAttempt";
};

if (((getPosATL s1) select 2) >1) exitWith {

hint "You must deploy the Rally Point at ground level.";
rallyDeployAttempt=false;
publicVariable "rallyDeployAttempt";
};

if (s1 distance base_center <500) exitWith {

hint "You cannot deploy the Rally Point within 500 meters of base.";
rallyDeployAttempt=false;
publicVariable "rallyDeployAttempt";
};

_list= position s1 nearObjects ["ALL",5.5];
if (count _list > 1) exitWith {

hint "There are objects or players in the way. Find a clear 6 meter radius to deploy the Rally Point.";
rallyDeployAttempt=false;
publicVariable "rallyDeployAttempt";
};

So my problem is... sometimes when I choose to deploy the Rally Point, it tells me that there are objects in the way, when there are not, at least nothing that I can see other than myself and some grass. So I want to check for specific object types, but I am not sure what I should add to the list of objects types to check for, or if maybe the check should be done using some sort of array. There have been other times when there were objects within 6 meters of my position, like a long wall for example, and yet it did allow me to go ahead and deploy the Rally Point, which also didn't make much sense to me.

Lastly, I wasn't sure if maybe I should be checking for any other conditions, but if you can think of anything I have left out that I should be checking for, please let me know. Sorry for the long explanation, I just want to get this working perfectly.

Share this post


Link to post
Share on other sites

nearobjects could be finding stuff you might not be expecting. For eaxmple, giving it "ALL" as a parameter will find pollen, bees, flies and triggers.

---------- Post added at 18:41 ---------- Previous post was at 18:31 ----------

Also, would the isflatempty command be any use?

http://community.bistudio.com/wiki/isFlatEmpty

Share this post


Link to post
Share on other sites

Yeah, I figured that. What object types should I be checking for? I figured buildings, but I also do not want rocks, trees, bushes in the way either. Players can be in the way, that shouldn't matter much. But what else should be added to the list that I'm not thinking of and where can I find a list of object types so I can add the exact names for these things?

Share this post


Link to post
Share on other sites

Mmm, that's tricky. I'm not at home right now so can't familiarise myself with exactly what is finds and what it doesnt. I did write some stuff on the biki. As far as I can remember, it won't find rocks.

Have you considered using clutter cutters to remove grass and bushes?

Share this post


Link to post
Share on other sites

Clutter cutter would probably not help much except to maybe make clearing after the Rally Point has been deployed.

I was just looking at the wiki for "nearEntities" and I thought maybe that might be an option, instead of using "nearObjects".

One of the wiki examples looked like this:

_list = (position player) nearEntities [["Man","Air","Car","Motorcycle","Tank"],200];

Maybe remove "Man" and add to it "House", "Tree". Rocks might not be a good thing to detect for since I wouldn't want a tiny rock to prevent the player from deploying the Rally Point, you also said that it won't find rocks anyway, so I guess trying to detect a rock nearby is pointless.

---------- Post added at 01:26 PM ---------- Previous post was at 12:15 PM ----------

So far this seems to work, but it doesn't detect most editor placed objects that are in the way, like tents, ammo crates, H-Barrier walls. I also would like it to detect if trees are in the way. Is there any possible way to detect these things? I set the detection radius a little bigger since the Rally Point was colliding with some tanks after it was deployed too close.

_list = nearestObjects [s1, ["House","Air","Car","Motorcycle","Tank"],8];

Share this post


Link to post
Share on other sites

_list =  nearestObjects [this, ["Thing","AllVehicles","building"],8]

That should return more objects such as barrier and ammo crates and furniture

You can detect trees, bushes and rocks it's just difficult to do anything with the info as it also returns feathers and bees ect.

example

_list = nearestObjects [this, [],8]

returns

[tim,

NOID stopa_l.p3d,

17750: honeybee.p3d,

17716: fly.p3d,

17756: mosquito.p3d,

17758: fly.p3d,

17753: honeybee.p3d,

15572: t_pinusn1s.p3d,

NOID stopa_p.p3d,

17754: mosquito.p3d,

17761: fly.p3d,

17763: honeybee.p3d,

17764: honeybee.p3d,

15575: t_pinusn1s.p3d,

17762: honeybee.p3d,

17749: mosquito.p3d,

NOID stopa_l.p3d,

15534: t_betula2s.p3d,

15574: t_pinusn1s.p3d,

NOID stopa_p.p3d,

NOID stopa_l.p3d]

You could write a function to look for specific letters and if you find them stop the deployment.

trees are t_ and bushes b_ and r2_ for rocks and probably more

Edited by F2k Sel

Share this post


Link to post
Share on other sites

I tried what you said and used:

_list =  nearestObjects [this, ["Thing","AllVehicles","building"],8]  

.. and it works great. Thank you so much. As far as writing a function to look for specific letters, I don't know how to do that. I didn't even know that was possible. Trees and bushes are the only things left that might cause problems. Large rocks might be a problem too, but I don't think it would be possible to detect whether a rock is tiny or very large. Obviously tiny rocks shouldn't cause any problems. Is there a sample script somewhere that I could study that shows how to write a function that looks for specific letters? It would be nice to add trees and bushes to the list.

Share this post


Link to post
Share on other sites

Large rocks are a problem to check because the centre position could be outside the range your checking so wouldn't be picked up.

Small rocks have a different name anyway. I did just did a quick test and it does pick up a few things but I wouldn't say it's reliable, it seems to give a few false positives.

create an init.sqf

FNC_instring = compile preprocessFileLineNumbers "instring.sqf";

this would run after you do the current check for buildings ect and if clear run a final check for clutter

_return= false;// it returns true if it finds what it's after
_clutter = str  nearestObjects [player, [],8];// find clutter
{
_return=[_clutter,_x] call FNC_instring  ;
} foreach  ["t_","b_","r2","cl_r","pow"] ;// serach for letters in "string"
if  !(_return)  then {  //deploy };

save as instring.sqf

// place this nect lin in init.sqf
//FNC_instring = compile preprocessFileLineNumbers "instring.sqf";
//
// save file as instring.sqf
//
// ret=[array,"search"] call FNC_instring // ret = true/false

private ["_count","_inc","_result"];
_count = 0;
_inc = 0;
_result = false;

_array = toArray   (_this select 0); // string
_sizearray = count _array;

_find = toArray  (_this select 1); // find
_sizefind = count _find;


for "_i" from 0 to _sizearray-1 do
{
_letter = _array select _i;

If (_letter == (_find select 0) and _sizearray-_i >= _sizefind   ) then {

  for "_i" from 0 to _sizefind-1 do
{
if (_array select _i+_inc == _find select _i) then {
	_count = _count +1} else {_count=0}; 
};
 };
 if (_count == _sizefind) then {_result = true;};
_inc=_inc+1;
};	
_result

This was really written to help me identify pilots,crew or medics so I could lock them out of vehicles depending on their type without having to make arrays of units.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

First I just want to thank you for the omg amazing help you gave me. Very impressive stuff. I'm testing it now. I'm not sure what "cl_r" and "pow" are. I'm guessing that cl_r is some kind of rock and pow probably works for power line poles, power generators, power plants, power stations etc.

I created a test mission and placed 1 man named "s1" and a functions module.

I added a repeat trigger radio juliet to activate a shortened version of the script.

null = [s1] execVM "deploy_rally.sqf";

I created an init.sqf and put this in it:

FNC_instring = compile preprocessFileLineNumbers "instring.sqf";

I created an instring.sqf file and copy and pasted exactly what you had above.

// place this nect lin in init.sqf
//FNC_instring = compile preprocessFileLineNumbers "instring.sqf";
//
// save file as instring.sqf
//
// ret=[array,"search"] call FNC_instring // ret = true/false

private ["_count","_inc","_result"];
_count = 0;
_inc = 0;
_result = false;

_array = toArray   (_this select 0); // string
_sizearray = count _array;

_find = toArray  (_this select 1); // find
_sizefind = count _find;


for "_i" from 0 to _sizearray-1 do
{
_letter = _array select _i;

If (_letter == (_find select 0) and _sizearray-_i >= _sizefind   ) then {

  for "_i" from 0 to _sizefind-1 do
   {
   if (_array select _i+_inc == _find select _i) then {
       _count = _count +1} else {_count=0}; 
};
 };
 if (_count == _sizefind) then {_result = true;};
_inc=_inc+1;
};    
_result

Then I created a deploy_rally.sqf and only added this to it:

_return = false;
_clutter = str nearestObjects [s1, [],8];
{
_return=[_clutter,_x] call FNC_instring;
} foreach  ["t_","b_","r2","cl_r","pow"];

if !(_return) then {

hint "Area clear. There are no trees, bushes, rocks in the way. That goes for whatever cl_2 and pow are too. Deploying Rally Point...";
} else {
hint "The area is not clear. There are trees, rocks or bushes in the way. Find a clear 8 meter radius to deploy the Rally Point.";
};

Finally I previewed it and ran up to bushes, trees, rocks, power line poles and activated the trigger and it always told me that the area was clear when it was not. So I'm not sure what I am doing wrong.

---------- Post added 01-23-2013 at 01:21 AM ---------- Previous post was 01-22-2013 at 11:28 PM ----------

I just noticed when trying to use this...

_list = nearestObjects [s1, ["Thing","AllVehicles","building"],8];

...to detect if a building was within 8 meters of the player - that on most occasions it would not detect big buildings even if I was standing right up against the side of a building, but if I entered the building and stood in the center of it, it would then detect that the building was within 8 meters. It's almost as if some big buildings have a detectable radius no bigger than a skinny pole. I thought I could detect the actual collision points of the buildings, but instead I only seem to be able to detect the most central placement position of most big buildings.

I still can't get it to detect the trees, bushes etc.

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

I'll check later to see why the script isn't working, I changed a few things when posting.

The second issue sounds like the same problem with the large rocks that i noticed, you could ad an extra nearestobjects to detect houses but give it a larger radius

_list = nearestObjects [s1, ["Thing","AllVehicles","building"],8];

_list2 = nearestObjects [s1, ["houses"],16];

_newlist=_list + list2;

Share this post


Link to post
Share on other sites

I've used similar tactics to F2k Sel. You often have to do more than one search with these commands, or combine the different near* commands, such as nearestBuilding, nearestObject, etc and bundle the results into another array, then filter the junk out of that before you get something useful.

Share this post


Link to post
Share on other sites

The first script was working except that it was only returning the sate of the last Item and if it had found that one or not.

I just needed to and an exit for and a variable

// player addaction ["Deploy","deploy_rally.sqf"];


_found = false;
_clutter = str nearestObjects [s1, [],8];

{
_return = [_clutter,_x] call FNC_instring;
if (_return ) then {_found = true}; // I'd like to end this when true but I don't know how...
} foreach  ["t_","b_","r2","cl_r","pow"];

if (_found ) then {
hint "The area is not clear. There are trees, rocks or bushes in the way. Find a clear 8 meter radius to deploy the Rally Point.";

} else {
hint "Area clear. There are no trees, bushes, rocks in the way. That goes for whatever cl_2 and pow are too. Deploying Rally Point...";

};

And yes POW and CL_R are rocks and powerlines..

Anyone now how to end { code } foreach the code within foreach brackets when I get the result I'm after ?

Share this post


Link to post
Share on other sites

...to detect if a building was within 8 meters of the player - that on most occasions it would not detect big buildings even if I was standing right up against the side of a building, but if I entered the building and stood in the center of it, it would then detect that the building was within 8 meters. It's almost as if some big buildings have a detectable radius no bigger than a skinny pole. I thought I could detect the actual collision points of the buildings, but instead I only seem to be able to detect the most central placement position of most big buildings.

So the building 'detection point' is at it's centre. Not very useful for large objects like buildings. Perhaps sizeOf or boundingBox might be useful here.

http://community.bistudio.com/wiki/sizeOf

http://community.bistudio.com/wiki/boundingBox

I can't remember when or why, but the last time I used boundingBox, it didn't work as expected, so your mileage may vary.

Share this post


Link to post
Share on other sites

The problem with bounding box is that it creates a box and the building fits into that box rather than follow the exact shape of the building.

Share this post


Link to post
Share on other sites

Yes, boundingBox is better for vehicles that are more square in their plan view and sizeOf is even worse as it returns the size only of it's x dimension, but it might be that it's the best we have under the circumstances.

Share this post


Link to post
Share on other sites
_list = nearestObjects [this, ["Thing","AllVehicles","building"],8]

Is there a list somewhere of these keywords?

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  

×