[Weapon Hud] Script help

Xml V2.0

Veteran XV
I am wanting have my weapons come up individually, which i got. But the ammo count still comes up when i am not using a particular weapon, which is what i don't want.

I am no coder so your help is appreciated in achieving what i am asking for.

Or if someone can make a simpler code than the weaponsHud.acs that i am using, that would be great as well.

6T0M6G7.png


Code:
//What a POS this is, but it kinda works, somehow.

Event::Attach(eventConnected, WH::Init);

Event::Attach(eventExitStation, WH::Update);
//Dunno why you have to use a schedule here?
Event::Attach(eventItemReceived, "schedule::add(\"WH::Update();\",0);");

//My events that I added to this pile of junk to make it run smoother
Event::Attach(eventUsedItem, WH::Update);
Event::Attach(eventDropItem, WH::Update);
Event::Attach(EventNextWeapon, WH::Update);
Event::Attach(EventPrevWeapon, WH::Update);
Event::Attach(EventYouFired, WH::Update);

//This exists because I can't get an event for all nec. updates, so run it over and over. 
$WH::UpdateTime = 0.5;

//Helper functions
//Function attachments exist so that you don't have to overwrite them anymore. -Noxwizard
function itemUsed(%desc) after use
{
    %type = getItemType(%desc);
    if (%type != -1)
    {
        Event::Trigger("eventUsedItem", %type);
    }
}

function itemDropped(%desc) after drop
{
    %type = getItemType(%desc);
    if (%type != -1)
    {
        Event::Trigger("eventDropItem", %type);
    }
}

function onNext() before nextWeapon
{
    schedule("checkWeapon(\"Next\", " @ $CheckWepNum++ @ ");", 1);
}

function onPrev() before prevWeapon
{
    schedule("checkWeapon(\"Prev\", " @ $CheckWepNum++ @ ");", 1);
}
//End helpers

function checkWeapon(%type, %num)
{
	if(%num == $CheckWepNum)
    {
		Event::Trigger("event" @ %type @ "Weapon", GetMountedItem(0));
	}
}

function WH::Update()
{
	
	%slot = 0;

	//For all possible weapons
	for (%i=0; %i<=$Weapon::Count; %i++)
	{
		//If the weapon is in your loadout
		if (getItemCount($Weapon::Name[%i]) > 0)
		{
			//Get Ammo
			%ammo = $Weapon::Ammo[%i];
			if (%ammo !="")
				%ammoNum = getItemCount(%ammo);

			//If you are holding the weapon highlight it
			%mounted = false;
			if (getItemType($Weapon::Name[%i]) == getMountedItem(0))
			{
				%mounted = true;
				//Highlight ammo on firing and increase update time
				if ($AF::Firing == "TRUE")
				{
					%ammoNum = "<f2>"~%ammoNum;
					$WH::UpdateTime = 0.1;				
				}
				else
				{
					%ammoNum = "<f1>"~%ammoNum;
					$WH::UpdateTime = 0.5;
				}
			}
			
			//Draw our weapon
			if(%mounted)
				control::setValue("WeaponHUD::Item"~%slot,"<B0,0:modules\\weaponshud\\"~$Weapon::File[%i]~"on.png>");
			else
				control::setValue("WeaponHUD::Item"~%slot,"<B0,0:modules\\weaponshud\\"~$Weapon::File[%i]~".png>");

			//Draw our ammo
			control::setValue("WeaponHUD::Ammo"~%slot,%ammoNum);

			//Go to the next slut, err slot
			%ammoNum = "";
			%slot++;
		}
	}

	//Clear the rest of the weapon slots
	for (%slot; %slot<=10;%slot++)
	{
		control::setValue("WeaponHUD::Item"~%slot,"");
		control::setValue("WeaponHUD::Ammo"~%slot,"");

	}

	//Fuck I want to get rid of this. Someone help!
	schedule::add("WH::Update();", $WH::UpdateTime);

}

