[T1] Help port WeapHUD to VP

-kllr2001-

Veteran X
Can someone please help me port this script to VP?


Code:
$NWH::UpdateTime = 0.30;
$NWH::XPos = 0;
$NWH::YPos = 300;
$NWH::Align = "Left";

Event::Attach(eventExit, NWH::Destroy);
Event::Attach(eventConnectionAccepted, NWH::Destroy);
Event::Attach(eventConnectionAccepted, NWH::Create);

function NWH::Create()
{
	//
	if(!$ConnectedToServer)
	{
		schedule("NWH::Create();", 1);
		return;
	}

		$NWH::hudContainer=newObject(NewWeaponHud_Container, SimGui::Control, $NWH::XPos, $NWH::YPos, 222, 550);
	
	if ($NWH::Align == "Left")
	{

		$NWH::WeapIcon00=newObject(newWeaponHud_WeapIcon00, FearGuiFormattedText, 8, 135, 45, 22);
		$NWH::WeapIcon01=newObject(newWeaponHud_WeapIcon01, FearGuiFormattedText, 8, 135, 45, 22);
		$NWH::WeapIcon02=newObject(newWeaponHud_WeapIcon02, FearGuiFormattedText, 8, 135, 45, 22);
		$NWH::WeapIcon03=newObject(newWeaponHud_WeapIcon03, FearGuiFormattedText, 8, 135, 45, 22);
		$NWH::WeapIcon04=newObject(newWeaponHud_WeapIcon04, FearGuiFormattedText, 8, 135, 45, 22);

		$NWH::AmmoText00=newObject(newWeaponHud_AmmoText00, FearGuiFormattedText, 103, 135, 0, 0);
		$NWH::AmmoText01=newObject(newWeaponHud_AmmoText01, FearGuiFormattedText, 103, 135, 0, 0); 
		$NWH::AmmoText02=newObject(newWeaponHud_AmmoText02, FearGuiFormattedText, 103, 135, 0, 0); 
		$NWH::AmmoText03=newObject(newWeaponHud_AmmoText03, FearGuiFormattedText, 103, 135, 0, 0);
		$NWH::AmmoText04=newObject(newWeaponHud_AmmoText04, FearGuiFormattedText, 103, 135, 0, 0);

		$NWH::PackIcon=newObject(newWeaponHud_PackIcon, FearGuiFormattedText, 34, 190, 22, 22);
	}
	else
	{

		$NWH::WeapIcon00=newObject(newWeaponHud_WeapIcon00, FearGuiFormattedText, 118, 0, 24, 18);
		$NWH::WeapIcon01=newObject(newWeaponHud_WeapIcon01, FearGuiFormattedText, 90, 0, 24, 18);
		$NWH::WeapIcon02=newObject(newWeaponHud_WeapIcon02, FearGuiFormattedText, 62, 0, 24, 18);
		$NWH::WeapIcon03=newObject(newWeaponHud_WeapIcon03, FearGuiFormattedText, 34, 0, 24, 18);
		$NWH::WeapIcon04=newObject(newWeaponHud_WeapIcon04, FearGuiFormattedText, 6, 0, 24, 18);

		$NWH::AmmoText00=newObject(newWeaponHud_AmmoText00, FearGuiFormattedText, 119, 22, 0, 0);
		$NWH::AmmoText01=newObject(newWeaponHud_AmmoText01, FearGuiFormattedText, 91, 22, 0, 0); 
		$NWH::AmmoText02=newObject(newWeaponHud_AmmoText02, FearGuiFormattedText, 63, 22, 0, 0); 
		$NWH::AmmoText03=newObject(newWeaponHud_AmmoText03, FearGuiFormattedText, 35, 22, 0, 0);
		$NWH::AmmoText04=newObject(newWeaponHud_AmmoText04, FearGuiFormattedText, 6, 22, 0, 0);

		$NWH::PackIcon=newObject(newWeaponHud_PackIcon, FearGuiFormattedText, 146, 0, 24, 18);
	}

	addToSet(NewWeaponHud_Container, $NWH::WeapIcon00);
	addToSet(NewWeaponHud_Container, $NWH::WeapIcon01);
	addToSet(NewWeaponHud_Container, $NWH::WeapIcon02);
	addToSet(NewWeaponHud_Container, $NWH::WeapIcon03);
	addToSet(NewWeaponHud_Container, $NWH::WeapIcon04);

	addToSet(NewWeaponHud_Container, $NWH::AmmoText00);
	addToSet(NewWeaponHud_Container, $NWH::AmmoText01);
	addToSet(NewWeaponHud_Container, $NWH::AmmoText02);
	addToSet(NewWeaponHud_Container, $NWH::AmmoText03);
	addToSet(NewWeaponHud_Container, $NWH::AmmoText04);

	addToSet(NewWeaponHud_Container, $NWH::PackIcon);

	addToSet(PlayGui, $NWH::hudContainer);

	NWH::Init();
	NWH::Update();
}

