Jump to content
HonzaVinCZ

Simple script shows error

Recommended Posts

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;
};

 

Share this post


Link to post
Share on other sites

You pass no argument to the script so _this select 0; throws an error. The script is intended to used for an unit right? You need to throw an unit as [unit] execVM "scripts\Auto_Rearm.sqf";.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

You made a small mistake in the vehicle init box, so for your situation it would be:

_null = [this] execVM "scripts\Auto_Rearm.sqf";

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
8 hours ago, HonzaVinCZ said:

// Start loop while {true} do

 

Hello there HonzaVinCZ !

 

You should really consider about using an eventhandler instead of a loop :

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Fired

 

ex:

{
if!(isplayer _x)then{	
	_x addEventHandler["Fired", {
		params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"];
		
		if({_x isEqualTo _magazine}count magazines _unit < 2)then{
			_unit addMagazines [_magazine, 3];
			systemchat "addMagazines";
		};
	}];
	};
}foreach units group player;

 

  • Like 2

Share this post


Link to post
Share on other sites
56 minutes ago, GEORGE FLOROS GR said:

 

Hello there HonzaVinCZ !

 

You should really consider about using an eventhandler instead of a loop :

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Fired

 

ex:


{
if!(isplayer _x)then{	
	_x addEventHandler["Fired", {
		params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"];
		
		if({_x isEqualTo _magazine}count magazines _unit < 2)then{
			_unit addMagazines [_magazine, 3];
			systemchat "addMagazines";
		};
	}];
	};
}foreach units group player;

 

Thank you a lot! I have one more problem and it is this script:
VehicleMarkers.sqf

_unit = _this select 0;
_text = _this select 1;
_randomnumber = random 100 + random 100;
_nameMarker = "Markername" + (str _randomnumber);
_debug = true;

createMarker [_nameMarker, getPosVisual _unit];
_nameMarker setMarkerType "hd_dot";
_nameMarker setMarkerColor "ColorBlue";

if (_text == 1) then {
	_nameMarker setMarkerText "Repair truck";
};

if (_text == 2) then {
	_nameMarker setMarkerText "Fuel truck";
};

if (_text == 3) then {
	_nameMarker setMarkerText "Ammo truck";
};

while {true} do {
	if (alive _unit) then {
		_nameMarker setMarkerPos getPosVisual _unit;
		if (_text == 1) then {
			_nameMarker setMarkerText "Repair truck";
		};

		if (_text == 2) then {
			_nameMarker setMarkerText "Fuel truck";
		};

		if (_text == 3) then {
			_nameMarker setMarkerText "Ammo truck";
		};
	} else {
		if (_text == 1) then {
			_nameMarker setMarkerText "Repair truck is destroyed";
		};

		if (_text == 2) then {
			_nameMarker setMarkerText "Fuel truck is destroyed";
		};

		if (_text == 3) then {
			_nameMarker setMarkerText "Ammo truck is destroyed";
		};
	};
	sleep 3;
};

Vehicle var:

Franta


vehicle init:

veh = [this, 30, 120, 0, FALSE, FALSE] execVM "scripts\vehicle.sqf";
_this = [Franta,2] execVM "scripts\VehicleMarkers.sqf";


as you see, I'm very beginner... so, my point is to make marker move with unit, in my case with vehicle and if it is destroyed, it just changes to "destroyed" text and after it respawns, marker should move to vehicle and text should be same as before it was destroyed but that doesn't work. I have set in respawn script vehicleVarName to save it and in editor there's vehicleVarName set. So when vehicle is destroyed and it respawns, marker won't move to respawned vehicle but varName still exists when I try Franta(vehicleVarName) setDamage 1; . Any idea please? Please try as easiest script as you can so I can understand it, thank you!

  • Like 1

Share this post


Link to post
Share on other sites
17 minutes ago, HonzaVinCZ said:

Thank you a lot!

You're welcome !

 

14 minutes ago, HonzaVinCZ said:

Please try as easiest script as you can so I can understand it, thank you!

 

Generally you need to check these EH and probably store your Var in missionNamespace :

    _veh addEventHandler ["GetIn",{_this execVM "server\SpawnVehicleBase\getIn.sqf";}];
    _veh addEventHandler ["GetOut",{_this execVM "server\SpawnVehicleBase\getout.sqf";}];
    _veh addMPEventHandler ["mpkilled",{_this execVM "server\SpawnVehicleBase\killed.sqf";}];

