[help] Crosshair cycling script

Gr00ve

Veteran XV
Using Tribes from Groove's installer, I altered the vbackground script so I can cycle through crosshairs. It works well, except that I have to revert to one particular crosshair (whatever I decide is the 'default') every time I start tribes. If I don't revert to the 'default', Tribes either crashes on startup or produces a black screen with a ghosting tribes cursor. It's not a big deal, but if it's easily solvable, I'd like to know.

The code looks like this:

Code:
// Modified Groove's background changer to cycle
// through pre-configured crosshairs.

function Xhairs::Init() {
	if($Xhairs:Loaded)
		return;
	$Xhairs:Loaded = true;

	HUD::New( "Xhair::Container", 0, 0, 128, 128, BG::NoSleep, BG::NoSleep );
 	newObject("Xhair::Xhair", FearGuiFormattedText, 0, 0, 128, 128);
	HUD::Add("Xhair::Container","Xhair::Xhair");
	Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/green_white_cross.png>");		
}
Xhairs::Init();

$Xhairchange::Color[1] = "Green with White Cross";
$Xhairchange::Color[2] = "Green with White Circle";
$Xhairchange::Color[3] = "Green with Red Circle";
$Xhairchange::Color[4] = "Red with White Circle";
$Xhairchange::Color[5] = "Small Red Cross";
$Xhairchange::Color[6] = "Green Dot";
$Xhairchange::Color[7] = "Red Dot";
$Xhairchange::Color[8] = "White Dot";
$Xhairchange::Color[9] = "Blank";

$Xhairchange::currentstyle = 1;

// increment counter, loop at 9, set pref, remoteBP style name, apply the style
function Xhairchange::styleup()	{
	$Xhairchange::currentstyle += 1;
	if ($Xhairchange::currentstyle > 9) $Xhairchange::currentstyle = 1;
	$pref::vhud::Xhair::style = $Xhairchange::Color[$Xhairchange::currentstyle];
	remoteBP(2048, "<jc><f1>Xhair Style set to <f2>" @ $Xhairchange::Color[$Xhairchange::currentstyle] @ ".", 2);
	Xhairchange::applystyle();
	}

// apply the texture settings changes for the various styles
function Xhairchange::applystyle()
{
	switch($pref::vhud::Xhair::style)
	{
		case "Green with White Cross":
			Xhairchange::default();
			break;
		case "Green with White Circle":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/green_cross_white_circle.png>");
			break;
		case "Green with Red Circle":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/green_cross_red_circle.png>");
			break;
		case "Red with White Circle":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/red_white_circle.png>");
			break;
		case "Small Red Cross":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/small_red_cross.png>");
			break;
		case "Green Dot":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/green_dot.png>");
			break;
		case "Red Dot":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/red_dot.png>");
			break;
		case "White Dot":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/white_dot.png>");
			break;
		case "Blank":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/blank.png>");
			break;
		default:
			Xhairchange::default();
			break;
	}
}

function Xhairchange::default() {
	Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/green_white_cross.png>");
	}

//hack to insert binds into the menu
function Xhairchange::addBindsToMenu() after GameBinds::Init
{
	$GameBinds::CurrentMap = "actionMap.sae";
	$GameBinds::CurrentMapHandle = GameBinds::GetActionMap2( "actionMap.sae" );
	GameBinds::addBindCommand( "Change Crosshair Style", "Xhairchange::styleup();", "" );
}

Event::attach(eventGuiOpen, Xhairchange::applystyle);

At the moment, I have to set $pref::vhud::Xhair::style in the autoexec to be whatever is set in Xhairs::Init, otherwise I get the crash described above. Any ideas why? Also, what is the BG::NoSleep in the Init and why is it important?

Thanks!
 
i'd have to poke around with the original to see what's changed thats causing the crash

the NoSleep function i just use as a hack to avoid console errors - when you define a new hud with

Code:
HUD::New( "Xhair::Container", 0, 0, 128, 128, BG::NoSleep, BG::NoSleep );

the last 2 are the huds 'sleep' and 'wake' functions - when you hit the tab menu or escape (or other shit), tribes tries to put the huds to 'sleep' so they dont update anymore and use resources. you'd define BG::Sleep and BG::Wake (or whatever u want to call them) and put code in there that stops and resumes the updates

