Lucky44 13 Posted June 13, 2010 I've searched all over and can't find anything close to this. (That probably means I'm going about it all wrong!) All I want to do is find the nearest PLAYER to an object. I've got an Action on the object, and when a player "uses" the object/action, I want to play (force) an animation on the player. I know how to do the animation, but I am having trouble finding the player unit name. What am I missing? Thanks in advance. Share this post Link to post Share on other sites
Jelliz 10 Posted June 13, 2010 Getnearestobject can only find types(classes). The AI wont use the action unless called by a script. So you could probably use _myobject = nearestObject [objectname, "Man"]; Although i am lazy and havent tested this. Share this post Link to post Share on other sites
Lucky44 13 Posted June 13, 2010 (edited) Getnearestobject can only find types(classes). The AI wont use the action unless called by a script. So you could probably use_myobject = nearestObject [objectname, "Man"]; Although i am lazy and havent tested this. OK, thanks. I'll try that. EDIT: that works, so far. I'm only worried about whether any other unit that's a "man" could be closer and mess things up. Can you not use "player" as a class? Edited June 13, 2010 by Lucky44 Share this post Link to post Share on other sites
Jelliz 10 Posted June 13, 2010 (edited) see here The player isnt a class, but i might work. But you can also browse the classnames provided in the link above, and change the classname to the same as the player. Like if the player is an insurgent medic, it would be _myobject = nearestObject [objectname, "Ins_Soldier_Medic"]; . It would reduce the risk of other AI interfering.(In this example, only an AI insurgent medic wich is closer to the object than the player, could ruin the addaction.)But this solution is not the optimal overall, i hope someone else chimes in with a better solution. But this will work, just with a risk of occasional fuckups. Edited June 13, 2010 by Jelliz Share this post Link to post Share on other sites
Lucky44 13 Posted June 13, 2010 OK, thanks. I am making this for just 4 (possible) players, so I could give them names and do 4 "if" statements. On the other hand, maybe I'm worried unnecessarily. What I'm doing is "breaking down" a static MG to load it for transport. Maybe the closest unit to the MG is the one who should be doing the work anyway! (But I would like to know the easiest/safest way to find the closest PLAYER to an object anyway!) Share this post Link to post Share on other sites
wokstation 0 Posted June 13, 2010 Reference all the players in an array, and then check the object found against the array? eg... _myobject = nearestObject [objectname, "Man"]; if (_myobject in MyBigArrayOfPlayers) then { // Pop your codey stuff here }; Share this post Link to post Share on other sites
f2k sel 164 Posted June 14, 2010 You say you have an action on the object, if so why not use that to identify the man. _obj = _this select 0; _man = _this select 1; Share this post Link to post Share on other sites
Lucky44 13 Posted June 15, 2010 You say you have an action on the object, if so why not use that to identify the man._obj = _this select 0; _man = _this select 1; OK, would those two lines go in the script called by the action? I'm just not clear on what "_this" will refer to here. ---------- Post added at 04:31 PM ---------- Previous post was at 04:25 PM ---------- Reference all the players in an array, and then check the object found against the array?eg... _myobject = nearestObject [objectname, "Man"]; if (_myobject in MyBigArrayOfPlayers) then { // Pop your codey stuff here }; That looks like an interesting approach to check to see if the "man" involved is a player. I can use that some places. Thanks. Share this post Link to post Share on other sites
f2k sel 164 Posted June 15, 2010 If your using addaction to call the script putting those two lines in the script will return both the object and the user. Read down the page a little for more info. http://www.ofpec.com/COMREF/index.php?action=details&id=5&game=All Share this post Link to post Share on other sites
[frl]myke 14 Posted June 15, 2010 OK, would those two lines go in the script called by the action? I'm just not clear on what "_this" will refer to here. The variable "_this" at the beginning of the script always refer to the passed variables. Mostly when calling a script you have a line like this: nul = [here, there, anywhere] execVM "anyscript.sqf" The square brackets part is an array holding several variables. Those are passed to the script. _var1 = _this select 0; _var2 = _this select 1; _var3 = _this select 2; These lines does read the variables out of the passed array. You could also just read the array and split it up inside the script: _myArray = _this; _var1 = _myArray select 0; _var2 = _myArray select 1; _var3 = _myArray select 2; The result is that _var1 to _var3 now holds the parameters passed by the scriptcall. In case of using a action, a array is passed by default containing who is the owner of the action (was attached to via addAction) and who finally activated the action. so: _unit = _this select 1; will always refer to the unit that used the action. Share this post Link to post Share on other sites
Lucky44 13 Posted June 15, 2010 Thanks F2k_Sel and Myke for taking the time to help with that. I get it now. I'm still just learning coding, and I love it! I just wish I knew more. -Practice practice practice! Share this post Link to post Share on other sites