//Add our items
function WH::AddItem(%item, %file, %ammo) {
	if(getItemType(%item) != -1) {
		//echo("Added "~%item);

		//ID num for weapon
		%num = getItemType(%item);
		$Weapon::Num[$Weapon::Count] = %num;

		//Name of Weapon
		$Weapon::Name[$Weapon::Count] = %item;

		//Filename for image
		$Weapon::File[$Weapon::Count] = %file;

		//Ammo Name for weapon
		$Weapon::Ammo[$Weapon::Count] = %ammo;

		//++ baby!
		$Weapon::Count++;

		return true;
	}
	return false;
}

//Crappy bubble sort, short list, who cares, only runs on init anyway
function WH::Sort()
{
	for(%i=0;%i<$Weapon::Count;%i++)
	{
		for (%j=1;%j<$Weapon::Count;%j++)
		{
			if ($Weapon::Num[%j] < $Weapon::Num[%j-1])
				WH::Swap(%j,%j-1);
		}
	}
}
			
//Swap two weapons	
function WH::Swap(%one,%two)
{
		%temp[0] = $Weapon::Num[%one];
		%temp[1] = $Weapon::Name[%one];
		%temp[2] = $Weapon::File[%one];
		%temp[3] = $Weapon::Ammo[%one];

		$Weapon::Num[%one] = $Weapon::Num[%two];
		$Weapon::Name[%one] = $Weapon::Name[%two];
		$Weapon::File[%one] = $Weapon::File[%two];
		$Weapon::Ammo[%one] = $Weapon::Ammo[%two];

		$Weapon::Num[%two] = %temp[0];
		$Weapon::Name[%two] = %temp[1];
		$Weapon::File[%two] = %temp[2];
		$Weapon::Ammo[%two] = %temp[3];
}

//Wake Sleep shit
function WH::Wake() {
	$WH::Awake = true;
	WH::Update();
}

function WH::Sleep() {
	Schedule::Cancel("WH::Update();");
	$WH::Awake = false;
}

function WH::Create() {

	if ($WeaponHUD::Loaded)
		return;
	$WeaponHUD::Loaded = true;

	$WeaponHUD::Awake = false;

	HUD::New( "WeaponHUD::Container", 0, 8, 710, 70, WH::Wake, WH::Sleep );

	//11 slots should be enough, any mod that has more than 11 can suck my ass
	for (%i=0;%i<=10;%i++)
	{
		newObject( "WeaponHUD::Item"~%i, FearGuiFormattedText, 0+(70*%i), 5, 70, 35 );
		newObject( "WeaponHUD::Ammo"~%i, FearGuiFormattedText, 29+(70*%i), 25, 70, 35 );

		HUD::Add( "WeaponHUD::Container", "WeaponHUD::Item"~%i );
		HUD::Add( "WeaponHUD::Container", "WeaponHUD::Ammo"~%i );

	}
}

