[Script] Weapons hud

Groove
Posts: 218
Joined: Thu Apr 17, 2014 10:36 pm

Re: [Script] Weapons hud

Post by Groove »

here's the scriptGL version that we've been talking about

http://pastebin.com/cGfzdp2r
Groove
Posts: 218
Joined: Thu Apr 17, 2014 10:36 pm

Re: [Script] Weapons hud

Post by Groove »

perrinoia wrote: PSS: Does anyone know how to create a hud with a rotating shapefile, like how the inventory station has a spinning item, or the main menu when you first launch tribes has the spinning Tribes logo at the bottom?
the spinning logo is a pba animation, and iirc the invy uses FearGui::ShapeView but there's some wackyness when it comes to where it positions in containers
User avatar
DaJ4ck3L
Crow{OZ}
Posts: 3375
Joined: Thu Jul 22, 2010 11:51 pm
Contact:

Re: [Script] Weapons hud

Post by DaJ4ck3L »

www.thelandofoz.net/weaponhud

here are the imgs for it. i haven't redone the anni imgs yet to match it.
Image
perrinoia
Site Admin
Posts: 3732
Joined: Sun Jul 01, 2012 7:18 pm

Re: [Script] Weapons hud

Post by perrinoia »

Hmm... I've got a few suggestions for you, too, Groove.

I've made one simple modification to your script... You had 19 lines of code that checked the item counts for each item. I simply added one check in function WeaponHud::draw(), and removed your 19 checks.

Code: Select all

// ScriptGL WeaponHUD by GreyHound / Hunden
// based on Andrews original design in hudbot
// slightly modified to draw a box around the mounted weapon by some other dude

$WeaponHud::Texture["Undefined"] = "WeaponHUD.Undefined.tga";
$WeaponHud::Texture["turret"] = "WeaponHUD.turret.tga";
$WeaponHud::Texture["shieldpack"] = "WeaponHUD.shieldpack.tga";
$WeaponHud::Texture["sensorjammerpack"] = "WeaponHUD.sensorjammerpack.tga";
$WeaponHud::Texture["sensorjammer"] = "WeaponHUD.sensorjammer.tga";
$WeaponHud::Texture["repairpack"] = "WeaponHUD.repairpack.tga";
$WeaponHud::Texture["pulse"] = "WeaponHUD.pulse.tga";
$WeaponHud::Texture["motion"] = "WeaponHUD.motion.tga";
$WeaponHud::Texture["ammopack"] = "WeaponHUD.ammopack.tga";
$WeaponHud::Texture["energypack"] = "WeaponHUD.energypack.tga";

$WeaponHud::Texture["sniper"] = "WeaponHUD.sniper.tga";
$WeaponHud::Texture["plasma"] = "WeaponHUD.plasma.tga";
$WeaponHud::Texture["mortar"] = "WeaponHUD.mortar.tga";
$WeaponHud::Texture["grenade"] = "WeaponHUD.grenade.tga";
$WeaponHud::Texture["blaster"] = "WeaponHUD.blaster.tga";
$WeaponHud::Texture["chaingun"] = "WeaponHUD.chaingun.tga";    
$WeaponHud::Texture["elf"] = "WeaponHUD.elf.tga";
$WeaponHud::Texture["disc"] = "WeaponHUD.disc.png";
$WeaponHud::Texture["TargetLaser"] = "WeaponHUD.TargetLaser.tga";

$WeaponHud::Texture["camera"] = "WeaponHUD.camera.tga";
$WeaponHud::Texture["inventory"] = "WeaponHUD.inventory.tga";  
$WeaponHud::Texture["deployable"] = "WeaponHUD.deployable.tga";
$WeaponHud::Texture["ammostation"] = "WeaponHUD.ammostation.tga";



