Jump to content

Added a new GameState object to all soldiers?


kosmo111

Recommended Posts

I got directed here. Apologies for going off-topic.

IMO the best alternative to "Game Finished loading" is a UIScreenListener watching for the AvengerHUD ScreenClass. Fire off your code from the OnInit method of that screen listener (with a do-once condition if you only want it to happen once) there and it's as good as "Game finished loading" for most purposes.

 

If you mean that you want to fire stuff off during an already-started tactical mission, I'm sure there are other screen classes you could listen to for the same purpose. TacticalHUD is the UI for tactical missions as far as I recall. I personally tend towards advising mod users to only install mods on saves made in the strategic/avenger view though. Tactical has too much extra complexity with gamestate and stuff baked into the save to be a clean location to initalize a mod in my view.

If initialising for Tactical and Strategic are so cumbersome, is it possible to initialise on game load? Is there any way to have your mod do something when the game has finished loading? As in - does one of the UI listeners listen for the main menu? That would avoid issues of having to listen to particular UI elements, I think.

Link to comment
Share on other sites

  • Replies 40
  • Created
  • Last Reply

Top Posters In This Topic

Initialising for tactical and strategic aren't cumbersome at all - It's just that the gamestate is more complex in tactical so in my opinion it's a bad idea to first-time-load a mod into a savegame made during a tactical mission. The gamestate (in the general sense) is cleaner in strategic.

A UIScreenListener with its ScreenClass set to 'none' will fire for every screen instead of a specific screen - and a doOnce variable will keep it from firing repeatedly. The first time a 'UIScreen' is shown is the main menu, so that's when this will first fire.

However, if you want to modify weapon templates you need to do so for every difficulty and I'm not sure that it's possible to access the necessary objects and set difficulties temporarily etc. while at the main menu, so I still favour doing that kind of thing on the first initialization of AvengerHUD.

class SomeMod_UIScreenListener extends UIScreenListener;
var class<UIScreen> ScreenClass;
var boolean doOnce;

// This event is triggered after a screen is initialized
event OnInit(UIScreen Screen)
{
    if(!doOnce)
	{
		CallSomeModFunctionHere();
		doOnce = true;
	}
}

defaultproperties
{
	// Leaving this assigned to none will cause every screen to trigger its signals on this class
	ScreenClass = none;
}
Edited by Kvalyr
Link to comment
Share on other sites

Initialising for tactical and strategic aren't cumbersome at all - It's just that the gamestate is more complex in tactical so in my opinion it's a bad idea to first-time-load a mod into a savegame made during a tactical mission. The gamestate (in the general sense) is cleaner in strategic. A UIScreenListener with its ScreenClass set to 'none' will fire for every screen instead of a specific screen - and a doOnce variable will keep it from firing repeatedly. The first time a 'UIScreen' is shown is the main menu, so that's when this will first fire.

Thank you kindly, that helps tremendously. Out of curiosity, though - is there any kind of ScreenClass which will only correspond to the main menu? I'll follow your instructional code, I'm just interested to know what what the main menu is called for my own personal information.

 

*edit*

Found a couple of potentially interesting UI classes. UILoadGame seems to be the UI for loading a game, so that might be a good place to put an event which has to happen on every game load. UIShell seems to be the main menu UI, though I'm not positive. Again, I'm not arguing, just looking through the code.

 

And now that I think about this, what you're suggesting sounds a lot like stat tweaks in Payday 2 through "persist scripts" which get run on every frame of animation. Now I'm starting to see what you mean.

 

However, if you want to modify weapon templates you need to do so for every difficulty and I'm not sure that it's possible to access the necessary objects and set difficulties temporarily etc. while at the main menu, so I still favour doing that kind of thing on the first initialization of AvengerHUD.

 

Really? That's odd. How do weapon stats vary by difficulty? From what I saw in the Default Weapons script, there's only one instance per weapon template in the game.

Edited by SteelRook
Link to comment
Share on other sites

 

 

Really? That's odd. How do weapon stats vary by difficulty? From what I saw in the Default Weapons script, there's only one instance per weapon template in the game.

 

 

There's a property on X2DataTemplate (which applies to all classes that extend it): "bShouldCreateDifficultyVariants"

 

Grenades, Weapons, HeavyWeapons, Schematics, Soldiers, Techs.. Lots of the game's templates have that flag set to true in their defaultproperties; which means variants get created that scale their costs etc according to the difficulty level.

 

When you grab templates from a manager, you're grabbing the templates for the currently selected difficulty. If you only change the values for one difficulty, things might get funky when the player changes difficulty mid-game. If you want to modify templates for all difficulties, you need to cycle through the difficulties temporarily and apply your changes to the templates at all difficulties. Amineri posted an example of how to do this somewhere in one of the large threads. I did too, in one of the other threads.