function WH::Init() {

    $CheckWepNum = 0;

	//Clear out current variables
	DeleteVariables("$Weapon::*");
	$Weapon::Count = 0;

	//Base Items
	WH::AddItem("Blaster","blaster");
	WH::AddItem("ChainGun", "chaingun", "Bullet");
	WH::AddItem("Disc Launcher", "disk", "Disc");
	WH::AddItem("Elf Gun", "elf");
	WH::AddItem("Grenade Launcher", "grenade", "Grenade Ammo");
	WH::AddItem("Laser Rifle", "sniper");
	WH::AddItem("Mortar", "mortar", "Mortar Ammo");
	WH::AddItem("Plasma Gun", "plasma", "Plasma Bolt");
	WH::AddItem("Repair Gun", "repair");
	WH::AddItem("Inventory Station", "inventory");
	WH::AddItem("Ammo Station", "ammostation");
	WH::AddItem("Ammo Pack", "ammopack");
	WH::AddItem("Camera" ,"camera");
	WH::AddItem("Energy Pack" ,"energypack");
	WH::AddItem("Motion Sensor","motionsensor");
	WH::AddItem("Pulse Sensor", "pulse");
	WH::AddItem("Repair Pack" ,"repairpack");
	WH::AddItem("Shield Pack" ,"shieldpack");
	WH::AddItem("Sensor Jammer Pack", "sensorjammerpack");
	WH::AddItem("Sensor Jammer", "sensorjammer");
	WH::AddItem("Turret", "turret");

	//Renegades Classic Stuff, mostly I just made shit look like an ammopack
	WH::AddItem("Hyper Blaster","plasma");
	WH::AddItem("Rocket Launcher","mortar","Rockets");
	WH::AddItem("Sniper Rifle","sniper","Sniper Bullet");
	WH::AddItem("Dart Rifle","sniper","Poison Dart");
	WH::AddItem("Magnum","blaster","Magnum Bullets");
	WH::AddItem("Shockwave Cannon","elf");
	WH::AddItem("Railgun","sniper","Railgun Bolt");
	WH::AddItem("Vulcan","chaingun","Vulcan Bullet");
	WH::AddItem("Flame Thrower","grenade");
	WH::AddItem("Ion Rifle","grenade");
	WH::AddItem("Omega Cannon","elf");
	WH::AddItem("Thunderbolt","elf");
	WH::AddItem("Engineer Repair-Gun","repair");
	WH::AddItem("Cloaking Device","sensorjammerpack");
	WH::AddItem("StealthShield Pack","shieldpack");
	WH::AddItem("Regeneration Pack","repairpack");
	WH::AddItem("Lightning Pack","energypack");
	WH::AddItem("Suicide DetPack","ammopack");
	WH::AddItem("Command Station","inventory");
	WH::AddItem("Ion Turret","turret");
	WH::AddItem("Laser Turret","camera");
	WH::AddItem("Shock Turret","camera");
	WH::AddItem("Mortar Turret","turret");
	WH::AddItem("Plasma Turret","turret");
	WH::AddItem("Vulcan Turret","turret");
	WH::AddItem("Rail Turret","turret");
	WH::AddItem("Missile Turret","turret");
	WH::AddItem("Force Field","ammopack");
	WH::AddItem("Large Force Field","ammopack");
	WH::AddItem("Blast Wall","ammopack");
	WH::AddItem("Hologram","ammopack");
	WH::AddItem("Mechanical Tree","ammopack");
	WH::AddItem("Springboard","ammopack");
	WH::AddItem("Deployable Platform","ammopack");
	WH::AddItem("Teleport Pad","ammopack");
	WH::AddItem("Interceptor Pack","ammopack");
	WH::AddItem("StealthHPC Pack","ammopack");

	//I don't give a shit about mods, this is a bitch, someone else can write more here

	//Sort the weapons list by ID so they are in order
	WH::Sort();

	//Add to GUI
	WH::Create();
}
 
yeah you really dont need a weaponhud that complex just to show the weapon description and ammo count

here's a snippet from my sgl + vhudmover config, it should give you an idea of how simple it needs to be

Code:
// weapon name and ammo vhuds for 1.40 and vhudmover

vhud::create( "HWepNameHud", "18% 4%", "82% 96%", HWepNameHud::onRender );
vhud::add_item( "pixelsize_text", "40%" );
vhud::add_item( "label_wepname", "3% 25%" );
vhud::add_item( "label_ammo", "83% 25%" );

function HWepNameHud::onRender()
{
	if($Scriptgl::CurrentGui != "playGui")
		return;

	%wep = GetItemdesc(GetMountedItem(0));
	if( %wep != "" )
	{
		glcolor4ub(255,224,0,192);	// color to match the Ammo vhud
		vhud::render_text( "label_wepname", "verdana", "pixelsize_text", $GLEX_SMOOTH, %wep );

	if($Weapon::Ammo < 0)
		%display = "~";
	else
		%display = $Weapon::Ammo;

	vhud::render_text( "label_ammo", "verdana", "pixelsize_text", $GLEX_SMOOTH, %display );

	}
}

really all its doing is drawing GetItemdesc(GetMountedItem(0)) (the description of the weapon mounted in slot0) and $Weapon::Ammo

if there's no description for the mounted item, then it skips the draw

ez pz
 
p.s. iirc that won't work with versions before 1.40 since i dont think they support the GetItemDesc command

and the draws are setup for vhudmover so it's probably not copy pasta code unless you have my vhudmover support scripts
 
i m not smart enuf 2 fix this problem 4 realz

only hunden can fix (or if he release sgl source mayb some1 else can)
 
Back
Top