C++/Lua Request Thread

Hi, I was wondering how I'd go around creating the Lua that converts every 5 culture into 2 tourism . Would this be possible? as I remember tourism was quite difficult to work with.

Also, can a building provide a resource based on local happiness? I know yields can be provided by population, and I guess I'd do that if this isn't possible, but I was wondering.
 
I'm about 99% sure this isn't possible, but...

Can a Civilization's color be changed after game start? I can set the color with PreGame.SetPlayerColor() as is usual for PreGame things it doesn't matter once the game's actually started (dawn of man, etc).

Tried reloading the map, didn't seem to work.
 
Okay so I hear you can ask whatever coding question here and it will be answered. My question is can you have a UI that replenishes the movement point of a friendly unit that enter's the UI?
 
can you have a UI that replenishes the movement point of a friendly unit that enter's the UI?

Assuming both UIs mean Unique Improvement and not User Interface - yes. Use the UnitSetXY() event handler, test XY for having the required improvement, test for a friendly unit and if use Set/ChangeMoves() to give movement points - note that you need to multiply by 60, so 2 moves is 120, half a move is 30
 
Assuming both UIs mean Unique Improvement and not User Interface - yes. Use the UnitSetXY() event handler, test XY for having the required improvement, test for a friendly unit and if use Set/ChangeMoves() to give movement points - note that you need to multiply by 60, so 2 moves is 120, half a move is 30

Yeah I did mean Unique Improvemnt, does it matter if it is a citedal?
 

Okay then, but where does one recode a citadel to do what it does plus this?
Han: Normal citadel benefits +4 gold, +2 with road/railroad connection, +1 tourism after flight. Replenishes half movement points of friendly units.
 
It's an UA, right?

I should be able to code it when I get home.
 
Okay then, but where does one recode a citadel to do what it does plus this?
Han: Normal citadel benefits +4 gold, +2 with road/railroad connection, +1 tourism after flight. Replenishes half movement points of friendly units.

This is the Lua for your UA:
Code:
local eSgtWolfCiv = GameInfoTypes["[COLOR="Red"]CIVILIZATION_YOUR_CIV_HERE[/COLOR]"]


function CitadelReplenishMoves(iPlayer, iUnit, iPlotX, iPlotY)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == eSgtWolfCiv then
		local pPlot = Map.GetPlot(iPlotX, iPlotY)
		if pPlot:GetImprovementType() == GameInfoTypes["IMPROVEMENT_CITADEL"] then
			local pUnit = pPlayer:GetUnitByID(iUnit)
			local iExtraMoves = math.floor(pUnit:MaxMoves() / 2)
			pUnit:ChangeMoves(iExtraMoves)
		end
	end
end

GameEvents.UnitSetXY.Add(CitadelReplenishMoves)

Change this to your civ's actual name.

This will make any unit gain half their maximum amount of movements when stepping on a Citadel tile; note, this might cause it to have more moves than their maximum [an unit with 4/4 moves uses it's first step to enter a citadel (3/4 moves), earning 2 moves(3/4 + 2); it's total is now 5/4].
If you need something different, specify and it shall be done. :)


EDIT: You better test this code before launching, because I never used the MaxMoves() method, I don't know if it returns the real value of the movement (a multiple of 60) or the amount displayed in the Unit panel.
EDIT2: Ok, just took a quick look at the UnitPanel.lua, MaxMoves() returns the correct amount. The code is good to go! :D
 
It's an UA, right?

I should be able to code it when I get home.

No it's the UI, this this is the UA: Upon a buildings completion, it's production can over flow into the next unit's production.* +5% combat strength against cities per each ongoing trade route you have. *(10-15% maybe, we're gonna test run it).

This is the Lua for your UA:
Code:
local eSgtWolfCiv = GameInfoTypes["[COLOR="Red"]CIVILIZATION_YOUR_CIV_HERE[/COLOR]"]


function CitadelReplenishMoves(iPlayer, iUnit, iPlotX, iPlotY)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == eSgtWolfCiv then
		local pPlot = Map.GetPlot(iPlotX, iPlotY)
		if pPlot:GetImprovementType() == GameInfoTypes["IMPROVEMENT_CITADEL"] then
			local pUnit = pPlayer:GetUnitByID(iUnit)
			local iExtraMoves = math.floor(pUnit:MaxMoves() / 2)
			pUnit:ChangeMoves(iExtraMoves)
		end
	end
end

GameEvents.UnitSetXY.Add(CitadelReplenishMoves)

Change this to your civ's actual name.

This will make any unit gain half their maximum amount of movements when stepping on a Citadel tile; note, this might cause it to have more moves than their maximum [an unit with 4/4 moves uses it's first step to enter a citadel (3/4 moves), earning 2 moves(3/4 + 2); it's total is now 5/4].
If you need something different, specify and it shall be done. :)