if i have time i'll try to add a code as well !

 

  • Like 1

Share this post


Link to post
Share on other sites

I would strongly suggest you should follow GEORGE FLOROS GR's advice and use an event handler. One minor note I would add is to use "Reloaded" event handler which is, most probably, triggered less often, which could prove to give a minor (or even close to zero) efficiency improvement. Apart from the different event handler and the different parameters passed I believe the code is exactly the same. Just for reference I will reproduce GEORGE FLOROS GR's code with those small changes.

{
if!(isplayer _x) then {	
	_x addEventHandler["Reloaded", { // CHANGED EVENT HANDLER FROM FIRED TO RELOADED
		params["_unit", "_weapon", "_muzzle", "_newMagazine", "_oldMagazine"]; // CHANGED THE PARAMETERS
		
		if({_x isEqualTo _magazine} count magazines _unit < 2) then {
			_unit addMagazines [_oldMagazine, 3]; // CHANGED THE VARIABLE HOLDING THE MAGAZINE (TYPE)... HERE YOU COULD ALSO USE _NEWMAGAZINE
			systemchat "addMagazines";
		};
	}];
	};
}foreach units group player;

One minor thing here is the case in which the previous magazine and the new one is different... For example, if the old magazine is replace by a tracer magazine. There will be a difference as to what magazines will be added to the unit if you use _newMagazine against _oldMagazine.

 

Now, regarding your marker script..... I believe you are doing a couple of things that might be wrong... I will try to use your script as base to work on your logic and make it both easier for you to understand and adapt your code.

// I WILL CALL THIS SCRIPT markerFollower.sqf

_unit = _this select 0;
_text = _this select 1;
_randomnumber = random 100 + random 100;
_nameMarker = "Markername" + (str _randomnumber);
_debug = true; // NOT SURE WHAT THIS IS FOR, SO I WILL JUST LEAVE IT AS IT IS...

createMarker [_nameMarker, getPosVisual _unit];
_nameMarker setMarkerType "hd_dot";
_nameMarker setMarkerColor "ColorBlue";

if (_text == 1) then {
	_nameMarker setMarkerText "Repair truck";
};

if (_text == 2) then {
	_nameMarker setMarkerText "Fuel truck";
};

if (_text == 3) then {
	_nameMarker setMarkerText "Ammo truck";
};

// UP TO THIS POINT YOU HAVE CREATED AND PLACED A MARKER (SO THAT'S JUST FINE)


// NOW WHAT YOU WANT IS TO MOVE THE MARKER AS LONG AS THE UNIT IS ALIVE, SO YOU SHOULD IMPLEMENT IT AS STRAIGHT FORWARD AS YOU CAN
while {alive _unit} do { // Take care to use DO instead of THEN on while-loops
	_nameMarker setMarkerPos (getPosVisual _unit); // Set the position of the marker
	sleep 5; // Set a delay to save some CPU
};

// NOW THE NEXT PART WILL BE EXECUTED WHEN THE UNIT CEASES TO BE ALIVE.... 8|. SO THIS IS THE PLACE TO CHANGE THE NAME OF THE MARKER
if (_text == 1) then {
	_nameMarker setMarkerText "Repair truck is destroyed";
};

if (_text == 2) then {
	_nameMarker setMarkerText "Fuel truck is destroyed";
};

if (_text == 3) then {
	_nameMarker setMarkerText "Ammo truck is destroyed";
};

// Here you can add an event handler that will be triggered when the unit respawns
_unit addEventHandler["Respawn", {
	private _respawnUnit = _this select 0; // Get the unit that is respawned... This is the same as the "_unit" you have above
	_respawnUnit removeEventHandler _thisEventHandler; // Remove the current event handler (a new one will be added two lines below...!!!)
	deleteMarker _nameMarker; // Delete the marker (the one named "Some Kind Of Truck Destroyed")
	[_respawnUnit, _text] execVM "markerFollower.sqf"; // Now run the current script
}];

Now, some things to note. First and foremost THIS IS NOT TESTED... Additionally, this is definitely not the best way to do it, but having to work on your implementation and looking for a quick solution, this is what I came up with... Hopefully someone else will come up with a better one (for example without the need to constantly remove and add an event handler).

 

I hope this helped somehow... If there's any gray fields please don't hesitate to ask.

  • Like 2

