MH2 Display remaining charge on the left for Flashlight , amplifer and invulnérability

Discussions about Coding and Scripting
Letylove49
Adept
Posts: 282
Joined: Tue Feb 28, 2012 7:47 pm
Location: suisse

MH2 Display remaining charge on the left for Flashlight , amplifer and invulnérability

Post by Letylove49 »

hi i need help because that don't work like expected : ( that work for scuba and jumboot but no for flashlight)
i would like to display remaining charges for Flashlight, Amplifer, and invulnérability. i wish this also works when i use the command "Mutate light")

this function come from MH2Hud class
simulated function DrawGameSynopsis(Canvas Canvas)
{
local float XL, YL, XOffset, YOffset, YOffsetSafe;
local inventory Inv;
local int BootCharges;
local int FlashCharges;
local string Spread;
local int i;



for ( Inv=PawnOwner.Inventory; Inv!=None; Inv=Inv.Inventory )
{
if ( Inv.IsA('MH2Scuba'))
{
Canvas.DrawColor = HUDColor;
if ((Inv.Charge/10) < 25) Canvas.DrawColor = RedColor;
Canvas.SetPos(0, YOffset);
Canvas.DrawText(" Scuba: "@(Inv.Charge/10), False);
YOffSet -= YL;
}
else if ( Inv.IsA('JumpBoots') || Inv.IsA('UT_Jumpboots') )
{
BootCharges=Inv.Charge;
Canvas.DrawColor = HUDColor;
Canvas.SetPos(0, YOffset);
Canvas.DrawText(" Jumps left: "@Inv.Charge, False);
YOffSet -= YL;
}
else if ( Inv.IsA('FlashLight'))
{
FlashCharges=Inv.Charge;
Canvas.DrawColor = HUDColor;
if ((Inv.Charge/10) < 100) Canvas.DrawColor = GoldColor;
else
if ((Inv.Charge/10) < 10) Canvas.DrawColor = RedColor;
Canvas.SetPos(0, YOffset);
Canvas.DrawText("Flashlight:"@(Inv.Charge/10), False);
YOffSet -= YL;
}
else
{
i++;
if ( i > 100 )
break; // can occasionally get temporary loops in netplay
}
}
Image





Letylove49 aka Alicia
User avatar
EvilGrins
Godlike
Posts: 10214
Joined: Thu Jun 30, 2011 8:12 pm
Personal rank: God of Fudge
Location: Palo Alto, CA

Re: MH2 Display remaining charge on the left for Flashlight , amplifer and invulnérability

Post by EvilGrins »

Don't use the flashlight, use the spotlight.

Spotlight never runs out of batteries.
User avatar
Barbie
Godlike
Posts: 2929
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: MH2 Display remaining charge on the left for Flashlight , amplifer and invulnérability

Post by Barbie »

Maybe describe WHAT you can see in HUD when you have an active FlashLight in Inventory. Do you see at least the text " Flashlight: "? If not, add some debug statements after else if ( Inv.IsA('FlashLight')) to see what's going on.
Example:

Code: Select all

       else if ( Inv.IsA('FlashLight'))
        {
        log(self @ "detected" @ Inv);
        FlashCharges=Inv.Charge;
        log(Inv $ ".Charge=" $ Inv.Charge);
        // and so on...
        
	}
Beware that it is called in Tick() so log will be flooded.
"If Origin not in center it be not in center." --Buggie
Letylove49
Adept
Posts: 282
Joined: Tue Feb 28, 2012 7:47 pm
Location: suisse

Re: MH2 Display remaining charge on the left for Flashlight , amplifer and invulnérability

Post by Letylove49 »

i have try this but i have nothing on the log :

Code: Select all

if ( Inv.IsA('FlashLight'))
        {   log(self @ "detected" @ Inv);
            FlashCharges=Inv.Charge;
            log(Inv $ ".Charge=" $ Inv.Charge);
            Canvas.DrawColor = HUDColor;
            if ((Inv.Charge/10) < 100) Canvas.DrawColor = GoldColor;
            else
            if ((Inv.Charge/10) < 10) Canvas.DrawColor = RedColor;
            Canvas.SetPos(0, YOffset);
            Canvas.DrawText(" Flashlight: "@(Inv.Charge/10), False);
            YOffSet -= YL;
        } 
Image





Letylove49 aka Alicia
Letylove49
Adept
Posts: 282
Joined: Tue Feb 28, 2012 7:47 pm
Location: suisse

Re: MH2 Display remaining charge on the left for Flashlight , amplifer and invulnérability

Post by Letylove49 »

now i have this :
else if ( Inv.IsA('FlashLight'))
{
FlashCharges=Inv.Charge;
if ((Inv.Charge/10) > 100)Canvas.DrawColor = HUDColor;
if ((Inv.Charge/10) < 100) Canvas.DrawColor = GoldColor;
if ((Inv.Charge/10) < 10) Canvas.DrawColor = RedColor;
Canvas.SetPos(0, YOffset);
Canvas.DrawText(" Flashlight: "@(Inv.Charge/10), False);
YOffSet -= YL;
}


else if ( Inv.IsA('LimeLight'))
{
LimeCharges=Inv.Charge;
if ((Inv.Charge/10) > 100) Canvas.DrawColor = HUDColor;
if ((Inv.Charge/10) < 100) Canvas.DrawColor = GoldColor;
if ((Inv.Charge/10) < 10) Canvas.DrawColor = RedColor;
Canvas.SetPos(0, YOffset);
Canvas.DrawText(" Limelight: "@(Inv.Charge/10), False);
YOffSet -= YL;
}

else if ( Inv.IsA('UDamage')|| Inv.IsA('MH2UDamage') )
{
UdamageCharges=Inv.Charge;
if ((Inv.Charge/10) > 20)Canvas.DrawColor = HUDColor;
if ((Inv.Charge/10) < 20) Canvas.DrawColor = GoldColor;
if ((Inv.Charge/10) < 10) Canvas.DrawColor = RedColor;
Canvas.SetPos(0, YOffset);
Canvas.DrawText(" Amplifer: "@(Inv.Charge/10), False);
YOffSet -= YL;
}

else if ( Inv.IsA('SBInvulnerability'))
{
SBInvulnerabilityCharges=Inv.Charge;
if ((Inv.Charge/10) > 30)Canvas.DrawColor = HUDColor;
if ((Inv.Charge/10) < 30) Canvas.DrawColor = GoldColor;
if ((Inv.Charge/10) < 10) Canvas.DrawColor = RedColor;
Canvas.SetPos(0, YOffset);
Canvas.DrawText(" Invulnerability: "@(Inv.Charge/10), False);
YOffSet -= YL;
for invulnérability that work like expected now : display and count down
for Amplifer is only display but i haven't count down. ( how i can fix that ?)

for Flashlight and LimeLight that doesn't work. ( this item is activate with a mutate command)
Shot00621.png
You do not have the required permissions to view the files attached to this post.
Image





Letylove49 aka Alicia
User avatar
Barbie
Godlike
Posts: 2929
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: MH2 Display remaining charge on the left for Flashlight , amplifer and invulnérability

Post by Barbie »

Looks like UDamage uses a separate counter FinalCount.
Untested example:

Code: Select all

else if ( Inv.IsA('UDamage')|| Inv.IsA('MH2UDamage') )
	{
	InvCharge = UDamage(Inv).FinalCount / 10; // have expensive division only once
	if ((InvCharge) > 20) Canvas.DrawColor = HUDColor;
	else if ((InvCharge) < 10) Canvas.DrawColor = RedColor; // use ELSE to lower amount of statements
	else Canvas.DrawColor = GoldColor; // last IF not needed
	Canvas.SetPos(0, YOffset);
	...
"If Origin not in center it be not in center." --Buggie