MH problem: Using ini values instead of default properties

Discussions about Coding and Scripting
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

MH problem: Using ini values instead of default properties

Post by Aldebaran »

I want that I can configure (setting on/off) the visibility of the monsters hud (here the health points of each monster) with a variable stored in the ini file.
I have done these codings but the MonsterHunt2_CUSTOM Mod still uses the value stored in defaultproperties and not the value from the ini file, so the monster health points are not drawn although I activated them in the ini file.
So changing the ini value DrawMonsterHP does not change anything.
What I am doing wrong?

File MonsterHunt2_CUSTOM.ini:

Code: Select all

[MonsterHunt2_CUSTOM.MH2Base]
...

[MonsterHunt2_CUSTOM.MH2HUD]
DrawMonsterHP=True

[MonsterHunt2_CUSTOM.ShutUp]
...
File MH2HUD.uc:

Code: Select all

class MH2HUD expands ChallengeTeamHUD config(MonsterHunt2_CUSTOM);
...

var config bool DrawMonsterHP;
...

simulated function PostRender( Canvas Canvas )
{
...
	
    if ( DrawMonsterHP && PawnOwner == PlayerOwner )
       		 DrawMonsterName(Canvas);
...

}
...

defaultproperties
{
...

    DrawMonsterHP=False
}
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: MH problem: Using ini values instead of default properti

Post by Barbie »

I'm not sure which MonsterHunt2_CUSTOM.ini is read: that one on client or on server? (For such cases in doubt I temporary add a SaveConfig() to the code and look where and what is saved.)
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: MH problem: Using ini values instead of default properti

Post by Aldebaran »

Barbie wrote:I temporary add a SaveConfig() to the code and look where and what is saved.
I made it now and it saves an ini clientside with the [MonsterHunt2_CUSTOM.MH2HUD] section, the others like [MonsterHunt2_CUSTOM.MH2Base] are missing.
But what can I do to store the variable serverside?

EDIT: I want the MH2HUD class to read the ini value from server ini file instead from client ini file. Saving is not my intention.
Last edited by Aldebaran on Tue Mar 14, 2017 5:06 pm, edited 1 time in total.
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: MH problem: Using ini values instead of default properti

Post by Barbie »

My first try would be adding "DrawMonsterHP" to the replication block. But I'm not sure which value is taken if server and client have different INI values for it.
<EDIT>
wiki.beyondunreal.com: Everything you ever wanted to know about replication (but were afraid to ask)
</EDIT>
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: MH problem: Using ini values instead of default properti

Post by JackGriffin »

Add a config value to the base called "ShowMonsterHealth". In your HUD class just add a call to the overlay to check whether or not "if(ShowMonsterHealth)". As long as the HUD class and the mutator live in the same u file they will talk to each other without needing to set up replication.

Mutator boolean values are polled from the server at map start and those values are sent out to the client. As long as you don't update them during the match you'll be fine. If you need to update them then you'll need to set up replication blocks so it periodically checks.
So long, and thanks for all the fish
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: MH problem: Using ini values instead of default properti

Post by Aldebaran »

JackGriffin wrote:Add a config value to the base called "ShowMonsterHealth". In your HUD class just add a call
Thanx. I tested this already and the problem is that the class MH2HUD.uc don't know the variable DrawMonsterHP/ShowMonsterHealth declared in MH2Base.uc and stops the compiling with an error message.