Link to comment
Share on other sites

Does it work by explicitly changing the difficulty of the game and then fetching the template? Cause that could interfere with achievements if it calls code that sets the "lowest difficulty used" flag. It'd be nice to get an official way to get and set the templates for particular difficulties regardless of what the current level is.
Link to comment
Share on other sites

When you grab templates from a manager, you're grabbing the templates for the currently selected difficulty. If you only change the values for one difficulty, things might get funky when the player changes difficulty mid-game. If you want to modify templates for all difficulties, you need to cycle through the difficulties temporarily and apply your changes to the templates at all difficulties. Amineri posted an example of how to do this somewhere in one of the large threads. I did too, in one of the other threads.

How does that work if no difficulty is selected, though? Such as when that code gets passed at game launch? Does it just default to a particular difficulty? I don't think there's a specific difficulty chosen for the main game.

 

So is there any way to pull all difficulty versions of an item or ability from the corresponding Item Manager?

Link to comment
Share on other sites

Does it work by explicitly changing the difficulty of the game and then fetching the template? Cause that could interfere with achievements if it calls code that sets the "lowest difficulty used" flag. It'd be nice to get an official way to get and set the templates for particular difficulties regardless of what the current level is.

 

Yeah that's how it works. UnrealScript code in mods has full access to achievements and nothing is protected from scripts - You could in theory write a mod that instantly gives you all of the achievements as far as I can see. That's presumably why Firaxis made it so that mods don't disable achievements, because then they'd need to set up some kind of code-tainting system similar to what games like WoW have; and that would be an immense effort for them (and a pain in the ass for modders).

 

You just store the current difficulty and the lowest-difficulty-used; modify the dificulty temporarily, then set the difficulty and lowest-difficulty back to the values they were at before you modified templates. That way, achievements are unaffected.

 

Technically a mod could be used to 'cheat' that stuff and set 'lowest difficulty used' to 'Legend' for a game that was played entirely on rookie difficulty. XCOM2 achievements are not secure. :P

 

 

How does that work if no difficulty is selected, though? Such as when that code gets passed at game launch? Does it just default to a particular difficulty? I don't think there's a specific difficulty chosen for the main game.

 

So is there any way to pull all difficulty versions of an item or ability from the corresponding Item Manager?

 

 

That was exactly my point above and why I don't think the main menu is the place to make these changes - As far as I know it doesn't work to try and set/get difficulties at the main menu. I forget which function call failed, but I was getting redscreens when trying to access the relevant gamestate objects to cycle through difficulties at the main menu. So my conclusion is: Don't bother. Do it on first load of AvengerHUD instead.

Link to comment
Share on other sites

That was exactly my point above and why I don't think the main menu is the place to make these changes - As far as I know it doesn't work to try and set/get difficulties at the main menu. I forget which function call failed, but I was getting redscreens when trying to access the relevant gamestate objects to cycle through difficulties at the main menu. So my conclusion is: Don't bother. Do it on first load of AvengerHUD instead.

 

I'm not sure I follow, then. Surely the difficulty-specific "stuff" would be written down somewhere and able to be written explicitly without needing to set the current difficulty to it. Sooner or later some method somewhere has to look up the appropriate data by absolute address, rather than by relative address based on the "current" difficulty. I'm at work at the moment so I can't even hazard a guess, but I'll go back to your advise on changing difficulty and try to track down the "chain of command" of those classes when I get home.

 

Then again, very little in XCOM 2 works the way I'd intuit it should work, so it's possible I may be entirely off-base here. After all, I couldn't find a decent event to listen to for loading a saved game...

 

*edit*

Are difficulty-dependent stats buried into the X2WeaponTemplate itself? I don't recall seeing them in the X2Item_DefaultWeapon class. That deals with only one set of stats per weapon. Isn't difficulty separate from that, to be tweaked separately? I mean from the sounds of what you're saying obviously not, but I don't see how when the creation functions don't deal with difficulty.

Edited by SteelRook
Link to comment
Share on other sites

It would actually be useful in some circumstances to be able to rely on a method being executed every time a mod is loaded. I haven't been able to reproduce this behaviour on my side though - When I load saves that were made after already loading one of my mods, it doesn't fire that method again.

 

I've requested this exact thing from Firaxis -- to add a "Always fires on game load when mod active" in addition to the "Fires only first time loading with Mod/DLC"

Link to comment
Share on other sites

The current difficulty is stored in the XComGameState_CampaignSettings, which is only present when actually in a campaign -- not from the main menu/shell. When templates are retrieved in the shell, it defaults to difficulty 1 -- Veteran.

 

Regarding using screen listeners -- it's possible to set one up listening to "none" (and hence all) UIScreens. Then test whether the game is in either strategy or tactical in order to exclude the shell, and you should be able to modify difficulty variant templates.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...