Lua Questions

Aidence

The Archduke
Joined
Nov 23, 2013
Messages
224
How would I make this UA possible: "For every 5 units under your control, receive 1 delegate to the World Congress."? Also for every mod I try to use Lua, the Lua never works, so how do I get Lua to work in the first place? Thanks in advance.
 
To close to time to leave for cook-out and fireworks show to answer substantively today, but I'll try to remember to take a look at the idea tomorrow. Unless, of course, someone throws you an answer before then.
 
Lua, unsurprisingly, will be required.

Ideally it should go something like this:
1) Get the number of units the player has with the function Player.GetNumUnits()
2) once you get that number, divide it by 5 using math.floor, kind of like this:
Code:
numExtraDelegates = math.floor(numUnits / 5)
3) I think this should speak for itself:
Code:
player:GetCapitalCity():SetNumRealBuilding(GameInfoTypes.BUILDING_XTRA_DELEGATES, numExtraDelegates)
4) Hook into GameEvents.PlayerDoTurn so it fires each turn. Done.

EDIT: SPOILER = Free code, but optimally you should learn to code it like I'm trying to
Spoiler :
Code:
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
	pPlayer = Players[iPlayer]
	if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_YOUR_CIV) then
		pUnit_num = pPlayer:GetNumUnits()
		pPlayer_xtraDelegates = math.floor(pUnit_num / 5)
		pPlayer:GetCapitalCity():SetNumRealBuilding(GameInfoTypes.BUILDING_XTRA_DELEGATES, pPlayer_xtraDelegates)
	end
end)

Now, for BUILDING_XTRA_DELEGATES, give it the column <ExtraLeagueVotes> set to 1, and give its buildingclass the column <NoLimit> set to true. You also may want to make the building invisible, optimally.

Also... potentially a super-OP UA.
 
Would this be the correct code:
<Buildings>
<Row>
<Type>BUILDING_BUILDING_EXTRA_DELEGATES</Type>
<NoLimit>true</NoLimit>
<Cost>-1</Cost>
<GoldMaintenance>-1</GoldMaintenance>
<PrereqTech>NULL</PrereqTech>
<FaithCost>-1</FaithCost>
<ExtraLeagueVotes>1</ExtraLeagueVotes>
</Row>
</Buildings>
I made sure to add the 'E' in the Lua.

EDIT I just tried it, the UB icon is gone, the civ and UU icons are switched and the only civs are my civ, Morocco, and Greece. Please help.
 
...you forgot to give it a buildingclass...

It, optimally, needs to be a completely new buildingclass. And <NoLimit>true</Limit> is a column for a buildingclass, not building.

Also, I'm not sure what setting maintenance cost to -1 would do but 0 makes it a free building, so that can probably be outright deleted.
 
So, I got the mod working, yet the UA does not. Do I need to turn on import to VFS?
 
Lua doesn't need VFS=true unless it's replacing a base game file (in which case it must also have the exact same name as that file), is a map script (in which case it also needs a MapScript entry), or another file references it using the include() function. In any case none of those [should] apply, so you give it an InGameUIAddin Entry. (See this thread for additional details and on how to give a file an entry)
 
I got the UA working, however I need it to be 5 military units. Sorry it was my fault, I didn't specify.
 
Okay so I added the word Military in the code as you described, and I got a bug that I have seen before but never knew how to fix it. Here is a screenshot:

I have no idea how to fix it. Maybe you can help.
 
Logs! Logs, Aidence! Logs!
And attachment!

Other than that; yeah, I've never seen such a thing either. I can tell you that your icons have too large of a diameter, but I've never seen that "Civ Specific Bonus 2" thing before. :confused:
 
Top Bottom