Hello, guys. I have very simple script but it shows error. I don't know how about you but I'm sure I have it written correctly because it was working in my old mission and in new one it won't work. Any help please?
Vehicle init:
_this = execVM "scripts\Auto_Rearm.sqf";
scripts\Auto_Rearm.sqf:
// Define Variables
_unit = _this select 0;
// Start loop
while {true} do
{
_unit setVehicleAmmo 1;
sleep 300;
};
Depends on how you do the respawn you could use something like this:
//initPlayerLocal.sqf or wherever you seem fit
//function to register vehicles for marker drawing
TAG_vehMarkers = [];
TAG_fnc_vehMarkerHandling = {
params ["_veh","_textType"];
_veh setVariable ["TAG_fnc_vehMarkerRespawnParams",_this];
_mrk = createMarker [str _veh, getPosVisual _veh];
_mrk setMarkerType "hd_dot";
_mrk setMarkerColor "ColorBlue";
_this append [_mrk];
TAG_vehMarkers pushBack _this;
_mrk
};
//use this to remove the vehicle from marker handling
TAG_fnc_vehMarkerRemove = {
params ["_veh"];
_index = TAG_vehMarkers findIf {_x#0 isEqualTo _veh};
_removed = TAG_vehMarkers deleteAt _index;
deleteMarker (_removed#2);
systemChat format ["Removed %1 from marker handling",_removed];
true
};
//handle marker drawing and text selection
addMissionEventHandler ["EachFrame",{
_truckTexts = [["Repair truck","Repair truck is destroyed"],["Fuel truck","Fuel truck is destroyed"],["Ammo truck","Ammo truck is destroyed"]];
{
_x#2 setMarkerPos getPosVisual (_x#0);
_x#2 setMarkerText (_truckTexts#(_x#1) select (!alive (_x#0)));
} forEach TAG_vehMarkers;
}];
//to add vehicles to marker handling use this inside a trigger/script/whatever
_handleMarker = [ammotruck,2] call TAG_fnc_vehMarkerHandling;//0 for repair, 1 for fuel, 2 for ammo etc.
You can simply register vehicles and wanted text types with a single line, should be self explanatory, if not, ask.
Also added a function so you can cleanly remove a vehicle from being handled by the EachFrame Eventhandler and also deletes the vehicle related marker.
Will work from vehicle respawn module like this:
_handleMarker = [_this#1,2] call TAG_fnc_vehMarkerHandling;//adjust number to text you want to put out obviously
Setting marker positions on each frame costs negligible CPU cycles (0.0013ms on my rig), a frame lasts 16.67ms at 60fps, so 0.0013ms is 0.002167% of a frame at 60fps.
Can squeeze a few of those into a single frames runtime, heh.
Cheers