Dynamic 2D Leaderscenes

Vicevirtuoso

The Modetta Man
Joined
May 14, 2013
Messages
775
Location
The Wreckage, Brother
Special thanks to bc1 of EUI fame for helping fix two glaring usability issues with this utility!

This is a utility I wrote for two of my mods which allows for a leader scene to be changed dynamically depending on the disposition of the AI. With this, you can:

  • Display a different image for a leader when they are Friendly, Afraid, Guarded, Hostile, At War, Denouncing the player, or Defeated
  • Have the leader scenes for a leader update without requiring a reload if you use Lua to change the leader of a Civilization mid-game. For example, if you had an America civilization which changed leaders from Washington to Lincoln after certain requirements were met, you could make Lincoln appear instead of Washington without requiring a reload.
  • NEW in v2: Define custom functions which allow you to fetch any texture you want to display as the leaderscene

This mod replaces LeaderHeadRoot.xml, but not LeaderHeadRoot.lua. As of v4, this mod does not require any file replacement!

How to use

  1. Add VV_LeaderSceneChanger.sql as an OnModActivated action in the Actions tab in the properties of your mod. This file must be loaded before the one defining your leader in the Leaders table!
  2. When defining your Leader, set any or all of the following fields in the Leader table to be the exact name of the .dds texture file you want to use, including the file extension:
    • VV_LeaderSceneOverride
    • VV_LeaderSceneOverrideFriendly
    • VV_LeaderSceneOverrideGuarded NEW in v2
    • VV_LeaderSceneOverrideAfraid NEW in v2
    • VV_LeaderSceneOverrideHostile
    • VV_LeaderSceneOverrideWar NEW in v3
    • VV_LeaderSceneOverrideDenouncing NEW in v3
    • VV_LeaderSceneOverrideDefeat NEW in v3
  3. Add VV_LeaderHeadImageOverride.xml as a DiplomacyUIAddin under the Content tab of your mod
  4. You may either use HookupExample.lua as an InGameUIAddin directly, or you can simply copy and paste the code into your own Lua script. No longer necessary as of v4!
  5. NEW in v2 (Optional): If you have more Lua experience, you may define custom functions to determine which texture is displayed for the leader image. Once a function is defined, add it to the utility's table of functions using LuaEvents.AddFunctionToLeaderSceneTable(function name) (note: you should probably add this line within a function called from Events.LoadScreenClose, in case your script loads after Dynamic 2D Leaderscenes does). These will run prior to the default functions which display the leaderscene based on the AI's disposition towards you. Functions will run in the order they are added to the table. If a value is returned, the dispositions will not be checked. The function will be passed all the arguments that Events.AILeaderMessage would pass to a function. Example:
    Spoiler :
    Code:
    --Special Leaderscene logic just for Uni:
    --If she is Friendly towards the player, but is only at 66% or less of the player's score, she gets a little flustered.
    function UniSpecialLeaderscene( iPlayer, iDiploUIState, szLeaderMessage, iAnimationAction, iData1 )
    	local pPlayer = Players[iPlayer]
    	if pPlayer:GetCivilizationType() == iUniCiv then
    		local pActivePlayer = Players[Game:GetActivePlayer()]
    		local iApproach = pActivePlayer:GetApproachTowardsUsGuess(iPlayer);
    		local bWar = Teams[pActivePlayer:GetTeam()]:IsAtWar(pPlayer:GetTeam())
    
    		if not bWar and iApproach == MajorCivApproachTypes.MAJOR_CIV_APPROACH_FRIENDLY then
    			local iPercent = GetUniScoreDifference(iPlayer, pActivePlayer:GetScore())
    			if iPercent <= UNI_FLUSTERED_THRESHOLD then
    				return "VVUniLeaderSceneDynamicFriendlyLowScore.dds"
    			end
    		end
    	end
    
    	return nil
    end
    
    Events.LoadScreenClose.Add(function () LuaEvents.AddFunctionToLeaderSceneTable(UniSpecialLeaderscene end)

Leaders without definitions for the VV_LeaderSceneOverride fields (or custom functions) will display normally.

Example of the mod in use, using my Hyperdimension Neptunia: Lowee mod:

Normal:
Spoiler :


Friendly:
Spoiler :


Hostile (text censored due to vulgarity):
Spoiler :
 

Attachments

  • Dynamic2DLeaderscenes-v5.zip
    2.6 KB · Views: 394
Ah, good to see this here. :)

Just one thing, though... if we're using this for a leader change, and are not worried about changing moods, would the process be the same except we do not define those extra fields?
 
Just one thing, though... if we're using this for a leader change, and are not worried about changing moods, would the process be the same except we do not define those extra fields?