function vhud::WeaponHud::onRender()
{
	if(!Control::getVisible("ScriptGL::vWeaponHud") || $Scriptgl::CurrentGui != "playGui" || $pref::vWeaponHUD::hide == "true")
		return;
	
	%pos = Control::getPosition("ScriptGL::vWeaponHud");
	%x = getWord(%pos, 0);
	%y = getWord(%pos, 1);
	
	glSetFont( "arial", 9, 0, 9 );
	
	%slot = -1;
	WeaponHud::Draw(%x + %slot++ * 80, %y + 40, $WeaponHud::Texture["disc"], GetItemCount("Disc"), "Disc Launcher");
	WeaponHud::Draw(%x + %slot++ * 80, %y + 40, $WeaponHud::Texture["grenade"], GetItemCount("Grenade Ammo"), "Grenade Launcher");
	WeaponHud::Draw(%x + %slot++ * 80, %y + 40, $WeaponHud::Texture["chaingun"], GetItemCount("Bullet"), "Chaingun");
	WeaponHud::Draw(%x + %slot++ * 80, %y + 40, $WeaponHud::Texture["sniper"], "~", "Laser Rifle");
	WeaponHud::Draw(%x + %slot++ * 80, %y + 40, $WeaponHud::Texture["mortar"], GetItemCount("Mortar Ammo"), "Mortar");
	WeaponHud::Draw(%x + %slot++ * 80, %y + 40, $WeaponHud::Texture["blaster"], "~", "Blaster");
	WeaponHud::Draw(%x + %slot++ * 80, %y + 40, $WeaponHud::Texture["elf"], "~", "ELF Gun");
	WeaponHud::Draw(%x + %slot++ * 80, %y + 40, $WeaponHud::Texture["plasma"], GetItemCount("Plasma Bolt"), "Plasma Gun");
	WeaponHud::Draw(10 + %slot++ * 80, %y + 40, $WeaponHud::Texture["TargetLaser"], "~", "Targeting Laser");
	
	%slot = -1;
	//	WeaponHud::Draw(10 + %slot++ * 80, %y + 1 * 40, $WeaponHud::Texture["Undefined"], 0);
	WeaponHud::Draw(%x + %slot++ * 80, %y, $WeaponHud::Texture["turret"], "", "Turret");
	WeaponHud::Draw(%x + %slot++ * 80, %y, $WeaponHud::Texture["shieldpack"], "", "Shield Pack");
	WeaponHud::Draw(%x + %slot++ * 80, %y, $WeaponHud::Texture["sensorjammerpack"], "", "Sensor Jammer Pack");
	WeaponHud::Draw(%x + %slot++ * 80, %y, $WeaponHud::Texture["sensorjammer"], "", "Sensor Jammer");
	WeaponHud::Draw(%x + %slot++ * 80, %y, $WeaponHud::Texture["repairpack"], "", "Repair Pack");
	WeaponHud::Draw(%x + %slot++ * 80, %y, $WeaponHud::Texture["pulse"], "", "Pulse Sensor");
	WeaponHud::Draw(%x + %slot++ * 80, %y, $WeaponHud::Texture["motion"], "", "Motion Sensor");
	WeaponHud::Draw(%x + %slot++ * 80, %y, $WeaponHud::Texture["ammopack"], "", "Ammo Pack");
	WeaponHud::Draw(%x + %slot++ * 80, %y, $WeaponHud::Texture["energypack"], "", "Energy Pack");
	
	%slot = -1;
	WeaponHud::Draw(%x + %slot++ * 80, %y, $WeaponHud::Texture["camera"], "", "Camera");
	WeaponHud::Draw(%x + %slot++ * 80, %y, $WeaponHud::Texture["inventory"], "", "Inventory Station");
	WeaponHud::Draw(%x + %slot++ * 80, %y, $WeaponHud::Texture["ammostation"], "", "Ammo Station");
	
}

function WeaponHud::Draw(%x, %y, %tex, %count, %Name)
{
	if(getItemCount(%Name) < 1)	// Moved here to simplify script. -perrinoia
		return;
	
	glEnable($GL_TEXTURE_2D);
	glBindTexture($GL_TEXTURE_2D, %tex);
	glColor3f(1.0, 1.0, 1.0, 1.0);
	
	glBegin($GL_QUADS);
	glTexCoord2f(0.0, 1.0);
	glVertex2f(%x, %y);
	glTexCoord2f(1.0, 1.0);
	glVertex2f(%x+60, %y);
	glTexCoord2f(1.0, 0.0);
	glVertex2f(%x+60, %y+30);
	glTexCoord2f(0.0, 0.0);
	glVertex2f(%x, %y+30);
	glEnd();
	
	glDrawString(%x + 50, %y + 20, %count);
	glColor4ub(255, 255, 255, 255);
	if(GetItemdesc(GetMountedItem(0)) == %Name)
		glDrawTexture("wephud_border.png", $GLEX_SCALED, %x, %y, 1, 1 );
}


