Jump to content
  • 0

Get a players name near an object


Guest

Question

I'm trying to get the name of a player that loots a crate. This doesn't work but it might help to show what I'm trying to do: 

 

 _playerAtCrate = name (nearestObject [player, "USOrdnanceBox"]);

 

Anyone have any ideas? 

 

Thanks

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

I'm trying to get the name of a player that loots a crate. This doesn't work but it might help to show what I'm trying to do: 

 

 _playerAtCrate = name (nearestObject [player, "USOrdnanceBox"]);

 

Anyone have any ideas? 

 

Thanks

first some advice:

obviously you do not know Arma engine and all its 5K commands and potential outputs by heart (BIKI is not always enough) what a surprise - me too!

lacking 100% knowledge of the engine, what I do is, making the engine report what it sees - after a bit of back and forth messaging with the engine, we usually tend to find common ground in the end.

and if nothing helps, gurus like axeman, face, then tend to help.

they won't come down for your question for example because it is something you can find by googling OR debug outputting yourself (not to bash you).

 

if you don't like devdebug'ing, posting in the forums is obviously helpful but the resolution speed would be much quicker if you talk to the engine directly, just like this debug output below.

 

 

now on the immediate issue: did you try splitting the problem to two?  if not, perhaps give it a try -- what do you see when you try this below:

_playerAtCrate = nearestObject [player, "USOrdnanceBox"];
diag_log format ["   [DEVDEBUG]   (_playerAtCrate) is: (%1).", (str _playerAtCrate)];

The above output will answer your question.

 

To give you some immediate pointers:

  1. are you aware that nearestObject (the way you use it) will only return matches up to 50 metres radius?
  2. are you also aware that even if there is only one 'hit', resulting player will be the sole member of an array thus your name command will fail anyhow just because name expects an object as the input whereas you're giving it an array. so please consider 'SELECT'ing the first object in your searchResultsArray  [which is item ID ZERO], just like this guy did back in 2009 then will serve you well.

 

Good luck!

 

P.S. Once you fix it, consider taking the moment to post your working code and marking this as RESOLVED so that the next guy (possibly 6 years later again) can find his answer without reading a book from someone like me lol

Link to comment
Share on other sites

  • 0

Hi,

 

for some reason i'm pretty sure you did not understand a word, that mgm said (i don't want to sound rude or unfriendly tho!)..

So what he means is:

  • Always add some debugging Information's to your script, so you can see what part works and what does not...
  • If something is not working the way it should, consider searching on how that function exactly works

 

However, i think what you want is something more like this:

private["_position","_nearBox","_nearBoxCount","_playerName"];

//First we need the Position of the Box (alternatively = _position = getPosATL _box)
_position = [123,456,789];

//Get an array of near Objects
_nearBox = nearestObjects [_position, ["USOrdnanceBox"], 50];

//Check, if _nearBox has some Value
if(!isnil "_nearBox") then {

	//Count the Values of the array _nearBox
	_nearBoxCount = (count _nearBox);
	
	//Check, if it counted more then 1 Entry
	if (_nearBoxCount >= 1) then {
	
		//Do this Loop for each array Entry
		{
			//Is the Entry a Player?
			if(isPlayer _x) exitWith {
				//Get the Player Name
				_playerName = name _x;
			};
		} foreach _nearBoxCount;
			
	};
};

Note: This is NON- TESTED and NON- OPTIMIZED. For a large knowledge of how to optimize code, visit the Bistudio Post for Code Optimization.

 

Link to comment
Share on other sites

  • 0

Hi,

 

for some reason i'm pretty sure you did not understand a word, that mgm said (i don't want to sound rude or unfriendly tho!)..

So what he means is:

  • Always add some debugging Information's to your script, so you can see what part works and what does not...
  • If something is not working the way it should, consider searching on how that function exactly works

 

However, i think what you want is something more like this:

private["_position","_nearBox","_nearBoxCount","_playerName"];

//First we need the Position of the Box (alternatively = _position = getPosATL _box)
_position = [123,456,789];

//Get an array of near Objects
_nearBox = nearestObjects [_position, ["USOrdnanceBox"], 50];

//Check, if _nearBox has some Value
if(!isnil "_nearBox") then {

	//Count the Values of the array _nearBox
	_nearBoxCount = (count _nearBox);
	
	//Check, if it counted more then 1 Entry
	if (_nearBoxCount >= 1) then {
	
		//Do this Loop for each array Entry
		{
			//Is the Entry a Player?
			if(isPlayer _x) exitWith {
				//Get the Player Name
				_playerName = name _x;
			};
		} foreach _nearBoxCount;
			
	};
};

Note: This is NON- TESTED and NON- OPTIMIZED. For a large knowledge of how to optimize code, visit the Bistudio Post for Code Optimization.

lol thanks very much Martin! :)

 

Good job providing source code though.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Discord

×
×
  • Create New...