JacobJ 10 Posted March 30, 2011 Hello I have this script and it works fine, but I would like to have one script for hummer, one for helicopters (kind 1), one for helicopters (kind 2), one for hercules plane and one for trucks. So instead of having many scripts I just have one script that works for all vehicles of the same kind. Here is the original code: // If for some reason the ammo box is destroyed, don't try to load it and remove actions to load or unload. if (!alive mhq1_ammobox) then { hum1 removeAction hum1load; hint "Nothing to load!"; } else { // Since the box is still in one piece, make sure it's within 15m of the MHQ and the MHQ isn't on. if (hum1 distance mhq1_ammobox < 16 and !isEngineOn hum1) then { deletemarker "dropmark"; // Attach the box to the MHQ roof. mhq1_ammobox attachTo [hum1,[0,-1.5,-0.5]]; removeW = execVM "removeActionW.sqf"; waitUntil {scriptDone removeW}; // Change the action on the MHQ to unload the box now. hum1unload = hum1 addaction ["Unload ammobox from hummer", "detach_ammoboxhum1.sqf"]; } else { // If the box isn't within 15m or the engine is running, tell them they have to try again. hint "You must be within 15m of the ammo box, with your engine off, to load it!"; }; }; I guess I would need something with nearest object and some kind of telling the script what vehicle the script works for. How would I do this? Share this post Link to post Share on other sites
Reezo 45 Posted March 30, 2011 Something like this: _nearestCar = getPos player nearestObject "Car"; _YourObject attachTo _nearestCar; Should work..bear with me if I did not get exactly what you need..I tried to chime in and get you some help since there were no replies. Share this post Link to post Share on other sites
JacobJ 10 Posted March 30, 2011 And I am very glad for your help! I will try to mix something with this. Could I be more specific with the car-type? Share this post Link to post Share on other sites
Reezo 45 Posted March 30, 2011 Yes you can (lol @ that) ArmA is made of classes and sub classes..so for example if you use a specific HMMWV type it will not affect a Civilian Skoda car, but if you "bigger classes" or super-classes like "Car" it will affect a Skoda and an HMMWV and all cars in game. you could do something like this _nearVehicles = nearestObjects [player, ["Car","Tank"], 200];Player is the object marking the center for the area searchCar and tank are classes, you can use as many as you want200 is the area radiusThe above will create an array called _nearVehicles. This will contain all objects of those classes in the area with that specific center and radius.You can eventually select the array more specifically, using a FOR function and maybe isKindOf..but if you just want, example, all BLUFOR HMMWVs, just put all those classes in nearestObjects and you are set. Still, you can then manage the array with a lot of freedom.. Share this post Link to post Share on other sites
JacobJ 10 Posted March 30, 2011 How would I put all the BLUfor HMMWVs in that list? How do I specify what sides HMMWVs that should be in the list created in the _nearVehicles list? Share this post Link to post Share on other sites
Reezo 45 Posted March 30, 2011 How would I put all the BLUfor HMMWVs in that list? How do I specify what sides HMMWVs that should be in the list created in the _nearVehicles list? Replace "car" and "tank" with the HMMWVs class names, separate them by commas and use "" around them..there is a class name thread here, you can use it to get specific class names, because if you do not write them correctly ArmA will not understand them. http://forums.bistudio.com/showthread.php?t=73241 Share this post Link to post Share on other sites
PELHAM 10 Posted March 31, 2011 (edited) Added a bit to the above that might help. _run=true; _YourObject = _this select 0; while {_run} do{ sleep 1; _nearestCar = getPos player nearestObject "Car"; }; if (_nearestCar isKindOf "HMMWV_MK19") then { waitUntil {(player distance _nearestCar) < 2}; _YourObject attachTo [_nearestCar,[0,0,1]]; _run=false; }; if (_nearestCar isKindOf "HMMWV_M2") then { waitUntil {(player distance _nearestCar) < 2}; _YourObject attachTo [_nearestCar,[0,0,1]]; _run=false; }; //etc etc You might need to alter the position of the ammo box depending on vehicle config - change the coordinates in each of the attachTo's. http://community.bistudio.com/wiki/ArmA_2:_CfgVehicles Hope this is of use. Edited March 31, 2011 by PELHAM add info Share this post Link to post Share on other sites
JacobJ 10 Posted March 31, 2011 Thanks very much, ill try this out as soon as I get home. That def. helps a lot! Share this post Link to post Share on other sites
JacobJ 10 Posted March 31, 2011 Okay Ive tried the code you have posted and I can't get it to work. Nothing happens. Ive changed the HMMWV_MK19 to HMMWV and ive changed player to ammobox, but it just won't load the box. What could I have done wrong? ---------- Post added at 10:38 ---------- Previous post was at 10:04 ---------- Okay now I got it to work. But another problem came up. If you have two vehicles of the same type within the range of lets say 10 meters, then it isnt sure that the box will be loaded to the vehicle that you want it to. How can I somehow do that? Here is my code: _nearestCar = getPos ammobox nearestObject "car"; if ((_nearestCar isKindOf "HMMWV") && ((ammobox distance _nearestCar) < 10) && (!isEngineOn _nearestCar)) then { ammobox attachTo [_nearestCar,[0,0,1]]; } else { hint "You are too far away or your engine is running"; }; Share this post Link to post Share on other sites
PELHAM 10 Posted March 31, 2011 [/color]Okay now I got it to work. But another problem came up. If you have two vehicles of the same type within the range of lets say 10 meters, then it isnt sure that the box will be loaded to the vehicle that you want it to. How can I somehow do that? That sort of script may not work properly for 2 objects of the same type parked close together and for larger distances than the dimensions of the vehicle. As you say there is chance of confusion. Either: -reduce the distance to 1 or 2m -make sure that 2 of the same type don't approach closer than your distance -name the vehicles and rewrite the script so that it selects names instead of types. eg: (ammobox distance namedCar) < 10 Can't think of anything else - sorry. :( Share this post Link to post Share on other sites
JacobJ 10 Posted March 31, 2011 Okay, so I am back where I started basicly. I need two scripts for each vehicle, one to attach and one to detach the ammobox. Share this post Link to post Share on other sites