Author Topic: Toggle Visible Player Names but not Crosshair  (Read 2412 times)

I'm trying to make seperate keybinds for disabling/enabling the visibility of player names and crosshair.

I've got the function name for toggling player names AND crosshair (ToggleShapeNameHud), but is there a way to have seperate keybinds to toggle each? If so, how?

Figure out what gets removed in the GUI that hides player names, then make a Canvas.PopDialog(%obj); and Canvas.PushDialog(%obj); I believe it was, for that. Same thing with the crosshair.

Figure out what gets removed in the GUI
I'm stuck on this step. how do I see what's being removed from the GUI?


Try using trace?
all it says in the trace is  Entering ToggleShapeNameHud(0), which removes player names and crosshair

also, what do these do:
Canvas.PopDialog(%obj); and Canvas.PushDialog(%obj);


crossHair.setVisible(1);
put that in after your ToggleShapeNameHud(0);

crossHair.setVisible(1);
put that in after your ToggleShapeNameHud(0);
ooh nice. thanks

is there a command like crossHair.setVisible(1); except for player names?


where can I find good reference material for making an add-on that adds new keybinds?

add-ons that add new keybinds

My code doesn't work. I believe the errors are on line 65 and 70 and have to do with crossHair.setVisibility();
does anything stand out that's wrong?

Code: [Select]
$remapdivision[$remapcount] = "Player Names & Crosshair Toggler";
$remapname[$remapcount] = "Turn Player Names On";
$remapcmd[$remapcount] = "PlayerNamesOnPlease";
$remapcount++;
$remapname[$remapcount] = "Turn Player Names Off";
$remapcmd[$remapcount] = "PlayerNamesOffPlease";
$remapcount++;
$remapname[$remapcount] = "Turn Crosshair On";
$remapcmd[$remapcount] = "CrosshairOnPlease";
$remapcount++;
$remapname[$remapcount] = "Turn Crosshair Off";
$remapcmd[$remapcount] = "CrosshairOffPlease";
$remapcount++;
$NamesAndCrosshairsGUIBind = true;

function PlayerNamesOnPlease(%val)
{
if(!%val)
{
return;
}

if(ToggleShapeNameHud() == 1)
{
return;
}

if(crossHair.setVisible() == 1)
{
%crossHairToggled = 1;
}

if(crossHair.setVisible() == 0)
{
%crossHairToggled = 0;
}

ToggleShapeNameHud(1);

if(%crossHairToggled == 1)
{
crossHair.setVisible(1);
}

if(%crossHairToggled == 0)
{
crossHair.setVisible(0);
}

}

function PlayerNamesOffPlease(%val)
{
if(!%val)
{
return;
}

if(ToggleShapeNameHud() == 0)
{
return;
}

if(crossHair.setVisible() == 1)
{
%crossHairToggled = 1;
}

if(crossHair.setVisible() == 0)
{
%crossHairToggled = 0;
}

ToggleShapeNameHud(0);

if(%crossHairToggled == 1)
{
crossHair.setVisible(1);
}

if(%crossHairToggled == 0)
{
crossHair.setVisible(0);
}

}

function CrosshairOnPlease(%val)
{
if(!%val)
{
return;
}

crossHair.setVisible(1);
}


function CrosshairOffPlease(%val)
{
if(!%val)
{
return;
}

crossHair.setVisible(0);
}

does anything stand out that's wrong?

Code: [Select]
if(ToggleShapeNameHud() == 1)
if(crossHair.setVisible() == 1)
if(crossHair.setVisible() == 0)
if(%crossHairToggled == 1)
if(%crossHairToggled == 0)
These all seem like they wouldn't work. crossHair.setVisible is a function to set if the cross hair is visible or not, it doesn't return anything so using it as an if statement wont work. Same with ToggleShapeNameHud so your if statements are all wrong. Iirc you should use if(crossHair.Visible == true) and if(crossHair.Visible == false)


I always use the below function for making key binds. Some guy made it. I don't remember who. It even allows you to add a key bind to already defined categories; even default ones, which the regular method does not allow you to do.
Code: [Select]
function addBind(%division, %name, %command)
{
for(%i=0;%i<$remapCount;%i++)
{
if($remapDivision[%i] $= %division)
{
%foundDiv = 1;
continue;
}
if(%foundDiv && $remapDivision[%i] !$= "")
{
%position = %i;
break;
}
}
if(!%foundDiv)
{
error("Division not found: " @ %division);
return;
}
if(!%position)
{
$remapName[$remapCount] = %name;
$remapCmd[$remapCount] = %command;
$remapCount++;
return;
}
for(%i=$remapCount;%i>%position;%i--)
{
$remapDivision[%i] = $remapDivision[%i - 1];
$remapName[%i] = $remapName[%i - 1];
$remapCmd[%i] = $remapCmd[%i - 1];
}
$remapDivision[%position] = "";
$remapName[%position] = %name;
$remapCmd[%position] = %command;
$remapCount++;
}