Jump to content
Sign in to follow this  
silens

cutrsc in multiplayer help

Recommended Posts

I'm looking for some help with this script, I am not sure what I am doing wrong, it's probably something simple too :)

The script is supposed to show a custom hud/image over the vehicle radar. This works, when a player gets in the vehicle it pops up and when they get out it goes away.

The problem is that in multiplayer when a player gets in the vehicle, the hud also shows up for the other players!

description.ext

class RscTitles
{
#include "scripts\rdf\rdf_hud.hpp"
};

init.sqf

if(hasInterface)then{execVM "scripts\rdf\init_rdf.sqf"};

init_rdf.sqf

RDF_RADAR_X = profilenamespace getvariable "IGUI_GRID_RADAR_X";
RDF_RADAR_Y = profilenamespace getvariable "IGUI_GRID_RADAR_Y";
missionNamespace setVariable ["RDF_RADAR_X",RDF_RADAR_X];
missionNamespace setVariable ["RDF_RADAR_Y",RDF_RADAR_Y];

waitUntil{!isNull (findDisplay 46)};
RDF_InVeh = {
_veh = _this select 0;
9900 cutRsc["RadarCover","PLAIN",1,false];
RDF_updateheading = [] spawn{disableSerialization;_ui = uiNameSpace getVariable ["RadarCover",displayNull];_headingui = _ui displayCtrl 24587;while{true}do{_headingui ctrlsettext str (floor direction vehicle player);};};		
_veh addEventhandler ["GetOut",{[_this select 2] call RDF_OutVeh;}];
};
RDF_OutVeh = {
9900 cutText ["", "PLAIN"];
terminate RDF_updateheading;
};

{
if (typeOf _x == "B_Heli_Light_01_armed_F")then
 	{	
	_x addEventhandler ["GetIn",{ [_this select 2] call RDF_InVeh;}];
};
}foreach Vehicles;

rdf_hud.hpp

class RscText
{
access = 0;
type = 0;
idc = -1;
colorBackground[] = 
{
	0,
	0,
	0,
	0
};
colorText[] = 
{
	1,
	1,
	1,
	1
};
text = "";
fixedWidth = 0;
x = 0;
y = 0;
h = 0.037;
w = 0.3;
style = 0;
shadow = 1;
colorShadow[] = 
{
	0,
	0,
	0,
	0.5
};
font = "PuristaMedium";
SizeEx = "(((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1)";
linespacing = 1;
};
class RscPicture
{
access = 0;
type = 0;
idc = -1;
style = 48;
colorBackground[] = 
{
	0,
	0,
	0,
	0
};
colorText[] = 
{
	1,
	1,
	1,
	1
};
font = "TahomaB";
sizeEx = 0;
lineSpacing = 0;
text = "";
fixedWidth = 0;
shadow = 0;
x = 0;
y = 0;
w = 0.2;
h = 0.15;
};
class RadarCover
{
idd=-1;
movingEnable=0;
fadein=0;
duration = 99999999999999999999999999999999999999999999;
fadeout=0;
class controlsBackground
{
	class RadarCover_Background: RscPicture
	{
		text = "scripts\rdf\radar_bckg.paa";
		x="0 * 					(			((safezoneW / safezoneH) min 1.2) / 40) + 		(missionNamespace getvariable [""RDF_RADAR_X"",		(safezoneX + safezoneW / 2 - 2.8 * 			(			((safezoneW / safezoneH) min 1.2) / 40))])";
		y="0 * 					(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + 		(missionNamespace getvariable [""RDF_RADAR_Y"",		(safezoneY + 0.5 * 			(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25))])";
		w="5.6 * 					(			((safezoneW / safezoneH) min 1.2) / 40)";
		h="5.6 * 					(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25)";
		colorText[]=
				{
					"(profilenamespace getvariable ['IGUI_BCG_RGB_R',0])",
					"(profilenamespace getvariable ['IGUI_BCG_RGB_G',1])",
					"(profilenamespace getvariable ['IGUI_BCG_RGB_B',1])",
					1//"(profilenamespace getvariable ['IGUI_TEXT_RGB_A',0.8])"
				};
	};
	class RadarCover_Tex2: RscPicture
	{
		text = "scripts\rdf\radar_dir.paa";
		x="0 * 					(			((safezoneW / safezoneH) min 1.2) / 40) + 		(missionNamespace getvariable [""RDF_RADAR_X"",		(safezoneX + safezoneW / 2 - 2.8 * 			(			((safezoneW / safezoneH) min 1.2) / 40))])";
		y="0 * 					(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + 		(missionNamespace getvariable [""RDF_RADAR_Y"",		(safezoneY + 0.5 * 			(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25))])";
		w="5.6 * 					(			((safezoneW / safezoneH) min 1.2) / 40)";
		h="5.6 * 					(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25)";
		colorText[]=
				{
					"(profilenamespace getvariable ['IGUI_TEXT_RGB_R',0])",
					"(profilenamespace getvariable ['IGUI_TEXT_RGB_G',1])",
					"(profilenamespace getvariable ['IGUI_TEXT_RGB_B',1])",
					1//"(profilenamespace getvariable ['IGUI_TEXT_RGB_A',0.8])"
				};
	};		
	class RadarCover_Glass: RscPicture
	{
		text = "scripts\rdf\radar_glass.paa";
		x="0 * 					(			((safezoneW / safezoneH) min 1.2) / 40) + 		(missionNamespace getvariable [""RDF_RADAR_X"",		(safezoneX + safezoneW / 2 - 2.8 * 			(			((safezoneW / safezoneH) min 1.2) / 40))])";
		y="0 * 					(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + 		(missionNamespace getvariable [""RDF_RADAR_Y"",		(safezoneY + 0.5 * 			(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25))])";
		w="5.6 * 					(			((safezoneW / safezoneH) min 1.2) / 40)";
		h="5.6 * 					(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25)";
		colorText[]=
				{
					"(profilenamespace getvariable ['IGUI_TEXT_RGB_R',0])",
					"(profilenamespace getvariable ['IGUI_TEXT_RGB_G',1])",
					"(profilenamespace getvariable ['IGUI_TEXT_RGB_B',1])",
					1//"(profilenamespace getvariable ['IGUI_TEXT_RGB_A',0.8])"
				};
	};
	class Radar_Heading: RscText
			{
				idc=24587;
				style=2;
				colorText[]=
				{
					"(profilenamespace getvariable ['IGUI_TEXT_RGB_R',0])",
					"(profilenamespace getvariable ['IGUI_TEXT_RGB_G',1])",
					"(profilenamespace getvariable ['IGUI_TEXT_RGB_B',1])",
					"(profilenamespace getvariable ['IGUI_TEXT_RGB_A',0.8])"
				};
				text=" 359";
				x="1.70 * 					(			((safezoneW / safezoneH) min 1.2) / 40) + 		(missionNamespace getvariable [""RDF_RADAR_X"",		(safezoneX + safezoneW / 2 - 2.8 * 			(			((safezoneW / safezoneH) min 1.2) / 40))])";
				y="4.1 * 					(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + 		(missionNamespace getvariable [""RDF_RADAR_Y"",		(safezoneY + 0.5 * 			(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25))])";
				w="2 * 					(			((safezoneW / safezoneH) min 1.2) / 40)";
				h="1 * 					(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25)";
				sizeEx="0.8 * 					(			(			((safezoneW / safezoneH) min 1.2) / 1.2) / 25)";
			};
};
};

