C++/Lua Request Thread

I have a request if people wouldn't mind helping out.

How would I go about making a civ have +2 Gold from All Improvements during Golden Ages? It's for a Gold Rush themed California Republic.
 
While I am still in absolutely desperate panic-mode in my need for Lua for Yucatan, California, and CSA, perhaps the presence of some actual code that only needs to be edited for my upcoming (did I forget to announce it?) Cascadia mod will be a bit more likely to receive help.

I'm using code from the National Park mod (with the permission of the owner to both use it and edit it, of course), for a Unique Building that will require either a Natural Wonder, a Forest, or a Jungle nearby to be built. The Natural Wonder bit works perfectly, but I need it to also check for the aforementioned other features if there are no NWs nearby.

Spoiler :
Code:
function CanBuildCascadiaPark(iPlayer, iCity, iBuildingType)
	--print("CityCanConstruct() invoked with iPlayer=" .. Players[iPlayer]:GetName() .. ", iCity=" .. Cities[iCity]:GetName() .. ", iBuildingType=" .. Buildings[iBuildingType]:GetName() .. ".");
	--print("CityCanConstruct() invoked with iPlayer=" .. iPlayer .. ", iCity=" .. iCity .. ", iBuildingType=" .. iBuildingType .. ".");

	-- Check if the city has a Natural Wonder within its radius
	if GameInfo.Buildings[iBuildingType].Type == "BUILDING_CASCADIAPARK" then 
		local pCity = Players[iPlayer]:GetCityByID(iCity);
		--print("Looking for Natural Wonder in " .. pCity:GetName());
		for i = 0, pCity:GetNumCityPlots() - 1, 1 do
			local pPlot = pCity:GetCityIndexPlot( i );
			if (pPlot ~= nil) then
				if(pPlot:GetFeatureType() >= 0 and pPlot:GetOwner() == iPlayer) and GameInfo.Features[pPlot:GetFeatureType()].NaturalWonder then
					return true;
				end
			end
		end
		return false;
	end
	return true; -- Not checking for National Park, do not need to look for Natural Wonders
	--local aPlayer=Players[Game.GetActivePlayer()]; local aCity = aPlayer:GetCapitalCity(); for i = 0, aCity:GetNumCityPlots() - 1, 1 do local pPlot = aCity:GetCityIndexPlot( i ); if (pPlot ~= nil) then if(pPlot:GetOwner() == Game.GetActivePlayer()) and GameInfo.Features[pPlot:GetFeatureType()].NaturalWonder then print("true"); end end end
end

-------------------------
--- HOOK TO LISTENERS ---
-------------------------

GameEvents.CityCanConstruct.Add(CanBuildCascadiaPark);

print("CityCanConstruct.lua loaded.");

If anyone can help me out with this bit, and/or is interested in doing more Lua for Cascadia or any of the other mods, I'll be eternally indebted to you.
 
Code:
local iCascadiaPark = GameInfoTypes.BUILDING_CASCADIAPARK
local iForest = GameInfoTypes.FEATURE_FOREST
local iJungle = GameInfoTypes.FEATURE_JUNGLE

function CanBuildCascadiaPark(iPlayer, iCity, iBuildingType)
  if (iBuildingType == iCascadiaPark) then 
    local pCity = Players[iPlayer]:GetCityByID(iCity)

    for i = 0, pCity:GetNumCityPlots() - 1, 1 do
      local pPlot = pCity:GetCityIndexPlot(i)
      if (pPlot and pPlot:GetOwner() == iPlayer) then
        local iPlotFeature = pPlot:GetFeatureType()
        if (iPlotFeature >= 0 and (iPlotFeature == iForest or iPlotFeature == iJungle or GameInfo.Features[iPlotFeature].NaturalWonder)) then
          return true
        end
      end
    end
    return false
  end

  return true
end
GameEvents.CityCanConstruct.Add(CanBuildCascadiaPark)

Pretty sure the
Code:
if (pPlot and pPlot:GetOwner() == iPlayer) then
  ...
end
statement is redundant as you're explicitly getting city plots, but it doesn't hurt to be paranoid!
 