function NWH::Destroy()
{
	deleteObject($NWH::WeapIcon00);
	deleteObject($NWH::WeapIcon01);
	deleteObject($NWH::WeapIcon02); 
	deleteObject($NWH::WeapIcon03);
	deleteObject($NWH::WeapIcon04);

	deleteObject($NWH::AmmoText00);
	deleteObject($NWH::AmmoText01);
	deleteObject($NWH::AmmoText02);
	deleteObject($NWH::AmmoText03);
	deleteObject($NWH::AmmoText04);

	deleteObject($NWH::PackIcon);

	deleteObject($NWH::hudContainer); 
}


function NWH::Init()
{
	$NWH::WeaponList[0] = "Disc Launcher";
	$NWH::WeaponList[1] = "Grenade Launcher";
	$NWH::WeaponList[2] = "Mortar";
	$NWH::WeaponList[3] = "Plasma Gun";
	$NWH::WeaponList[4] = "Chaingun";
	$NWH::WeaponList[5] = "Blaster";
	$NWH::WeaponList[6] = "Laser Rifle";
	$NWH::WeaponList[7] = "ELF Gun";

	$NWH::AmmoList[0] = "Disc";
	$NWH::AmmoList[1] = "Grenade Ammo";
	$NWH::AmmoList[2] = "Mortar Ammo";
	$NWH::AmmoList[3] = "Plasma Bolt";
	$NWH::AmmoList[4] = "Bullet";

	$NWH::PackList[0] = "Inventory Station";
	$NWH::PackList[1] = "Ammo Station";
	$NWH::PackList[2] = "Energy Pack";
	$NWH::PackList[3] = "Repair Pack";
	$NWH::PackList[4] = "Shield Pack";
	$NWH::PackList[5] = "Sensor Jammer Pack";
	$NWH::PackList[6] = "Motion Sensor";
	$NWH::PackList[7] = "Ammo Pack";
	$NWH::PackList[8] = "Pulse Sensor";
	$NWH::PackList[9] = "Sensor Jammer";
	$NWH::PackList[10] = "Camera";
	$NWH::PackList[11] = "Turret";
}

function NWH::Update()
{
	%i = 0;
	$NWH::CarriedWeapons = 0;
	$NWH::MountedPack = "Nekkid";
	$NWH::MountedArmor = "Light Male";

	%clientId = getManagerId();
	
	$NWH::MountedWeaponID = getMountedItem(0);
	if ($NWH::MountedWeaponID == 11) { $NWH::MountedWeapon = "Blaster"; }
	else if ($NWH::MountedWeaponID == 13) { $NWH::MountedWeapon = "Chaingun"; }
	else if ($NWH::MountedWeaponID == 15) { $NWH::MountedWeapon = "Plasma Gun"; }
	else if ($NWH::MountedWeaponID == 17) { $NWH::MountedWeapon = "Grenade Launcher"; }
	else if ($NWH::MountedWeaponID == 19) { $NWH::MountedWeapon = "Mortar"; }
	else if ($NWH::MountedWeaponID == 21) { $NWH::MountedWeapon = "Disc Launcher"; }
	else if ($NWH::MountedWeaponID == 22) { $NWH::MountedWeapon = "Laser Rifle"; }
	else if ($NWH::MountedWeaponID == 24) { $NWH::MountedWeapon = "ELF Gun"; }
	else if ($NWH::MountedWeaponID == 25) { $NWH::MountedWeapon = "Repair Gun"; }

	for (%clear_temp = 0; %clear_temp < 6; %clear_temp++)
	{
		$NWH::CarriedWeaponList[%clear_temp] = "";
		$NWH::CarriedWeaponAmmo[%clear_temp] = "";
	}

	for (%weapon_count = 0; %weapon_count < 8; %weapon_count++)
	{
		%weapon_temp = getItemCount($NWH::WeaponList[%weapon_count]);

		if (%weapon_temp == 1)
		{
			$NWH::CarriedWeaponList[%i] = $NWH::WeaponList[%weapon_count];
			
			if ( $NWH::CarriedWeaponList[%i] == $NWH::MountedWeapon) {  $NWH::MountedWeaponPosition = %i; }
			if (%weapon_count < 5)
			{
				$NWH::CarriedWeaponAmmo[%i] = getItemCount($NWH::AmmoList[%weapon_count]);
			}
			else
			{
				$NWH::CarriedWeaponAmmo[%i] = "~";
			}

			%i++;
			$NWH::CarriedWeapons++;
		}
	}

	for (%pack_count = 0; %pack_count < 12; %pack_count++)
	{
		%pack_temp = getItemCount($NWH::PackList[%pack_count]);
		if (%pack_temp == 1) { $NWH::MountedPack = $NWH::PackList[%pack_count]; break; }
	}

	for (%armor_count = 0; %armor_count < 3; %armor_count++)
	{
		%armor_temp = getItemCount($NWH::ArmorList[%armor_count]);
		if (%armor_temp == 1) { $NWH::MountedArmor = $NWH::ArmorList[%armor_count]; break; }
	}


	NWH::UpdateHud();
}

