1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

[Help!] Displaying Weapon Names for Custom Weapons

Discussion in 'Infiltration Development' started by UN17, May 21, 2004.

  1. UN17

    UN17 Taijutsu Specialist

    Joined:
    Dec 7, 2003
    Messages:
    675
    Likes Received:
    0
    Hi INF Dev community! One thing that bugged me is that I couldn't display Weapon Names in the lower HUD for custom weapons. Duke's XM8, M16A4, my DE.50AE, none would have a Weapon Name shown.

    So I hacked into Duke's Add HUD mutator. And made it work hardcoded. Now I need your help! Will the Programming masters who are working on the INF Weapon Bonus pack make a "fix" to allow custom weapons to have their WeaponNames displayed? If so, tell me now so I can stop working on it!

    If not, here's the pseudocode for what I want to do. I need help executing it though:

    Code:
            	// WEAPON NAME
            	Canvas.SetPos( BaseX + k*WeaponOffset, BaseY );
            	if( HUDColor != WhiteColor )
              		Canvas.DrawColor = WhiteColor;
            	else
              		Canvas.DrawColor = RedColor;
            	j = FindWeaponNameY(WeaponSlot[i].ItemName);
    			if ( j >= 0)
    			{
            		Canvas.DrawTile( Texture'InfiltrationUT.NamesIcon',128,12,0,j,128,12 );
    			}
    
    /* NEW CODE BELOW FOR CUSTOM WEAPON NAMES! */
    
    			else
    			{
            		Canvas.DrawTile( CustomWeaponName ,128,12,0,0,128,12 );
    			}
    Ok, so in the original code, the engine checks a list for known weapons and returns the Y value lookup for the NamesIcon.pcx. If it didn't find the weapon name, it returned -1 and quit. So... Here's what I wanted to do! I created:
    var Texture CustomWeaponName
    My DE.50AE has this line in it's defaultproperties: Texture'SecondWind.Icons.SWDE50Icon'

    Now, hardcoded, it gives the result you see in the picture. Yay! But how do I make the engine call the CustomWeaponName value from the weapon in question, then return the value to the WeaponDisplayHUDfix script so it can enter the information and execute it as normal?

    I tried this: INFc_Weapon(Weapon).CustomWeaponName but on compile it gave me an error saying that that member did not exist. Of course it doesn't exist in INFc_Weapon! It only exists (so far) in SW_DE50 which extends INFc_Weapon.

    Please help! Or tell me to give up and you guys do it!
     

    Attached Files:

    Last edited: May 21, 2004
  2. Beppo

    Beppo Infiltration Lead-Programmer

    Joined:
    Jul 29, 1999
    Messages:
    2,284
    Likes Received:
    1
    Use the original functions made for this but place the keyword 'simulated' in front of the function name to let them work online too.
    so:
    Code:
    // if a new weapon is added you can use this function to give it its own HUD icon
    simulated function CheckIcon(out Texture Icon) {
    		Icon = Texture'Mypackage.MyWeaponIcon';
    }
    // if a new weapon is added you can use this function to give it its HUD weapon firing modes
    simulated function bool CheckWeaponMode(out int WeaponModesYOffset, out int WeaponModeActiveYOffset, out int WeaponModesMaxY) {
    	// semi-auto - other setups for ie semi-burst-auto can be found in class InfChallengeHUD, function DrawWeaponMode
    	WeaponModesYOffset = 60;
    	switch( FireMode )
    	{
    		case 0 : WeaponModeActiveYOffset = 13;
    				 break;
    		case 1 : WeaponModeActiveYOffset = 7;
    				 break;
    	}
    	return True;
    }
    
    This works and Duke's Add HUD mutator isn't needed anymore then. Sorry that the example codes from the UT8Ball within INF 2.9 missed the simulated keywords for these two functions.

    The specific weapon names are not editable this way. I will check it out.
     
    Last edited: May 22, 2004
  3. Beppo

    Beppo Infiltration Lead-Programmer

    Joined:
    Jul 29, 1999
    Messages:
    2,284
    Likes Received:
    1
    ok here is the stuff you need to add to your weapon class. Fully tested and working on- and offline:
    Code:
    var string WeaponName;
    
    // draw the weapon name on the HUD icon
    simulated function RenderOverlays( canvas Canvas ) {
    	if ( bDroppedInventory || bHideWeapon || (Owner == None) || (Mesh == PickupViewMesh) )
    		return;
    	Super.RenderOverlays( Canvas );
      	if (Pawn(Owner).Weapon == self && WeaponName != "")
    		RenderWeaponName(Canvas);
    }
    
    simulated function RenderWeaponName( canvas Canvas ) {
      	local Weapon W, WeaponSlot[11];
    	local inventory inv;
      	local int i, k, BaseY, BaseX, WeaponOffset;
    
      	BaseX = 0.2*Canvas.ClipX + 46;
      	BaseY = Canvas.ClipY - 61 + 4;
      	WeaponOffset = 76;
    
    	WeaponSlot[InventoryGroup] = self;
    	i = 0;
    	for ( Inv=Pawn(Owner).Inventory; Inv!=None; Inv=Inv.Inventory )	{
    		if ( Inv.IsA('Weapon') && (Inv != Pawn(Owner).Weapon) )	{
    			W = Weapon(Inv);
    			if ( WeaponSlot[W.InventoryGroup] == None )
    				WeaponSlot[W.InventoryGroup] = W;
    			else if (
    				(WeaponSlot[W.InventoryGroup] != Pawn(Owner).Weapon)
    				&& ( ( W == Pawn(Owner).PendingWeapon)
    				|| (WeaponSlot[W.InventoryGroup].AutoSwitchPriority < W.AutoSwitchPriority)
    				&& INFc_Weapon(W)!=none && !INFc_Weapon(W).OutOfAmmo() )
    				)
    				WeaponSlot[W.InventoryGroup] = W;
    		}
    		i++;
    		if ( i > 100 ) break;
    	}
    
      	k=0;
      	for ( i=0; i < ArrayCount(WeaponSlot); i++ )
      	{
          	if( WeaponSlot[i] == self )
          	{
            	// WEAPON NAME
    			Canvas.Style = ERenderStyle.STY_Normal;
            	Canvas.SetPos( BaseX + k*WeaponOffset, BaseY );
              	Canvas.DrawColor.R = 255; Canvas.DrawColor.G = 255; Canvas.DrawColor.B = 255;
    			Canvas.Font = Canvas.SmallFont;
              	Canvas.DrawText( WeaponName );
          	}
          	if( WeaponSlot[i] != None )
    			k++;
    	}
    }
    
    defaultproperties
    {
    	 WeaponName="MyNewWeapon"
    }
    
    @moderator, plz sticky, thx!
     
    Last edited: May 22, 2004
  4. UN17

    UN17 Taijutsu Specialist

    Joined:
    Dec 7, 2003
    Messages:
    675
    Likes Received:
    0
    Success!

    Beppo! Thank you! I took your code and added my CustomWeaponName code and it worked! I now have code that can display either a Custom Weapon name texture or Custom Weapon name text on the Weapon HUD offline and online! Coding is awesome!

    For all Custom Weapons makers:

    Insert this code into your Weapon's main script for it to have a Weapon Name displayed offline/online. You will need these variables declared and added into the DefaultProperties:

    Code:
    var	string	WeaponName;
    var	texture NameTex;
    
    defaultproperties
    {
         WeaponName="DE .50AE"
         NameTex=Texture'SecondWind.Icons.SWDE50Name'
    }
    /* Replace NameTex and WeaponName with your own Weapon Name and Custom Weapon Name texture. To get this texture, extract NamesIcon.pcx from the INF core files. Edit it so that your weapon replaces the first entry (DE .357 Magnum). Save it and make it one of your loaded assets just like the WeaponIcon. */

    If you don't want to make a NameTex, just put None. You'll get the other variable displayed. It looks good, but not smooth like the texture.

    Code:
    
    // The following script goes into the body of your weapon script.
    
    simulated function RenderOverlays( canvas Canvas ) {
    	if ( bDroppedInventory || bHideWeapon || (Owner == None) || (Mesh == PickupViewMesh) )
    		return;
    	Super.RenderOverlays( Canvas );
     	if (Pawn(Owner).Weapon == self && WeaponName != "")
    		RenderWeaponName(Canvas);
    }
    
    simulated function RenderWeaponName( canvas Canvas ) {
      	local Weapon W, WeaponSlot[11];
    	local inventory inv;
      	local int i, k, BaseY, BaseX, WeaponOffset;
    
      	BaseX = 0.2*Canvas.ClipX + 46;
      	BaseY = Canvas.ClipY - 61 + 4;
      	WeaponOffset = 76;
    
    	WeaponSlot[InventoryGroup] = self;
    	i = 0;
    	for ( Inv=Pawn(Owner).Inventory; Inv!=None; Inv=Inv.Inventory )	{
    		if ( Inv.IsA('Weapon') && (Inv != Pawn(Owner).Weapon) )	{
    			W = Weapon(Inv);
    			if ( WeaponSlot[W.InventoryGroup] == None )
    				WeaponSlot[W.InventoryGroup] = W;
    			else if (
    				(WeaponSlot[W.InventoryGroup] != Pawn(Owner).Weapon)
    				&& ( ( W == Pawn(Owner).PendingWeapon)
    				|| (WeaponSlot[W.InventoryGroup].AutoSwitchPriority < W.AutoSwitchPriority)
    				&& INFc_Weapon(W)!=none && !INFc_Weapon(W).OutOfAmmo() )
    				)
    				WeaponSlot[W.InventoryGroup] = W;
    		}
    		i++;
    		if ( i > 100 ) break;
    	}
    
      	k=0;
      	for ( i=0; i < ArrayCount(WeaponSlot); i++ )
      	{
          	if( WeaponSlot[i] == self )
          	{
            	// WEAPON NAME
    		if ( NameTex != None )
    		{
    			Canvas.Style = ERenderStyle.STY_Translucent;
    			Canvas.SetPos( (BaseX - 46) + k*WeaponOffset, (BaseY - 4) );
    			Canvas.DrawColor.R = 255; Canvas.DrawColor.G = 255; Canvas.DrawColor.B = 255;
    			Canvas.DrawTile( NameTex,128,12,0,0,128,12 );
    		}
    		else
    		{
    			Canvas.Style = ERenderStyle.STY_Normal;
    	        	Canvas.SetPos( BaseX + k*WeaponOffset, BaseY );
    	          	Canvas.DrawColor.R = 255; Canvas.DrawColor.G = 255; Canvas.DrawColor.B = 255;
    			Canvas.Font = Font'WhiteFont';
    	          	Canvas.DrawText( WeaponName );
    		}
          	}
          	if( WeaponSlot[i] != None )
    			k++;
    	}
    }
    Check attached pic for a comparison! (Top: NameTex, Bot: WeaponName)
     

    Attached Files:

    Last edited: May 22, 2004
  5. MP_Duke

    MP_Duke Banned

    Joined:
    May 23, 2002
    Messages:
    711
    Likes Received:
    0
    Nice, i'll add this to the pack i'm working on right now, and i'll update the XM8 and M16A4 with this too.
     
  6. Beppo

    Beppo Infiltration Lead-Programmer

    Joined:
    Jul 29, 1999
    Messages:
    2,284
    Likes Received:
    1
    The following is the slightly changed base class of the upcomming bonus pack weapons. It features the WeaponNames as text and as texture version. In addition it has some lines of code that prevent the weapon names from being drawn while the HUD details are lowered, the HUD is turned off completely or while a player is dying aso. This was missing in the original codes already posted here.
    So, if you want to use this, then this way:
    Code:
    class MyBaseWeapon extends INFc_Weapon;
    
    #exec TEXTURE IMPORT NAME=MyWeaponNamesIcon FILE=Textures\MyWeaponNames.PCX   GROUP="" MIPS=OFF FLAGS=2
    
    var string WeaponName; // used for text version
    var Texture WeaponNameTex; //used for texture version
    var int WeaponNameY; //pixel offset on the Y-axis of the used texture
    
    // draw the weapon name on the HUD icon
    simulated function RenderOverlays( canvas Canvas ) {
    	if ( bDroppedInventory || bHideWeapon || (Owner == None) || (Mesh == PickupViewMesh) )
    		return;
    	Super.RenderOverlays( Canvas );
      	if (Owner != None && PlayerPawn(Owner) != None && Pawn(Owner).Weapon == self && (WeaponName != "" || WeaponNameTex != None) )
    		RenderWeaponName(Canvas);
    }
    
    simulated function RenderWeaponName( canvas Canvas ) {
      	local Weapon W, WeaponSlot[11];
    	local inventory inv;
      	local int i, k, BaseY, BaseX, WeaponOffset;
    
    	if 	(  Owner.IsInState('Dying')
    		|| Owner.IsInState('PlayerSpectating')
    	 	|| PlayerPawn(Owner).bShowScores
    		|| ChallengeHUD(PlayerPawn(Owner).myHUD).bShowInfo
    		|| ChallengeHUD(PlayerPawn(Owner).myHUD).bHideAllWeapons
    		|| ChallengeHUD(PlayerPawn(Owner).myHUD).bHideHUD )
    		return;
    
    	WeaponSlot[InventoryGroup] = self;
    	i = 0;
    	for ( Inv=Pawn(Owner).Inventory; Inv!=None; Inv=Inv.Inventory )	{
    		if ( Inv.IsA('Weapon') && (Inv != Pawn(Owner).Weapon) )	{
    			W = Weapon(Inv);
    			if ( WeaponSlot[W.InventoryGroup] == None )
    				WeaponSlot[W.InventoryGroup] = W;
    			else if (
    				(WeaponSlot[W.InventoryGroup] != Pawn(Owner).Weapon)
    				&& ( ( W == Pawn(Owner).PendingWeapon)
    				|| (WeaponSlot[W.InventoryGroup].AutoSwitchPriority < W.AutoSwitchPriority)
    				&& INFc_Weapon(W)!=none && !INFc_Weapon(W).OutOfAmmo() )
    				)
    				WeaponSlot[W.InventoryGroup] = W;
    		}
    		i++;
    		if ( i > 100 ) break;
    	}
    
      	k=0;
      	for ( i=0; i < ArrayCount(WeaponSlot); i++ )
      	{
          	    if( WeaponSlot[i] == self )
          	    {
            	    // WEAPON NAME
    			Canvas.Style = ERenderStyle.STY_Normal;
              	        Canvas.DrawColor.R = 255; Canvas.DrawColor.G = 255; Canvas.DrawColor.B = 255;
    			if ( WeaponNameTex != None ) {
      				BaseX = 0.2*Canvas.ClipX;
      				BaseY = Canvas.ClipY - 61;
      				WeaponOffset = 76;
            		        Canvas.SetPos( BaseX + k*WeaponOffset, BaseY );
    				Canvas.DrawTile( WeaponNameTex,128,12,0,WeaponNameY,128,12 );
    			}
    			else {
      				BaseX = 0.2*Canvas.ClipX + 46;
      				BaseY = Canvas.ClipY - 61 + 4;
      				WeaponOffset = 76;
            		        Canvas.SetPos( BaseX + k*WeaponOffset, BaseY );
    				Canvas.Font = Canvas.SmallFont;
              		        Canvas.DrawText( WeaponName );
    			}
          	    }
          	    if( WeaponSlot[i] != None )
    		k++;
    	}
    }
    
    // if a new weapon is added you can use this function to give it its own HUD icon
    simulated function CheckIcon(out Texture Icon) {
    //		Icon = Texture'MyPackage.MyWeaponIcon';
    }
    // if a new weapon is added you can use this function to give it its HUD weapon firing modes
    simulated function bool CheckWeaponMode(out int WeaponModesYOffset, out int WeaponModeActiveYOffset, out int WeaponModesMaxY) {
    //	// semi-auto - more examples can be found in function DrawWeaponMode, class InfChallengeHUD
    //	WeaponModesYOffset = 60;
    //	switch( FireMode )
    //	{
    //		case 0 : WeaponModeActiveYOffset = 13;
    //				 break;
    //		case 1 : WeaponModeActiveYOffset = 7;
    //				 break;
    //	}
    //	return True;
    
    // no weapon mode display
    	return False;
    }
    
    defaultproperties
    {
    	 WeaponName="MyNewWeapon"
    }
    
     
    Last edited: May 26, 2004
  7. UN17

    UN17 Taijutsu Specialist

    Joined:
    Dec 7, 2003
    Messages:
    675
    Likes Received:
    0
    Yay Beppo :) That looks like a pretty evolved bit of scripting. One minor "bug" I need help with. I'm using the render trick for my MK23 LAM mode and the text is still drawn when in the Scoreboard screen (F1). How do I detect if user is checking the Score?
     
  8. Beppo

    Beppo Infiltration Lead-Programmer

    Joined:
    Jul 29, 1999
    Messages:
    2,284
    Likes Received:
    1
    ha, have forgotten these checks ;)
    I've updated the above script accordingly.
     
  9. psi-Drake

    psi-Drake "keep your head down" Last words

    Joined:
    Jun 20, 2004
    Messages:
    3
    Likes Received:
    0
    on a similar note, i set up a lan with a friend to test out the M16a4 and the XM8 and only the computer that was the server could use and see the weapons, the other player couldn't see the weapon to use it. any ideas how to fix this one?
     
  10. AlmostAlive

    AlmostAlive Active Member

    Joined:
    Jun 12, 2001
    Messages:
    1,114
    Likes Received:
    0
    Allthough your question belongs in either Online or better yet, Troubleshooting, I believe the answer is simple. Your friend needs to download, install and enable the mutator with the weapons too. It's not enough for the server to have it or download it to your cache directly from the server. Give it a try and if it doesn't work, post in Troubleshooting ;)
     
  11. Beppo

    Beppo Infiltration Lead-Programmer

    Joined:
    Jul 29, 1999
    Messages:
    2,284
    Likes Received:
    1
    Infiltration.ini file:

    ServerPackages=PlaceThePackageNameHere

    All packages that have content that has to be visible on a client (like weapons that are held in 1st person aso) need to be a serverpackage.

    Check the readmes of the mutators you downloaded. I guess some explain exactly how to do this too.
     
    Last edited: Jun 21, 2004

Share This Page