Share this post


Link to post
Share on other sites

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

  • Like 2

Share this post


Link to post
Share on other sites
12 hours ago, ZaellixA said:

I would strongly suggest you should follow GEORGE FLOROS GR's advice and use an event handler. One minor note I would add is to use "Reloaded" event handler which is, most probably, triggered less often, which could prove to give a minor (or even close to zero) efficiency improvement. Apart from the different event handler and the different parameters passed I believe the code is exactly the same. Just for reference I will reproduce GEORGE FLOROS GR's code with those small changes.


{
if!(isplayer _x) then {	
	_x addEventHandler["Reloaded", { // CHANGED EVENT HANDLER FROM FIRED TO RELOADED
		params["_unit", "_weapon", "_muzzle", "_newMagazine", "_oldMagazine"]; // CHANGED THE PARAMETERS
		
		if({_x isEqualTo _magazine} count magazines _unit < 2) then {
			_unit addMagazines [_oldMagazine, 3]; // CHANGED THE VARIABLE HOLDING THE MAGAZINE (TYPE)... HERE YOU COULD ALSO USE _NEWMAGAZINE
			systemchat "addMagazines";
		};
	}];
	};
}foreach units group player;

One minor thing here is the case in which the previous magazine and the new one is different... For example, if the old magazine is replace by a tracer magazine. There will be a difference as to what magazines will be added to the unit if you use _newMagazine against _oldMagazine.

 

Now, regarding your marker script..... I believe you are doing a couple of things that might be wrong... I will try to use your script as base to work on your logic and make it both easier for you to understand and adapt your code.


// I WILL CALL THIS SCRIPT markerFollower.sqf

_unit = _this select 0;
_text = _this select 1;
_randomnumber = random 100 + random 100;
_nameMarker = "Markername" + (str _randomnumber);
_debug = true; // NOT SURE WHAT THIS IS FOR, SO I WILL JUST LEAVE IT AS IT IS...

createMarker [_nameMarker, getPosVisual _unit];
_nameMarker setMarkerType "hd_dot";
_nameMarker setMarkerColor "ColorBlue";

if (_text == 1) then {
	_nameMarker setMarkerText "Repair truck";
};

if (_text == 2) then {
	_nameMarker setMarkerText "Fuel truck";
};

if (_text == 3) then {
	_nameMarker setMarkerText "Ammo truck";
};

// UP TO THIS POINT YOU HAVE CREATED AND PLACED A MARKER (SO THAT'S JUST FINE)


// NOW WHAT YOU WANT IS TO MOVE THE MARKER AS LONG AS THE UNIT IS ALIVE, SO YOU SHOULD IMPLEMENT IT AS STRAIGHT FORWARD AS YOU CAN
while {alive _unit} do { // Take care to use DO instead of THEN on while-loops
	_nameMarker setMarkerPos (getPosVisual _unit); // Set the position of the marker
	sleep 5; // Set a delay to save some CPU
};

// NOW THE NEXT PART WILL BE EXECUTED WHEN THE UNIT CEASES TO BE ALIVE.... 8|. SO THIS IS THE PLACE TO CHANGE THE NAME OF THE MARKER
if (_text == 1) then {
	_nameMarker setMarkerText "Repair truck is destroyed";
};

if (_text == 2) then {
	_nameMarker setMarkerText "Fuel truck is destroyed";
};

if (_text == 3) then {
	_nameMarker setMarkerText "Ammo truck is destroyed";
};

// Here you can add an event handler that will be triggered when the unit respawns
_unit addEventHandler["Respawn", {
	private _respawnUnit = _this select 0; // Get the unit that is respawned... This is the same as the "_unit" you have above
	_respawnUnit removeEventHandler _thisEventHandler; // Remove the current event handler (a new one will be added two lines below...!!!)
	deleteMarker _nameMarker; // Delete the marker (the one named "Some Kind Of Truck Destroyed")
	[_respawnUnit, _text] execVM "markerFollower.sqf"; // Now run the current script
}];

Now, some things to note. First and foremost THIS IS NOT TESTED... Additionally, this is definitely not the best way to do it, but having to work on your implementation and looking for a quick solution, this is what I came up with... Hopefully someone else will come up with a better one (for example without the need to constantly remove and add an event handler).

 

I hope this helped somehow... If there's any gray fields please don't hesitate to ask.