function NWH::UpdateHud()
{
	for (%j = 0; %j < $NWH::CarriedWeapons; %j++)
	{
		control::setVisible("newWeaponHud_WeapIcon0" @ %j, True);
		
		if (%j == $NWH::MountedWeaponPosition)		
		{
			control::setVisible("newWeaponHud_AmmoText0" @ %j, True);
		}
		else
		{
			control::setVisible("newWeaponHud_AmmoText0" @ %j, False);
		}

		if (%j == $NWH::MountedWeaponPosition)
		{
			control::setValue("newWeaponHud_WeapIcon0" @ %j, "<B0,0:weaponHud\\" @ $NWH::CarriedWeaponList[%j] @ " On.bmp>");
			if ($NWH::CarriedWeaponAmmo[%j] == "~")
			{
				control::setValue("newWeaponHud_AmmoText0" @ %j, "<B0,0:weaponHud\\blank1.bmp><B0,0:weaponHud\\Infinity On.bmp>");
			}
			else
			{
				if ($NWH::CarriedWeaponAmmo[%j] < 10)
				{
					control::setValue("newWeaponHud_AmmoText0" @ %j, "<B0,0:weaponHud\\blank2.bmp><f0>" @ $NWH::CarriedWeaponAmmo[%j]);
				}
				else if (($NWH::CarriedWeaponAmmo[%j] > 9) && ($NWH::CarriedWeaponAmmo < 100))
				{
					control::setValue("newWeaponHud_AmmoText0" @ %j, "<B0,0:weaponHud\\blank1.bmp><f0>" @ $NWH::CarriedWeaponAmmo[%j]);
				}
				else if ($NWH::CarriedWeaponAmmp[%j] > 99)
				{
					control::setValue("newWeaponHud_AmmoText0" @ %j, "<f0>" @ $NWH::CarriedWeaponAmmo[%j]);
				}
			}
		}
		else
		{
			control::setValue("newWeaponHud_WeapIcon0" @ %j, "<B0,0:weaponHud\\" @ $NWH::CarriedWeaponList[%j] @ " Off.bmp>");
			if ($NWH::CarriedWeaponAmmo[%j] == "~")
			{
				control::setValue("newWeaponHud_AmmoText0" @ %j, "<B0,0:weaponHud\\blank1.bmp><B0,0:weaponHud\\Infinity Off.bmp>");
			}
			else
			{
				if ($NWH::CarriedWeaponAmmo[%j] < 10)
				{
					control::setValue("newWeaponHud_AmmoText0" @ %j, "<B0,0:weaponHud\\blank2.bmp><f1>" @ $NWH::CarriedWeaponAmmo[%j]);
				}
				else if (($NWH::CarriedWeaponAmmo[%j] > 9) && ($NWH::CarriedWeaponAmmo < 100))
				{
					control::setValue("newWeaponHud_AmmoText0" @ %j, "<B0,0:weaponHud\\blank1.bmp><f1>" @ $NWH::CarriedWeaponAmmo[%j]);
				}
				else if ($NWH::CarriedWeaponAmmp[%j] > 99)
				{
					control::setValue("newWeaponHud_AmmoText0" @ %j, "<f1>" @ $NWH::CarriedWeaponAmmo[%j]);
				}
				
			}
		}
	}

	if (%j < 5)
	{
		while (%j < 5)
		{
			control::setVisible("newWeaponHud_WeapIcon0" @ %j, False);
			control::setVisible("newWeaponHud_AmmoText0" @ %j, False);
			%j++;
		}
	}

	control::setValue(newWeaponHud_PackIcon, "<B0,0:weaponHud\\"@ $NWH::MountedPack @ ".bmp>");

	schedule("NWH::Update();", $NWH::UpdateTime);
}
 
mmm, it may be because its 6:47 am or because im still very drunk, but i'd say theres no reason why that shouldnt work for viking ;/
 
Code:
Event::Attach(eventConnectionAccepted, NWH::Destroy);
Event::Attach(eventConnectionAccepted, NWH::Create);

Try change those two lines to:
Code:
Event::Attach(eventLoadPlayGui, NWH::Destroy);
Event::Attach(eventLoadPlayGui, NWH::Create);

Oh, btw, I wrote that script ;)
Also, I did make a Viking version, so if you find the release thread you should be able to download the Viking version. :)
 
Bah, forgot to turn off smilies in my previous post.

Use my suggested solution if there is no Sytax errors when the script tries to run of course. If there are any errors tell us what lines and should be able to fix it.
 
Back
Top