It will default to VV_LeaderSceneOverride for any mood if VV_LeaderSceneOverrideFriendly or VV_LeaderScenOverrideHostile are undefined.



Gentleman, you had my curiosity; now you have my attention. Care to send a PM with the uncensored version? :groucho:

Sure.
 
Wonder if this could be used to make certain Easter Egg in the Flanders civ even more amusing... :D
 
I love this! I will make sure to utilize this in my WIP to show variations of Athena Prime with attitude and time. I really wanted to have leader scenes that reflect the changing nature of an immortal robot adjusting for changes in perceptions and expectations with technological progress and diplomatic relationships (including war).

Sadly, I don't have the time or skills to complete my mod to the point where it would be ready to use your wonderful component any time soon. My preliminary Alpha release might come in a month. My unique ability requires some LUA code that I neither know how to write from scratch nor find to modify, yet.

Keep up the great work!
 
I love this! I will make sure to utilize this in my WIP to show variations of Athena Prime with attitude and time. I really wanted to have leader scenes that reflect the changing nature of an immortal robot adjusting for changes in perceptions and expectations with technological progress and diplomatic relationships (including war).


Good to hear. Let me know if you need any help with using this utility.
 
v3 uploaded:

  • Adds VV_LeaderSceneOverrideWar, VV_LeaderSceneOverrideDenouncing, VV_LeaderSceneOverrideDefeat
  • Added comments to LeaderHeadRoot.xml to make it easier for users to merge this with other copies of the same file (e.g. EUI)
  • Leaderscreens will no longer appear in network multiplayer games
 
Are you able to code it so that AI players in multiplayer games can propose deals to human players?

Far outside the scope of this mod. There is a DLL mod out there which allows this functionality IIRC.
 
Far outside the scope of this mod. There is a DLL mod out there which allows this functionality IIRC.

Yeah, unfortunately the source code for that DLL mod hasn't been released so it can't be combined with any other DLL mods...

Oh well, was worth an ask.
 
Version 4 of the utility uploaded, with special thanks to bc1 for his help coding it such that it no longer requires LeaderHeadRoot.xml to be replaced, and for also showing me how an image can be scaled with linear sampling!
 
Version 5 uploaded:

  • Compatible with DLL - Various Mod Components v67's "Diplomacy - No Leaderheads" mini-mod. When it is active, none of the dynamic 2D leaderscenes will display.
  • Fixed "Unable to load texture "null" " error when used in multiplayer modpacks.
  • Marginal performance increase.
  • Fix for flashing red screen when switching between leaderhead contexts (such as moving from the leaderhead root to the trade window).

Edit: mistakenly uploaded without necessary SQL file, fixed
 
2. When defining your Leader, set any or all of the following fields in the Leader table to be the exact name of the .dds texture file you want to use, including the file extension:

Please forgive my noobishness, but I'm not sure I understand how I would go about doing that.

I assume you're meaning this table?
Spoiler :
Code:
	<Leaders>
		<Row>
			<Type>LEADER_BALALAIKA</Type>
			<Description>TXT_KEY_LEADER_BALALAIKA</Description>
			<Civilopedia>TXT_KEY_LEADER_BALALAIKA_PEDIA</Civilopedia>
			<CivilopediaTag>TXT_KEY_CIVILOPEDIA_LEADERS_BALALAIKA</CivilopediaTag>
			<ArtDefineTag>Balalaika_Scene.xml</ArtDefineTag>
			<VictoryCompetitiveness>9</VictoryCompetitiveness>
			<WonderCompetitiveness>2</WonderCompetitiveness>
			<MinorCivCompetitiveness>2</MinorCivCompetitiveness>
			<Boldness>10</Boldness>
			<DiploBalance>4</DiploBalance>
			<WarmongerHate>1</WarmongerHate>
			<WorkAgainstWillingness>8</WorkAgainstWillingness>
			<WorkWithWillingness>8</WorkWithWillingness>
			<Chattiness>6</Chattiness>
			<Loyalty>5</Loyalty>
			<Neediness>5</Neediness>
			<Meanness>6</Meanness>
			<Forgiveness>1</Forgiveness>
			<DenounceWillingness>5</DenounceWillingness>
			<DoFWillingness>5</DoFWillingness>
			<PortraitIndex>1</PortraitIndex>
			<IconAtlas>ROANAPUR_COLOR_ATLAS_LEGENDS</IconAtlas>
		</Row>
	</Leaders>

If so, is it possible to get an example of what I would write?
 
Yep, you just add those fields to your leader's entry in that table and put in the name of your texture file. Like this:

<VV_LeaderSceneOverride>YourTextureHere.dds</VV_LeaderSceneOverride>
 
Top Bottom