if a hud isn't updating all the time (like this one) or you dont care about it sleeping, i make a blank function (in this case i guess it was BG:NoSleep) that does nothing and use that as your sleep and wake calls - so that when it tries to sleep/wake it does nothing, but doesn't throw errors in the console like it would if you had no sleep/wake defined at all

other times im extra lazy and point the sleep/wake functions at something i know is already a dead function - in a lot of my scriptGL configs i pointed all the Sleep/Wakes at onMouseRMB which is a blank function GreyHound defined in sgl.mouse.acs.cs
 
Ah, good to know, thanks. It works well regardless, but I'd thought it might be something obvious I'd overlooked.
 
i tinkered and it's probably something to do with the fact that the styleup(); function is the only thing that sets the $pref:: variable that saves

this works:

Code:
// Xhair changey thingy

// Style Names:
$Xhairchange::Style[1] = "Green with White Cross";
$Xhairchange::Style[2] = "Green with White Circle";
$Xhairchange::Style[3] = "Green with Red Circle";
$Xhairchange::Style[4] = "Red with White Circle";
$Xhairchange::Style[5] = "Small Red Cross";
$Xhairchange::Style[6] = "Green Dot";
$Xhairchange::Style[7] = "Red Dot";
$Xhairchange::Style[8] = "White Dot";
$Xhairchange::Style[9] = "Blank";

// define HUD
function Xhairs::Init() {
	if($Xhairs:Loaded)
		return;
	$Xhairs:Loaded = true;

	// HUD::New( "HUD NAME", X-loc , Y-loc , X-size , Y-size , SleepFunction , WakeFunction );
	HUD::New( "Xhair::Container", 0, 0, 25, 25, BG::NoSleep, BG::NoSleep );
 	newObject("Xhair::Xhair", FearGuiFormattedText, 0, 0, 25, 25);
	HUD::Add("Xhair::Container","Xhair::Xhair");
	Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/green_white_cross.png>");		
}

// increment counter, loop at 9, set pref, remoteBP style name, apply the style
function Xhairchange::styleup()	{
	$Xhairchange::currentstyle += 1;
	if ($Xhairchange::currentstyle > 9) $Xhairchange::currentstyle = 1;
	$pref::XhairStyle = $Xhairchange::Style[$Xhairchange::currentstyle];
	remoteBP(2048, "<jc><f1>Xhair Style set to <f2>" @ $Xhairchange::Style[$Xhairchange::currentstyle] @ ".", 2);
	Xhairchange::applystyle();
	}
	
function Xhairchange::applystyle()
{
	switch($pref::XhairStyle)
	{
		case "Green with White Cross":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/green_white_cross.png>");
			break;
		case "Green with White Circle":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/green_cross_white_circle.png>");
			break;
		case "Green with Red Circle":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/green_cross_red_circle.png>");
			break;
		case "Red with White Circle":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/red_white_circle.png>");
			break;
		case "Small Red Cross":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/small_red_cross.png>");
			break;
		case "Green Dot":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/green_dot.png>");
			break;
		case "Red Dot":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/red_dot.png>");
			break;
		case "White Dot":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/white_dot.png>");
			break;
		case "Blank":
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/blank.png>");
			break;
		default:
			echoc(6, "Xhair Style undefined!! Setting default!!");
			$pref::XhairStyle = "Green with White Circle";
			Control::SetValue("Xhair::Xhair", "<B0,0:Modules/Xhairs/green_white_cross.png>");
			break;
	}
}	

//hack to insert binds into the menu
function Xhairchange::addBindsToMenu() after GameBinds::Init
{
	$GameBinds::CurrentMap = "actionMap.sae";
	$GameBinds::CurrentMapHandle = GameBinds::GetActionMap2( "actionMap.sae" );
	GameBinds::addBindCommand( "Change Crosshair Style", "Xhairchange::styleup();", "" );
}

function BG::NoSleep() { } // blank WakeSleep function
Xhairs::Init(); // load our HUD
Event::attach(eventGuiOpen, Xhairchange::applystyle); // apply the style on Gui Open

p.s. this thread makes me feel like im talking to myself
 
p.p.s. i renamed some of your vars

k fuck this im out

if anyone wants to come drink i'll be @ the Red Lion with my girl and her slutty friend, come @ me bros i'll get u laid
 
Back
Top