Awesome! I just tested it out in-game, and it works like a charm. Thank you, whoward! On the Cascadia note, if you or anyone else wants to try and code any of the other attributes requiring Lua, here they are:

  • For that UB (a State Park), it's a Garden replacement that has the aforementioned terrain requirements instead of needing fresh water, and further increases the GP spawn rate by 5% for each unimproved tile adjacent to the city itself. So, maybe a script that checks for the building, checks the adjacent 6 tiles for improvements, and awards hidden buildings (BUILDING_CASCADIA_DUMMY) appropriately?
  • For the UU (UNIT_SASQUATCH_MILITIA, an Infantry replacement), a script that has a very slight chance to spawn said units on unimproved Forest tiles within Cascadian territory on the outbreak of war. If that's not possible, than a further reduced chance on all Forest tiles, improvement or not, would still be great!
  • And this last one is a real doozy, probably requires the most complicated, horrendous, code out of all of them, but is still pretty essential to the design. For the UA, enemy Cities may revolt and join your empire even before adopting an Ideology. So basically, enemy cities within a certain radius of Cascadian cities (10 or so at most, for the sake of balance) where the owner's Global Happiness is under 10 or 20, have a chance each turn to join Cascadia, regardless of Ideology, and ideally would display the normal messages ("The citizens of [city name] have revolted and split from [civ name], declaring themselves the newest state of Cascadia!", or something along those lines).

Again to any and all takers who want to do any code for any of those, I thank you in advance!
 
I'd like a lua script that will allow a player to immediately be able to found a pantheon and religion after founding a city.
 
If you mean after founding the Capital city, I'd think all you would need to do is set the Civ to spawn with a free UNIT_PROPHET. If you mean with the second city, I think that might require a little bit of lua (to give a free unit/hidden building with that city, but not the Capital or any of the other cities.)
 
Here is the description for what we need:

"Weaker than the Galleass it replaces, the Lantaka is actually a land unit that can fire without setting up when embarked. When garrisoned within a city, the Lantaka provides the same yields as a Great Work of Art. Since the Lantaka replaces the Galleass, it can be built faster as dictated by the UA and provides +1 Food if placed on a Sea Resource."

I'm not sure if any of this is possible. If someone could tell me if it is/isn't that'd be great.

Also a unit that Gains a +25% Defensive Bonus and +1 Happiness for the empire while stationed on a Luxury Resource. Also can repair pillaged improvements.
 
If you mean after founding the Capital city, I'd think all you would need to do is set the Civ to spawn with a free UNIT_PROPHET. If you mean with the second city, I think that might require a little bit of lua (to give a free unit/hidden building with that city, but not the Capital or any of the other cities.)
Capital city, yes. Spawning a prophet doesn't allow creation of a religion if a pantheon hasn't been founded.
 
Spawning a prophet doesn't allow creation of a religion if a pantheon hasn't been founded.

My tests show that it does - when you get a prophet before creating a religion, you can found a religion immediately, and select all 3 beliefs for it.
 
My tests show that it does - when you get a prophet before creating a religion, you can found a religion immediately, and select all 3 beliefs for it.

How are you getting the prophet? I'm tried using traits for a free prophet at game start and the button to create a religion doesn't appear, even after founding a city.
 
How are you getting the prophet? I'm tried using traits for a free prophet at game start and the button to create a religion doesn't appear, even after founding a city.

I just create it using FireTuner.

Edit: Note that the Prophet must be inside the city to be able to found a religion.
 
Edit: Note that the Prophet must be inside the city to be able to found a religion.

That did work, thanks.
Though I wonder if it's possible to bypass that step and simply be able to found a religion (with chooseable beliefs) immediately after the capital city is founded, without having to have a prophet and move the prophet inside the capital.
 
Hey...seems like this thread is pretty active. I'm looking for some Lua help. For my upcoming UAE civ, there's three things that I need to happen.

1. You get some tourism from your gold stockpile. Let's say, 1 tourism per 200 gold.
2. Your civ gets Production from incoming trade routes.
3. A building which adds +1 gold to all tiles with a resource on it. Ideally, an extra gold for a strategic.

I'm primarily working on 1. I took a look at Mali from Tomatekh. I can read and understand his code...I just don't know what functions I have available to me. Is there a reference available for that sort of thing? I figure I can find another mod that does something with tourism so i can see specifically what to do, but I'm just curious if there's a thing I'm missing. Also, like my sig says, if you're interested in doing 20th-21st century civs with me let me know :)
 
Pleaaase help! I need help with UI components.
It's been a while that I try to understand this facet of modding, but it seems I can't get it right!

