PDA

View Full Version : addaction to every vehicle in map?



zooloo75
Jul 3 2011, 02:13
How do I add an action to every vehicle in the map without putting it in each of their init lines?

vehicle addaction["CL:Access Gear","gearbox.sqf"];

^ does nothing.

kylania
Jul 3 2011, 02:23
You'd assign them with a forEach loop in your init.sqf. Or maybe just add it to the player. This post (http://forums.bistudio.com/showpost.php?p=1863205&postcount=2) has an example for that kind of thing.

Demonized
Jul 3 2011, 13:38
you can use the command vehicles (http://community.bistudio.com/wiki/vehicles) as ive found exists recently :)
note it will also return static weapons like M2 tripods etc, they are excluded in the below code since those normally dont have gear menu, you can just remove the if part of the code if you want to include them as well.


{
if (!(_x isKindOf "StaticWeapon")) then {_x addAction ["acess gear", "script.sqf"]};
} foreach vehicles;

also note it will only add to the vehicles present at that time, if you rerun the code later again, you will get multiple actions on a vehicle, so track them in a array and skip if in.
or instead of vehicles use this as a list of specific named vehicles:

replace foreach vehicles
with foreach [vehiclename1,vehiclename2,etc]

Muzzleflash
Jul 3 2011, 16:25
If you have CBA (eg. you have ACE) then you can use extended event handlers to add the action. That will also work for any vehicle you spawn later. Although, it might, caues some problems JIP.