• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code [Help] HUD and Scoreboard icons

forrestmark9

Grizzled Veteran
Nov 29, 2011
1,110
42
I need help with a particular system, due to the way I want to do this Chat Status will not work.

Anyway I want to setup a system via the HUD and Scoreboard that shows if the player is in the console or is chatting, etc draw a icon above there head and one next to there name in the scoreboard

Due to my limit knowledge of anything like this via HUD I only know that the overhead icons needs to be drawn via DrawPlayerInfo and with the scoreboard I don't know, I tried using DrawNamePostfixIcons but this doesn't work and only works in the chat and nowhere else.
 
Personally, i'll grab the code from the argentina which shows the icon above the head. Use the code to make your own boolean (guessing this is used) which will then add an icon to the HUD/scoreboard.

That code is super weird, all it's doing is checking constantly if the controller is typing then spawns an actor with a texture then attaches that actor to the head
 
Upvote 0
Then you have found your answer. Instead of spawning the actor, set the boolean to true (bIsTyping inside the scoreboard for example) and set inside the scoreboard if bIsTyping, show icon. Or do it in the HUD.

Other option is to make a bool inside the PlayerReplicationInfo and have the HUD check it.

I already explained I know to do it via the HUD but I don't know HOW to do it as I've never done anything that uses Canvas on this scale other then DrawSpriteWidget
 
Upvote 0
Try to look into NadeWarn mutator.

I looked into it and used it as a base to make this

Code:
class HudChatOverlay extends HUDOverlay;

const CHAT_RADIUS = 750;
var Material ConsoleTex, ChatTex;

simulated function Render(Canvas C)
{
    local Pawn P;
    local PlayerController PC;

    P = HUD(Owner).PawnOwner;
    PC = PlayerController(P.Controller);
    if (P != None && P.Health > 0 && PC != none) 
        DrawIcons(C, PC, P.Location);
}

simulated function DrawIcons(Canvas C, PlayerController PC, vector PlayerLoc) {
    local vector ScreenLoc, CameraLoc, PlayerDir;
    local rotator CameraRot;
    local float TexSize, TexAdjust;

    ScreenLoc = C.WorldToScreen(PlayerLoc);
    C.GetCameraLocation(CameraLoc, CameraRot);
    PlayerDir = PlayerLoc - CameraLoc;
    if (PlayerDir dot vector(CameraRot) > 0) {
        TexSize = 64 * (3 - (VSize(PlayerDir) / CHAT_RADIUS * 2.4)); // scaled by distance from x3 to x0.6
        TexAdjust = TexSize / 2;
        C.Style = ERenderStyle.STY_Alpha;
        C.SetPos(ScreenLoc.X-TexAdjust, ScreenLoc.Y-TexAdjust);
        C.SetDrawColor(255,255,255,255);
        if( PC.bIsTyping && !PC.Player.Console.bVisible )
            C.DrawTile(ChatTex, TexSize, TexSize, 0, 0, 64, 64);
        else if( !PC.bIsTyping && PC.Player.Console.bVisible )
            C.DrawTile(ConsoleTex, TexSize, TexSize, 0, 0, 64, 64);
    }
}

defaultproperties
{
     ConsoleTex=Texture'FMXBaseResources2.Console'
     ChatTex=Texture'FMXBaseResources2.Chat'
}

I have no idea if it'll work as expected
 
Upvote 0
bIsTyping/bVisible is not replicated to the other players... so you need a custom PlayerReplicationInfo...

I see, I already have a custom PRI

Code:
var bool bConsole, bTyping;

replication
{
    reliable if( bNetDirty && (Role == Role_Authority) )
        bConsole, bTyping;
}

function Tick(float DT)
{
	Super.Tick(DT);

	bConsole = PlayerController(Owner).Player.Console.bVisible;
	bTyping = PlayerController(Owner).bIsTyping;
}

The only problem with the HudOverlay is the position it's putting the chat icon at the center of the players location and not above his head.
 
Last edited:
Upvote 0
Code:
class HudChatOverlay extends HUDOverlay;

const CHAT_RADIUS = 750;
var Material ConsoleTex, ChatTex;

simulated function Render(Canvas C)
{
    local Pawn P;
    local PlayerController PC;

    P = HUD(Owner).PawnOwner;
    PC = PlayerController(P.Controller);
    if (P != None && P.Health > 0 && PC != none) 
        DrawIcons(C, PC, P.Location);
}

simulated function DrawIcons(Canvas C, PlayerController PC, vector PlayerLoc) {
    local vector ScreenLoc, CameraLoc, PlayerDir, [COLOR=Lime]OffestLoc;[/COLOR]
    local rotator CameraRot;
    local float TexSize, TexAdjust;

    [COLOR=Lime]OffestLoc = PlayerLoc + vect(0,0,32);[/COLOR] //32 because I'm pretty sure that should be about above them

    ScreenLoc = C.WorldToScreen([COLOR=Lime]OffestLoc[/COLOR]);
    C.GetCameraLocation(CameraLoc, CameraRot);
    PlayerDir = [COLOR=Lime]OffestLoc [/COLOR]- CameraLoc;
    if (PlayerDir dot vector(CameraRot) > 0) {
        TexSize = 64 * (3 - (VSize(PlayerDir) / CHAT_RADIUS * 2.4)); // scaled by distance from x3 to x0.6
        TexAdjust = TexSize / 2;
        C.Style = ERenderStyle.STY_Alpha;
        C.SetPos(ScreenLoc.X-TexAdjust, ScreenLoc.Y-TexAdjust);
        C.SetDrawColor(255,255,255,255);
        if( PC.bIsTyping && !PC.Player.Console.bVisible )
            C.DrawTile(ChatTex, TexSize, TexSize, 0, 0, 64, 64);
        else if( !PC.bIsTyping && PC.Player.Console.bVisible )
            C.DrawTile(ConsoleTex, TexSize, TexSize, 0, 0, 64, 64);
    }
}

defaultproperties
{
     ConsoleTex=Texture'FMXBaseResources2.Console'
     ChatTex=Texture'FMXBaseResources2.Chat'
}

The only problem with the HudOverlay is the position it's putting the chat icon at the center of the players location and not above his head.

Since WorldToScreen() is, probably, taking the player's location from the middle of their body, simply adding an offset to that vector in the Z component should be enough.
 
Upvote 0