I put up a thread and even thought I could do it once I saw the Morindim's codes by whoward69. But I can't. Simply put.

I have two sets of incomplete codes. I could get the missions to work with a different approach, but I'm not sure how to make it work with a UI component to select the civilization.


-== Codes ==-​
Relevant Lua mission snippet (based on bouncymisha's code):
Spoiler :
Code:
  Action = function(action, unit, eClick)
	if eClick == Mouse.eRClick then
		return
	end
    local pPlayer = Players[Game:GetActivePlayer()];

	print("Summoning a Skeleton.")

	if pPlayer:IsHuman() then
		pPlayer:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, "Summoning!" ,"One of your sorceresses summoned a skeleton!", -1, -1);
	end
	KotSUpdateCivList() -- should this be 'ContextPtr:SetHide(false)' or something? If so, would the print work?
	print("Civ chosen is: " .. pCivs:GetCivilizationType())

  end,
}

MenuUtils.lua
Spoiler :
Code:
function Show()
  ShowMenu(g_MenuID)
end

function Hide()
  ShowMenu("")
end

function OnShowMenu(sMenu)
  if (g_MenuID == sMenu) then
    ContextPtr:SetHide(false)
  else
    ContextPtr:SetHide(true)
  end
end
LuaEvents.TestMenu_Show.Add(OnShowMenu)

function ShowMenu(sMenu)
  LuaEvents.TestMenu_Show(sMenu)
end

function Show1()
  ShowMenu("Menu1")
end

function Show1b()
  ShowMenu("Menu1b")
end

function Show2()
  ShowMenu("Menu2")
end

function Show2b()
  ShowMenu("Menu2b")
end

function Show3()
  ShowMenu("Menu3")
end

The (big) Menu.lua:
Spoiler :
Code:
print('Menu.lua loaded.')

local g_SortTable

function KotSOnShowHide(bHide, bInit)
	if (not bHide) then
		KotSUpdateCivList()
	end
end
ContextPtr:SetShowHideHandler(KotSOnShowHide)

function KotSOnOK()
	ContextPtr:SetHide(true)
	return pCivs:GetCivilizationType()
end
Controls.OK:RegisterCallback(Mouse.eLClick, KotSOnOK)

function SortByName(a, b)
	local sNameA = g_SortTable[tostring(a)].Name
	local sNameB = g_SortTable[tostring(b)].Name
	return sNameA < sNameB
end

function KotSOnCivSelected(iPlayerCivs)
	local pCivs = Players[iPlayerCivs]
end
Controls.CivMenu:GetButton():SetText(pCivs:GetName())

function KotSUpdateCivList()
	local iTeam = Game.GetActiveTeam()
	Controls.CivMenu:ClearEntries()
	g_SortTable = {}
	for iPlayerCivs = 0, GameDefines.MAX_MAJOR_CIVS-1,	1 do
		local pCivs = Players[iPlayerCivs]
			if pCivs:IsEverAlive() then
			if (pCivs:IsAlive() and Teams[pCivs:GetTeam()]:IsHasMet(iTeam)) then
				local sCivName = pCivs:GetName()
				local entry = {}
				Controls.CivMenu:BuildEntry("InstanceOne", entry)
				g_SortTable[tostring(entry.Button)] = {Name=sCivName}
				entry.Button:SetVoid1(iPlayerCivs)
				entry.Button:SetText(sCivName)
			end
		end
	end
	Controls.CivMenuStack:SortChildren(SortByName)
	Controls.CivMenu:GetButton():LocalizeAndSetText( "TXT_KEY_TEST_MENU_Civ_CHOOSE")
	Controls.CivMenu:CalculateInternals()
	Controls.CivMenu:RegisterSelectionCallback(KotSOnCivSelected)
end