function vhud::WeaponHud::create()
{
	if ( $vhud::WeaponHud::Loaded )
	return;
	
	$vhud::WeaponHud::Loaded = true;
	
	vhud::create("ScriptGL::vWeaponHud", "0% 0%", "0% 0%", vhud::WeaponHud::onRender );
	HUD::New("ScriptGL::vWeaponHud", 200, 200, 330, 75, onMouseRMB, onMouseRMB);
}

vhud::WeaponHud::create();
However, I have a few more suggestions, if you're interested...

First, if you rename all of your image files so they match the item descriptions, you'll be able to eliminate the vast majority of that code, including the entire $WeaponHud::Texture[] variable array.

Second, you can include all items in the hud, not just weapons and packs, to combine the item hud (beacons, grenades, health kits, mines), and the weapon hud. By doing this, the hud could potentially have icons for armors, and flags, too! The script should be written in such a way, that any item description that has an image, gets displayed in the hud. (PS: isFile(%name) is a function in Tribes!)

Third, if item count is less than 1, skip it, if it is 1, display only the icon, if it is greater than 1, display icon and count (and if the item is mounted in the weapon slot, draw a box around the icon).

Fourth, if you do add armor icons to the hud, you can combine that icon with the health bar, by adding damage skins or overlays, or something like that.

The tricky part will be arranging the icons in categories, without the variable array and complex scripting. I'm trying to figure out how to ascertain itemdata classnames via client side script, and having no luck, at the moment. Also, not sure how to figure out which ammo belongs to which weapon, without hard coding it on the client's side, as you've done.
Image
Groove
Posts: 218
Joined: Thu Apr 17, 2014 10:36 pm

Re: [Script] Weapons hud

Post by Groove »

nice, thanks for the update there perrin :)

it's not really my script all i added was the 2 lines that check if its the mounted weapon and draw a box around it

you guys know wayyy more than i do about scripting in general, alls i really know is scriptGL and some .exe tricks i stole from nofix/emjay/greyhound

i think the array is there just because those are kinda the standard set of weaponhud icons that have been floating around forever and have always been named that way since hudbot... but it does make sense to clean that up :)
Groove
Posts: 218
Joined: Thu Apr 17, 2014 10:36 pm

Re: [Script] Weapons hud

Post by Groove »

hrm playing around, because ur sending the draw command each time whether the weapon is there or not, it's still incrementing the slot counter every time rather than only when it hits a weapon you actually have
perrinoia
Site Admin
Posts: 3732
Joined: Sun Jul 01, 2012 7:18 pm

Re: [Script] Weapons hud

Post by perrinoia »

Oh yeah... Should increment in the draw function, too, or make the draw function return true or false, and increment based on that...

PS: I got ShapeView working, and figured out the coordinate thing... (0 0) = Upper left, near energy and health huds. (0 1080) = lower left, near weapon hud. etc...

So I put five of them on the left side of my screen, equally spaced, named from top to bottom; ArmorView, DefaultView, FlagView, PackView, WeaponView.

I then wrote a script that checked the mounted item in each slot and set the item to the appropriate ShapeView.

The item value has to be the itemType (number), not the description. And ascertaining the armor is difficult, because I have to loop through all of the possible armors and check item count, because I don't know a simple clientside command to get my own armor.

I ran into a few problems, though... Such as, a black wedge in the background that spins around the shapeview like a lighthouse. They disappear when you assign something that is not an item, and they don't come back. I can't figure out how to pause the spinning. Etc...

A simple solution to the lighthouse effect would probably be to make the shapeview opaque. I did not try this, as I assumed it would be ugly, but maybe I should.
Image
Groove
Posts: 218
Joined: Thu Apr 17, 2014 10:36 pm

Re: [Script] Weapons hud

Post by Groove »

hrm sounds cool keep us updated :)
perrinoia
Site Admin
Posts: 3732
Joined: Sun Jul 01, 2012 7:18 pm

Re: [Script] Weapons hud

Post by perrinoia »

Let's play pros and cons of ShapeView...

Pro: You don't have to define custom images. There is already a 3d shapefile for every item you can have.
Con: It doesn't support multiple shapefiles per item, so particlebeam looks like targeting laser and tank shredder looks like chaingun, etc...

In light of this discovery, I don't think it will replace the weapon hud, but it can definitely replace the miscellaneous item hud!

I intend to have a beacon, flag, grenade, health kit, and a mine, and also hope to have an armor one too... But that one is more complicated, so I'll worry about it last.

I also intend to have a toggle to make the hud horizontal or verticle.

I want to add it to the K menu, so it can be hidden or shown, and dragged around the screen, but I'll probably need help configuring that.
Image
Post Reply