Share this post


Link to post
Share on other sites

Check for locality before creating the resource.

Share this post


Link to post
Share on other sites

The "GetIn" event handler fires on every machine where it has been placed when a unit gets in the vehicle, since you are running the code that places the event handler in init.sqf all players have the event handler, giving the effect of a global command gone wrong. However, that is not the case.

The solution here is to add some code to RDF_InVeh that will check what unit entered the vehicle, and if it is a player then display a resource. Furthermore, I noticed something that was likely unintended, every time a unit gets into a vehicle then a "GetOut" event handler is added to every player's machine. The event handlers will not overwrite each other, a new completely identical event handler is created and all of them will fire at nearly the same time when the condition is met. This could have serious repercussions to your players' FPS in longer games (if RDF_OutVeh was a lot longer or more cpu costly). Here is the code with my corrections.

init_rdf.sqf

RDF_RADAR_X = profilenamespace getvariable "IGUI_GRID_RADAR_X";
RDF_RADAR_Y = profilenamespace getvariable "IGUI_GRID_RADAR_Y";
missionNamespace setVariable ["RDF_RADAR_X",RDF_RADAR_X];
missionNamespace setVariable ["RDF_RADAR_Y",RDF_RADAR_Y];

//waitUntil{!isNull (findDisplay 46)}; //there's not really a point to this since all you're doing is defining some code and adding event handlers

RDF_InVeh =
{
_veh = _this select 0;
_position = _this select 1; //adding support to limit the effect to driver-only or passenger-only or whatever
_unit = _this select 2; //the unit that entered the vehicle

if (isPlayer _unit && {local _unit}) then //make sure that the unit is local, ALSO make sure that the unit is a human player just in case an AI is ordered to get in
{
//		if (_position == "driver") then //limit the effect to driver/pilot only, leave this commented and it will not do anything
//		{
		9900 cutRsc["RadarCover","PLAIN",1,false];
		RDF_updateheading = [] spawn //I spread this out because it's harder to debug and it's pointless since it doesn't help the computer run the code any faster
		{
			disableSerialization;
			_ui = uiNameSpace getVariable ["RadarCover",displayNull];
			_headingui = _ui displayCtrl 24587;
			while {true} do
			{
				_headingui ctrlsettext str (floor direction vehicle player);
			};
		};
//		};
};
};

RDF_OutVeh =
{
9900 cutText ["", "PLAIN"];
terminate RDF_updateheading;
};

{
if (typeOf _x == "B_Heli_Light_01_armed_F")then
 	{	
	_x addEventhandler ["GetIn",{ [_this select 2] call RDF_InVeh;}];
	_x addEventhandler ["GetOut",{[_this select 2] call RDF_OutVeh;}]; //removed from RDF_InVeh and placed here
};
}foreach Vehicles;

Share this post


Link to post
Share on other sites

Yep that did it guys, thanks a lot!

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
Sign in to follow this  

×