I tried your script and it doesn't work. I got huge fps spike so it propably execvm-ing this script after vehicle respawn continously with using editor module respawn. I was using GOM's vehicle respawn script before and it showed error on his 123 line when I was using my script on same vehicle. I spent whole morning solving how to make it work but still not lucky. 
My actual not working script:

/*
Vehicle init
veh = [this,2] execVM "scripts\VehicleMarkers.sqf";

- vehicle name
- Text

Text:
1 = Repair Truck
2 = Fuel Truck
3 = Ammo Truck
4 = MHQ
*/

_unit = _this select 0;
_text = _this select 1;
_randomnumber = random 1000000;
_nameMarker = "Markername" + (str _randomnumber);

createMarker [_nameMarker, getPosVisual _unit];

if (_text == 1 or _text == 2 or _text == 3) then {
	_nameMarker setMarkerType "b_unknown";
};

if (_text == 4) then {
	_nameMarker setMarkerType "b_hq";
};

_nameMarker setMarkerColor "ColorBLUFOR";

if (_text == 1) then {
	_nameMarker setMarkerText "Repair truck";
};

if (_text == 2) then {
	_nameMarker setMarkerText "Fuel truck";
};

if (_text == 3) then {
	_nameMarker setMarkerText "Ammo truck";
};

if (_text == 4) then {
	_nameMarker setMarkerText "HQ";
};

while {alive _unit} do {
	_nameMarker setMarkerPos (getPosVisual _unit);
	sleep 5;
};

if (_text == 1) then {
	_nameMarker setMarkerText "Repair truck is destroyed";
};

if (_text == 2) then {
	_nameMarker setMarkerText "Fuel truck is destroyed";
};

if (_text == 3) then {
	_nameMarker setMarkerText "Ammo truck is destroyed";
};

if (_text == 4) then {
	_nameMarker setMarkerText "MHQ is destroyed";
};

_unit addEventHandler["Respawn", {
	private _respawnUnit = _this select 0;
	_respawnUnit removeEventHandler _thisEventHandler;
	deleteMarker _nameMarker;
	[_unit, _text] execVM "scripts\VehicleMarkers.sqf";
}];

 

Share this post


Link to post
Share on other sites
4 minutes ago, HonzaVinCZ said:

I was using GOM's vehicle respawn script before and it showed error on his 126 line

Weird, my snippet only has 35 lines and doesn't handle respawn at all, as stated earlier, with the one liner example for the respawn module, if that's what you're using.

 

Cheers

Share this post


Link to post
Share on other sites
3 minutes ago, Grumpy Old Man said:

Weird, my snippet only has 35 lines.

 

Cheers

Oh, nevermind... I overlook script and mistaken just the name with your aircraft pylon script.
Btw this is the vehicle respawn script I was using before ZaellixA script test. 
 

/*  
==================================================================================================================
  Simple Vehicle Respawn Script v1.81 for Arma 3
  by Tophe of Östgöta Ops [OOPS] and tweaked for I&A 3 by Rarek [AW]
  
  Put this in the vehicles init line:
  veh = [this] execVM "vehicle.sqf"

  
  Options:
  There are some optional settings. The format for these are:
  veh = [object, Delay, Deserted timer, Respawns, Effect, Dynamic] execVM "vehicle.sqf"
  
  Default respawn delay is 30 seconds, to set a custom respawn delay time, put that in the init as well. 
  Like this:
  veh = [this, 15] execVM "vehicle.sqf"

  Default respawn time when vehicle is deserted, but not destroyed is 120 seconds. To set a custom timer for this 
  first set respawn delay, then the deserted vehicle timer. (0 = disabled) 
  Like this:  
  veh = [this, 15, 10] execVM "vehicle.sqf"

  By default the number of respawns is infinite. To set a limit first set preceding values then the number of respawns you want (0 = infinite).
  Like this:
  veh = [this, 15, 10, 5] execVM "vehicle.sqf"

  Set this value to TRUE to add a special explosion effect to the wreck when respawning.
  Default value is FALSE, which will simply have the wreck disappear.
  Like this:
  veh = [this, 15, 10, 5, TRUE] execVM "vehicle.sqf"
  
  By default the vehicle will respawn to the point where it first was when the mission started (static). 
  This can be changed to dynamic. Then the vehicle will respawn to the position where it was destroyed. 
  First set all preceding values then set TRUE for dynamic or FALSE for static.
  Like this:
  veh = [this, 15, 10, 5, TRUE, TRUE] execVM "vehicle.sqf"
  
  If you you want to set the INIT field of the respawned vehicle, first set all other values, then set init commands. 
  Those must be inside quotations.
  Like this:
  veh = [this, 15, 10, 5, TRUE, FALSE, "this setDammage 0.5"] execVM "vehicle.sqf"		
  
  Default values of all settings are:
  veh = [this, 30, 120, 0, FALSE, FALSE] execVM "vehicle.sqf"
  
	
Contact & Bugreport: cwadensten@gmail.com
================================================================================================================== */
  