Menu.xml
Spoiler :
Code:
<GameData>
	<Context ID="1">
		<Box Style="BGBlock_ClearTopBar" />
		<Instance Name="Civilizations">
			<Label ID="Label" Anchor="L,T" Font="TwCenMT20" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
		</Instance>
		<Grid Size="600,400" Anchor="C,C" Style="Grid9DetailFive140" ConsumeMouse="1">
			<Label ID="Message" Anchor="C,T" Offset="0,50" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" String="TXT_KEY_TEST_MENU_Civ_TITLE"/>
			<PullDown ID="CivMenu" Style="GenericPullDown" ScrollThreshold="170" Size="190,27" SpaceForScroll="1" Anchor="C,T" Offset="0,90">
				<StackData ID="CivMenuStack"/>
				<InstanceData Name="InstanceOne" >
					<Button ID="Button" Size="200,24" Anchor="L,C">
						<ShowOnMouseOver>
							<AlphaAnim Anchor="C,C" Size="140,24" Pause="0" Cycle="Bounce" Speed="1" AlphaStart="1" AlphaEnd="0">
								<Grid Size="140,26" Style="Grid9FrameTurns" />
							</AlphaAnim>
						</ShowOnMouseOver>
						<Label ID="CivName" Anchor="L,C" Offset="40,0" Font="TwCenMT20" FontStyle="Shadow" ColorSet="Beige_Black_Alpha">
						</Label>
					</Button>
				</InstanceData>
			</PullDown>
			<GridButton ID="OK" Size="140,36" Anchor="C,B" Offset="0,50" Style="BaseButton" ToolTip="TXT_KEY_TEST_MENU_BUTTON_OK_TT">
				<Label Anchor="C,C" Offset="0,-2" String="TXT_KEY_TEST_MENU_BUTTON_OK" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
			</GridButton>
		</Grid>
	</Context>
</GameData>

Any little help would be appreciated. :goodjob:
 
Is it possible (without DLL hacks) to code a unique starter unit which founds a capital city and a religion at the same time? If it's doable, then that's the kind of starting unit I hope to give my merged version of the Papal States: could somebody please point me to the right scripts for the job? Thank you!
 
Isnorden, that is doable with lua. Hook into the playerFoundCity event and test to see if the founded city is the capital and if the player is the papal states civilization. If so, you could a) spawn a great prophet, b) give them 200ish faith.
 
OK, next question: How do you give a civilization a "dedicated" list of Great Works (once you have the pictures, sound files, and quotations to choose from)? I looked through JFD's mod, but couldn't find the right script; PapalStatesFunctions.lua didn't mention that.
 
Hey guys, here is a list of Revolutionary Bonuses (a Revolution is 3 turns of Anarchy, followed by 3 turns of a Golden Age). Revolutions happens whenever the first type of Great Person is born (not sure how to do that - so I'd like help on that too).

Revolutionary Bonuses

Radio Rebelde
+2% :tourism: Tourism bonus for each improved Sea Resource in the Empire. Rises to +3% :tourism: Tourism after an Ideology is picked. Gain +100 :tourism: Tourism whenever a Great Admiral is born.

Heroes Of Yaguajay
A free Great General Appears near the Capital. Enemy units in your territory take attrition damage on Forest and Jungle tiles. Gain +100 :tourism: Tourism whenever a Great General is born.

Betto Dialogues
The Shrines and Temples provide +1 :tourism: Tourism. Units purchased with :c5faith: Faith are 25% cheaper. Gain +100 :tourism: Tourism whenever a Great Prophet is born.

International Interventionism
Militaristic City-States gift units to you at double the rate. Workers captured from City-States may be converted to the most advanced Mounted unit you can build and gain Cover I. Gain +100 :tourism: Tourism whenever a Great Merchant is born.

Organiponicos
Cities with a garrisoned land unit provide a +2% Food Growth Bonus for each level of experience earned. Granaries, Water Mills, Aqueducts, Hospitals, and Medical Labs each provide +1 :tourism: Tourism respectively. Gain +100 :tourism: Tourism whenever a Great Scientist is born.

Timba Explosion
Birth rate of :c5greatperson: Great Musicians increased by 33% in cities with a Dance Hall. Writers, Artists and Musician Guilds provide +2 :c5gold: Gold. Gain +100 :tourism: Tourism whenever a Great Musician is born.

Afrocubanismo
Units start with an additional +15XP if built the Great Work of Writing slot in the National Epic is filled. Gain +100 :tourism: Tourism whenever a Great Writer is born.

Grupo Antillano
Great works of Art generate +1 :c5gold: Gold for each Trade Route with another civ or City-State sent to or from the City in which it is housed. Gain +100 :tourism: Tourism whenever a Great Artist is born.

Microbrigada
Melee Unit and Defensive Building costs are reduced by 25% if the city has a Specialist. This bonus is increased to +30% in the :c5capital. Gain +100 :tourism: Tourism whenever a Great Engineer is born.
 
Back
Top Bottom