EDIT: It seems that public variables exist as of Unreal Engine 2 :(
Last edited by Aldebaran on Tue Mar 14, 2017 7:40 pm, edited 3 times in total.
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: MH problem: Using ini values instead of default properti

Post by sektor2111 »

I have added in HUD Server's TickRate for figuring how loaded is map running in certain time. This was doable by adding a new parameter to whatever MonsterReplicationInfo2, and then you can use a bool there dependent on MonsterReplicationInfo(...).bDrawMonsterHealth - do draw that. It's all about replication when is about HUD else all HUD data usually is stored in client because it's client side. A customized HUD might have more related things dependent on whatever actor using replication, in this case I used the child of GameReplicationInfo because that one works for sure, was needed only a small add-on as a condition or whatever data to be sent in client.
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: MH problem: Using ini values instead of default properti

Post by Aldebaran »

I have another idea.

I copied file MH2HUD.uc to MH2HUD2.uc.
MH2HUD.uc is a class without that monsters HUD.
MH2HUD2.uc is a class with that monsters HUD.
And changed file MH2Base.uc in that way:

Code: Select all

var config bool ShowMonsterHealth;
...
if(Level.Game.HUDType !=none)
   {
      if(ShowMonsterHealth)		
          Level.Game.HUDType = class'MH2HUD2';
      else
          Level.Game.HUDType = class'MH2HUD';
   }
I have not tested it now but I saw similar code in other parts of the mh mod.
Chris
Experienced
Posts: 134
Joined: Mon Nov 24, 2014 9:27 am

Re: MH problem: Using ini values instead of default properti

Post by Chris »

Aldebaran wrote:I have another idea.

I copied file MH2HUD.uc to MH2HUD2.uc.
MH2HUD.uc is a class without that monsters HUD.
MH2HUD2.uc is a class with that monsters HUD.
And changed file MH2Base.uc in that way:

Code: Select all

var config bool ShowMonsterHealth;
...
if(Level.Game.HUDType !=none)
   {
      if(ShowMonsterHealth)		
          Level.Game.HUDType = class'MH2HUD2';
      else
          Level.Game.HUDType = class'MH2HUD';
   }
I have not tested it now but I saw similar code in other parts of the mh mod.
That's very redundant and ugly. If you want server to have authority over the client HUD settings then use the subclassed version of GameReplicationInfo in your mod and just add the bool there. Have the server set that variable during startup and then client can read the replicated data anytime, just like Sektor said...
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: MH problem: Using ini values instead of default properti

Post by sektor2111 »

To be honest I had in MH2 3 HUDS configurable VIA MOD ini not client's INI: Old HUD, Simple MH HUD, RADAR HUD. It works properly, of course wrapped to not have HUD4 HUD7 or others which doesn't exist. Changing HUD was used by UTJ series all time - problem was original MonsterHUD which would be better to be rewritten rather than spread into a subclass. Right now testing MH with that UTJ made me mad for a few moments, I got a memory refresh about those things which were not the best ever MH stuff...
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: MH problem: Using ini values instead of default properti

Post by Aldebaran »

Sure it is not a bad idea with that MonsterReplicationInfo(...).bDrawMonsterHealth but only my Unrealscript knowledge is not so good for realizing it that way.

In MH2HUD.uc I think I should do this:

Code: Select all

var config bool ShowMonsterHealth;
...

simulated function PostRender( Canvas Canvas )
{
    super.HUDSetup(canvas);

    if ( MonsterReplicationInfo(PlayerPawn(Owner).GameReplicationInfo).ShowMonsterHealth && PawnOwner == PlayerOwner )
        DrawMonsterName(Canvas);
    ...
}
But what are the code lines for setting this variable correctly?

I would set it in MH2Base.uc:

Code: Select all

function PostBeginPlay()
{
    ...
    if(Level.Game.HUDType !=none)
    {
          << missing lines >>
          Level.Game.HUDType = class'MH2HUD';
    }
    ....
}
Or should I use the replication block for that?
And is that all then or is there more code missing?
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: MH problem: Using ini values instead of default properti

Post by sektor2111 »

Points to take:
- New value should go in MH's replication - it's a bool preferable bDrawMonsterHealth for prevent any confusion with "int" and "float" - please RESPECT old coding convention;
- MH has a deal which can be taken as sample bUseLives - is automated set by Mod if Lives > 0;
- controller will have bUsingHealthDrawing as a config in MH.ini not HUd ini not other place;
- PostBeginPlay will use in controller GameReplicationInfo...bDrawMonsterHealth = bUsingHealthDrawing;

Pretty much simple as long as WE have a sample about bUseTeamColor but... that one has bugs in old HUD - it goes too fast and player doesn't have things ready as I could figure It needs "if (Gri != None) bUseTeamColor = Gri.bUseTeamSkins" or such it would be better to have a bit of delay, you can do the same things with other bool values probably initialized first second from timer in HUD - to draw or not MonsterHealth - condition coming from GRI which is set by controller. Controller is running in server because... Level.Game is located in server and all that game config is in Server. Now you can decide if you want to have health on HUD or not.

Hint: To not mess up like Shrimp, use logs

Code: Select all

log("GameReplication has bDrawMonsterHealth > "@Gri.bDrawMonsterHealth);
defining MonsterReplicationInfoX(GamReplicationinfo) as being GRI for shorter writing and the rest. In this way youl'll see if code gets called properly and not by guessing. If do works, remove logs and recompile it clean.


The second deal is a simple HUD modification in BaseMutator or even controller (is delayed a bit here) BaseMutator with PostBeginPlay is executed first... Here you can address bUseDrawHealth loading HUD accordingly and having 2 different HUD types, 1 with health 2 without health - no bool needed in replication and neither in HUD just... 2 completely different things, let's say the second HUD will have function with drawing removed out.
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: MH problem: Using ini values instead of default properti

Post by Aldebaran »

Thank you for your help.
sektor2111 wrote:- PostBeginPlay will use in controller GameReplicationInfo...bDrawMonsterHealth = bUsingHealthDrawing;
There is something missing. The compiler does not know the variable GameReplicationInfo.bDrawMonsterHealth at this position.
What do you mean with "..." in your code?
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: MH problem: Using ini values instead of default properti

Post by sektor2111 »

Aldebaran wrote:There is something missing
OF COURSE it's missing if you did not add it, code is not self writing. Define damn variable what is that hard to figure ?

By meaning ... i mean to not spam forum with useless codes >>

MonsterReplicationInfo2(GameReplicationInfo).bMyNewBoolWhichICannotWriteAndItsMissingBecauseNobodyWasWritingItBefore = bUseANewOptionWhichNeverExistedBeforeAndWhichItNeedsToBeDefinedToNotMockCompiler;

MonsterReplicationInfo2

Code: Select all

var bool bUseLives;
var bool bUseTeamSkins;
var int Lives;
var int Monsters;
var int Hunters;
var bool bMyNewBoolWhichICannotWriteAndItsMissingBecauseNobodyWasWritingItBefore; //We Might need a new variable DECLARED

replication
{
	reliable if ( Role == ROLE_Authority )
		Lives, Monsters, bUseLives, bUseTeamSkins, Hunters,
		bMyNewBoolWhichICannotWriteAndItsMissingBecauseNobodyWasWritingItBefore;
}
What exactly do we want to compile which is not even defined ? Compiler will not add any variable for you...

You'll understand that a game modification is not only a matter of compiling codes, they have to be completed first, else they will never compile.
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: MH problem: Using ini values instead of default properti

Post by Aldebaran »

Sorry, but I have done this already. The class file here is named Monster2ReplicationInfo. I configured it as you posted it now.
But in MH2Base.uc the compiler don't know the variable Monster2ReplicationInfo(GameReplicationInfo).bDrawMonsterHealth - that's the problem. I tried many other variable combinations there too but without success.
But however, I decided now to take the other version with choosing one of two different HUD's. That works for me...
Thank you for your help so far.
Post Reply