if (!isServer) exitWith {};

// Define variables
_unit = [_this,0,objNull,[objNull]] call BIS_fnc_param;
_delay = [_this,1,30,[0]] call BIS_fnc_param;
_deserted = [_this,2,120,[0]] call BIS_fnc_param;
_respawns = [_this,3,0,[0]] call BIS_fnc_param;
_explode = [_this,4,false,[true]] call BIS_fnc_param;
_dynamic = [_this,5,false,[true]] call BIS_fnc_param;
_unitinit = [_this,6];
_haveinit = if (count _this > 6) then { true } else { false };

_hasname = false;
_unitname = vehicleVarName _unit;
if (isNil _unitname) then {_hasname = false;} else {_hasname = true;};
_noend = true;
_run = true;
_rounds = 0;

if (_delay < 0) then {_delay = 0};
if (_deserted < 0) then {_deserted = 0};
if (_respawns <= 0) then {_respawns= 0; _noend = true;};
if (_respawns > 0) then {_noend = false};

_dir = getDir _unit;
_position = getPosASL _unit;
_type = typeOf _unit;
_dead = false;
_nodelay = false;

// Start monitoring the vehicle
while {_run} do 
{	
	sleep (2 + random 10);
	if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};

	// Check if the vehicle is deserted.
	if (_deserted > 0) then
	{
		if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8)) then 
		{
			_timeout = time + _deserted;
			sleep 0.1;
			waitUntil {_timeout < time or !alive _unit or {alive _x} count crew _unit > 0};

			if ({alive _x} count crew _unit > 0) then {_dead = false}; 
			if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true}; 
			if !(alive _unit) then {_dead = true; _nodelay = false}; 
		};
	};

	// Respawn vehicle
	if (_dead) then 
	{	
		if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay;};
		if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};
		if (_explode) then {_effect = "M_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};
		sleep 0.1;

		deleteVehicle _unit;
		sleep 2;
		_unit = _type createVehicle _position;
		_unit setPosASL _position;
		_unit setDir _dir;
		if (["B_UAV", _type] call BIS_fnc_inString) then { createVehicleCrew _unit; };

		if (_haveinit) then 
		{
			_unit call compile format ["%1=_This; PublicVariable '%1'",_unitinit];
		};

		if (_hasname) then 
		{
			_unit setVehicleVarName _unitname;
			_unit call compile format ["%1=_This; PublicVariable '%1'",_unitname];
		};	
		_dead = false;

		// Check respawn amount
		if !(_noend) then {_rounds = _rounds + 1};
		if ((_rounds == _respawns) and !(_noend)) then {_run = false;};
	};
};

Also did not try your script so give me time please. Thank you!

Share this post


Link to post
Share on other sites
6 hours ago, Grumpy Old Man said:

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

Well, it works also until the vehicle is destroyed. After vehicle respawn it shows vehicle marker on grid 000... . Maybe I'm so bad I can't use your scripts properly or I don't know. I'm really lost in this situation.
Also I was using script vehicle respawn I attached above because the editor module respawn is broken and spawns vehicles in walls and not properly on the place.

Share this post


Link to post
Share on other sites
1 hour ago, HonzaVinCZ said:

Well, it works also until the vehicle is destroyed. After vehicle respawn it shows vehicle marker on grid 000... . Maybe I'm so bad I can't use your scripts properly or I don't know. I'm really lost in this situation.
Also I was using script vehicle respawn I attached above because the editor module respawn is broken and spawns vehicles in walls and not properly on the place.

That's because my snippet doesn't handle respawn, which can be done in many ways, depending if you use a vanilla module, third party script, other custom solution.

Hence the example for the vanilla respawn modules expression field.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×