EDIT: You better test this code before launching, because I never used the MaxMoves() method, I don't know if it returns the real value of the movement (a multiple of 60) or the amount displayed in the Unit panel.
EDIT2: Ok, just took a quick look at the UnitPanel.lua, MaxMoves() returns the correct amount. The code is good to go! :D

Okay thanks for this! Where will I put it though? Like does it go in the buildings code or somewhere else?
 
Okay thanks for this! Where will I put it though? Like does it go in the buildings code or somewhere else?

Put it in a .lua file that's set as an InGameUIAddin in the Content tab of the mod properties section in ModBuddy.
 
Put it in a .lua file that's set as an InGameUIAddin in the Content tab of the mod properties section in ModBuddy.

Okay then I'll do that! But should I finish all the XML coding first? I go code in what ever pattern I want?

Also where do I put this code in?
 
Hi guys. I'm finally attempting to actually code the Greek City-States I planned. Here are some questions:

Is it actually possible to replace the Cargo Ship with a combat unit? I tried using a Trireme and enable the trade ability but it returns as a normal Cargo Ship after finishing its route. I thought of coding a workaround that tracked which started out as the UU but I'm not sure if it's worth it to code that.

I'm thinking instead of replacing it with a Trireme that gets a boost if it's near a Trade Route. Is that do-able?

What instances do I actually need multiple building types for a dummy/hidden (not sure which is the right term) building? I took code from MC's Minoa since the Anaktoro gives +2 Science per Trade Route, and Rhodes' UA is +2 Production per Route. The Anaktoro doesn't have multiple dummies from the looks of it, but just one dummy that has that +2 and then the code just seems to give a City more of the building as more Trade Routes are established.

And for my last question, why can't I seem to add Lua files into the Content portion of the mod properties? It just displays all of my XMLs.
 
Hi guys. I'm finally attempting to actually code the Greek City-States I planned. Here are some questions:

Is it actually possible to replace the Cargo Ship with a combat unit? I tried using a Trireme and enable the trade ability but it returns as a normal Cargo Ship after finishing its route. I thought of coding a workaround that tracked which started out as the UU but I'm not sure if it's worth it to code that.

I'm thinking instead of replacing it with a Trireme that gets a boost if it's near a Trade Route. Is that do-able?

What instances do I actually need multiple building types for a dummy/hidden (not sure which is the right term) building? I took code from MC's Minoa since the Anaktoro gives +2 Science per Trade Route, and Rhodes' UA is +2 Production per Route. The Anaktoro doesn't have multiple dummies from the looks of it, but just one dummy that has that +2 and then the code just seems to give a City more of the building as more Trade Routes are established.

And for my last question, why can't I seem to add Lua files into the Content portion of the mod properties? It just displays all of my XMLs.
If the dummy just adds production, gold, science, food, culture, faith, or Happiness then you are safe with one dummy building, and then you just add multiple copies in the same city to create the amount of production, gold, etc., you want added.

Happiness has to be added directly to the dummy under table <Buildings>, whereas the other yields are added to the dummy building under table <Building_YieldChanges>

Select the file-name from the file-name dropdown before selecting from the type dropdown.
 
Would anyone be able to help out with this?

-> When unit creates a GW/is expended, surrounding land units gain unique promotion.

-> Unit Promotion that allows you to heal twice as fast and have double moves when starting on improvements with access to Fresh Water
 
Would anyone be able to help out with this?

-> When unit creates a GW/is expended, surrounding land units gain unique promotion.

-> Unit Promotion that allows you to heal twice as fast and have double moves when starting on improvements with access to Fresh Water

Community Patch Project actually fulfill both of your request with a simple LUA command(GameEvents.GreatPersonExpended) for the first and an XML tag for the second(<UnitFreePromotion> in Improvement and <IsLostOnMove> in UnitPromotions).

Otherwise, the second part with LUA where it has to do a painful plot check on all units. The first I don't know.
 
I'd also like to request some functions, if anybody's up for them:

  • When war is declared upon this civ (civ 1), they receive a free naval unit in all coastal cities. (Just the basic melee ship for each era, except for the eras which don't have one, i.e. Classical [Trireme], Medieval [Galleass], Atomic [Destroyer], Information [Missile Cruiser])
  • This civ (civ 1) gains Culture from settling or capturing coastal cities.
  • This naval unit gains extra great admiral points, similar to the Keshik. (could probably be done via XML but I'm not sure)
  • This civ (civ 2) gains +1 Golden Age points from each specialist slot filled and each Great Person improvement worked.
  • This civ (civ 2) gains a dummy building in the capital during a Golden Age, and a different dummy building in each other city for the Golden Age's duration.

If nobody is or they can't be coded, that's absolutely fine ;)
If any clarification is needed, that's also fine ;)
 
Hey, senshi, I can code it, and I know precisely what it is. That said, I'm in class right now.
 
Back
Top Bottom