lemondragon 10 Posted November 5, 2013 Hey there everyone, I encountered a problem while scripting. I want the command "nearestObject" to return the nearest car, armored vehicle or helicopter, and then move my "hostage" in to the cargo of that vehicle. I'm using the following code: _carobject = nearestObject [player, "Car"]; _armobject = nearestObject [player, "Armored"]; _airobject = nearestObject [player, "Air"]; if(((_target distance _carobject) < 10)) then { _target moveInCargo _carobject; }; //same 'if' statement for the other 2 var's. This code, unfortunately, does not work. I personally think it has something to do with the classnames (Car, Armored and Air). Is someone able to help me out? Share this post Link to post Share on other sites
das attorney 858 Posted November 5, 2013 You could get the results like this: _unsorted = (position player) nearEntities [["Air", "Car", "Armored"], 200]; Then sort the array into closest > furthest away _sorted = []; _pos = getPos player; { _closest = _unsorted select 0; {if ((getPos _x distance _pos) < (getPos _closest distance _pos)) then {_closest = _x}} forEach _unsorted; _sorted = _sorted + [_closest]; _unsorted = _unsorted - [_closest] } forEach _unsorted; Then ONLY IF the vehicle has cargo positions, then move _target in. for "_i" from 0 to count _sorted - 1 do { _veh = _sorted select _i; _cargo = _veh emptyPositions "cargo"; if (_cargo > 0) exitWith {_target moveInCargo _veh}; }; Untested but should work. (I'm at work so the usual disclaimers apply). You might want to see if "Armored" is a class in the config browser - I know "Tank" is so you could could sub that in instead. Share this post Link to post Share on other sites
lemondragon 10 Posted November 5, 2013 (edited) It works for the car, so I guess the "Armored" and "Air" class name are wrong. I tried finding the actual class names in the config browser, but I didn't get any wiser. Edit: I replaced the three class names with "All", it delivers the wished result since the script already checks if the vehicle has a cargo slot. Thanks a lot for the help :D Edited November 5, 2013 by lemondragon Share this post Link to post Share on other sites
das attorney 858 Posted November 5, 2013 Select a random vehicle in the Config Browser, then look in the "parents" box in Config Browser and it will tell you what the classes are derived from. (For example "Air, "CAManBase", "Tank" etc) FYI, just to make sure the unit goes where he is supposed to, you may want to assignAsCargo before moveInCargo as well. :) Share this post Link to post Share on other sites
lemondragon 10 Posted November 5, 2013 (edited) I'm stuck again, I'm trying to update the nearest vehicle every time/second, so I can let a 'addaction' pop up (which the player can use to put the hostage in the vehicle) whenever the player is near a vehicle. I tried to put everything in a WHILE loop, tried partly moving bits of code around, etc, etc. well I tried a lot, I've cracked my brain on it the last ~2 hours, but I can't figure it out. Edit: Again, After much effort I managed to get it working. Thanks for all the help Das Attorney :D Edited November 6, 2013 by lemondragon Share this post Link to post Share on other sites