C++/Lua Request Thread

And then I was also wondering if anyone could program something like this as well:
Code:
When one of your units dies, a replacement unit has a 20% chance to appear outside the Capital.

Code:
GameEvents.UnitKilledInCombat.Add(function(iKillingPlayer, iKilledPlayer, iKilledUnitType) {
	local pPlayer = Players[iKilledPlayer]
	if pPlayer:GetCivilizationType() == iCiv and Game.Rand(5) == 0 then
		local pCapital = pPlayer:GetCapitalCity()
		if pCapital then
			local pPlot = pCapital:GetCityIndexPlot(1)
			pPlayer:InitUnit(iKilledUnitType, pPlot:GetX(), pPlot:GetY()):JumpToNearestValidPlot()
		end
	end
})

Just make sure you have a "local iCiv = GameInfoTypes.CIVILIZATION_ETC" line before this.
 
Great!

There's just one thing I forgot to ask for though: I need it to exclude Air units (if possible).
 
Code:
GameEvents.UnitKilledInCombat.Add(function(iKillingPlayer, iKilledPlayer, iKilledUnitType) {
	local pPlayer = Players[iKilledPlayer]
	if pPlayer:GetCivilizationType() == iCiv and Game.Rand(5) == 0 then
		local pCapital = pPlayer:GetCapitalCity()
		if pCapital then
			local pPlot = pCapital:GetCityIndexPlot(i)
			for row in DB.Query("SELECT * FROM Units WHERE ID = "..iKilledUnitType.." AND NOT (Domain = 'DOMAIN_AIR');") do
				pPlayer:InitUnit(iKilledUnitType, pPlot:GetX(), pPlot:GetY()):JumpToNearestValidPlot()
			end
		end
	end
})

I think this should work.
 
Code:
GameEvents.UnitKilledInCombat.Add(function(iKillingPlayer, iKilledPlayer, iKilledUnitType) [COLOR="Red"][B]{[/B][/COLOR]
	local pPlayer = Players[iKilledPlayer]
	if pPlayer:GetCivilizationType() == iCiv and Game.Rand(5) == 0 then
		local pCapital = pPlayer:GetCapitalCity()
		if pCapital then
			local pPlot = pCapital:GetCityIndexPlot(i)
			for row in DB.Query("SELECT * FROM Units WHERE ID = "..iKilledUnitType.." AND NOT (Domain = 'DOMAIN_AIR');") do
				pPlayer:InitUnit(iKilledUnitType, pPlot:GetX(), pPlot:GetY()):JumpToNearestValidPlot()
			end
		end
	end
[COLOR="red"][B]}[/B][/COLOR] )

I think this should work.
Why you has table symbols? Am I missing something?
 
Why you has table symbols?

I do that all the time! It's the sign of a confused JavaScript/Java/C++ programmer ;)

The { should be omitted
The } should be "end"
 
After some debilitating failure, I've consigned myself to the fact I'm not very good with lua, so I'd like to make some simple (by my estimation) requests:
  • Cycle through each unit. If a unit has PROMOTION_SENSHI_BANNER_1, and an adjacent unit also has PROMOTION_SENSHI_BANNER_1, this unit receives PROMOTION_SENSHI_BANNER_BONUS. Likewise for PROMOTION_SENSHI_BANNER_2, PROMOTION_SENSHI_BANNER_3, up to PROMOTION_SENSHI_BANNER_8. Otherwise, if it has PROMOTION_SENSHI_BANNER_BONUS, remove the promotion.
  • If UNIT_SENSHI_BANNERMAN is adjacent to two or more units with the same Banner type (as above), it receives PROMOTION_SECOND_ATTACK. Otherwise, if it has PROMOTION_SECOND_ATTACK, remove the promotion.
  • UNIT_SENSHI_GREEN_STANDARD is 20% cheaper to build in cities with a Courthouse.
 
After some debilitating failure, I've consigned myself to the fact I'm not very good with lua, so I'd like to make some simple (by my estimation) requests:
  • Cycle through each unit. If a unit has PROMOTION_SENSHI_BANNER_1, and an adjacent unit also has PROMOTION_SENSHI_BANNER_1, this unit receives PROMOTION_SENSHI_BANNER_BONUS. Likewise for PROMOTION_SENSHI_BANNER_2, PROMOTION_SENSHI_BANNER_3, up to PROMOTION_SENSHI_BANNER_8. Otherwise, if it has PROMOTION_SENSHI_BANNER_BONUS, remove the promotion.
  • If UNIT_SENSHI_BANNERMAN is adjacent to two or more units with the same Banner type (as above), it receives PROMOTION_SECOND_ATTACK. Otherwise, if it has PROMOTION_SECOND_ATTACK, remove the promotion.
  • UNIT_SENSHI_GREEN_STANDARD is 20% cheaper to build in cities with a Courthouse.
  1. Can only UNIT_SENSHI_BANNERMAN have these PROMOTION_SENSHI_BANNER_X promotions, or can any unit-type of player-X have these promotions?
  2. Can only units of player-X have these promotions and these effects?
  3. Checking for all these adjacencies during a player's turn as a unit moves from plot to plot using UnitSetXY event is possible but it is often lag-inducing esp in the late-game where there can be lots of units on the map, and UnitSetXY fires for every one of these for every entry into every tile
  4. Doing this all as part of PlayerDoTurn is not intrinsically any more or less difficult in terms of programming the code goes, but it is far more efficient in terms of processing and does not generally tend to create much of any perceptible lag (though mechanics like you are looking for have that potential even as part of turn processing). The downside is that the effects (promotions) get set at the start of the player's turn and remain applied for the duration of that turn regardless of where the unit moves to after the player gets control back from turn processing
  5. Depending on what exactly you mean by
    UNIT_SENSHI_GREEN_STANDARD is 20% cheaper to build in cities with a Courthouse.
    you might be able to make use of table Unit_ProductionModifierBuildings:
    Code:
    	<Table name="Unit_ProductionModifierBuildings">
    		<Column name="UnitType" type="text" reference="Units(Type)"/>
    		<Column name="BuildingType" type="text" reference="Buildings(Type)"/>
    		<Column name="ProductionModifier" type="integer"/>
    	</Table>
    It's a production-modifier effect so does not make purchasing cheaper.
 
  1. Any unit type of player-X (CIVILIZATION_SENSHI_MANCHU, sorry for not specifying) can have each of the Banner promotions
  2. Only units of player-X should have these promotions, but it's occurred to me that other civilizations might be able to get them through captures and the sort. I should probably make a check for that :p

Regarding 3 and 4, if you feel like it's going to cause that much lag, I'd be happy to move it to the start of the turn. Honestly my knowledge of lua is so limited I thought it was going to be at the start of the turn anyway :p

In regards to 5, that seems perfect! I now feel very foolish for not knowing that XML table...
 
Okay, so considering that this probably won't be able to happen:
Code:
+1 Global Happiness for each Civilization following the same Ideology as you. You are twice as effective at influencing other Civilizations of different Ideologies to switch to your Ideology. Captured cities spend half as much time in Resistance.

I've finally thought of something that would be good enough to substitute for it. Basically, I need a .lua code that will give the civilization (CIVILIZATION_AMERICA is my default choice) a building in their capital for each captured enemy city they possess. The building of course will be allowed to stack itself indefinitely; though the number of said buildings is irrelevant over the 3rd, but I need a code that can achieve this.
 
Okay, so I currently need an lua code that does the following:

Code:
Receive a +20% Attack Bonus when at war with a Civilization that you have Denounced. Receive a +20% Defense Bonus when at War with a Civilization that has Denounced you.

Basically, I need a code that triggers a Combat Bonus (either attack or defense) whenever you're at war with a civilization that you have either previously denounced, or has previously denounced you.
 
Alright, this should be simple enough:

I need an lua code that give the player (my default is: CIVILIZATION_AMERICA) a dummybuilding when they discover a specific technology (in this case: TECH_FLIGHT).

Anyone think they can help with that?
 
I have a request that should be pretty simple to do: I want to spawn a barbarian unit that will not move on the turn it's spawned.

I already have code that spawns the units, tied to GameEvents.PlayerDoTurn, and checking if it's the barbarian player that has the turn. The code uses the Player:InitUnit function. But the units move on the turn they are spawned, and I want to prevent it.
 
Alright, this should be simple enough:

I need an lua code that give the player (my default is: CIVILIZATION_AMERICA) a dummybuilding when they discover a specific technology (in this case: TECH_FLIGHT).

Anyone think they can help with that?
Code:
local iAmerica = GameInfoTypes.CIVILIZATION_AMERICA
local iFlight = GameInfoTypes.TECH_FLIGHT
local iDummyBuilding = GameInfoTypes.BUILDING_DUMMY_AMERICAN
local iAmericanTeam 
local pAmericanPlayer

function OnTeamTechResearched(iTeam,iTech)
	if iTeam == iAmericanTeam and iTech == iFlight then
		for pCity in pAmericanPlayer:Cities() do
			pCity:SetNumRealBuilding(iDummyBuilding, 1)
		end
    end
end

for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
	local pPlayer = Players[iPlayer]
	if pPlayer:IsEverAlive() and pPlayer:GetCivilizationType() == iAmerica then
		GameEvents.TeamTechResearched.Add(OnTeamTechResearched)
		iAmericanTeam = pPlayer:GetTeam()
		pAmericanPlayer = pPlayer
		break
    end
end
 
Think that could be flawed since you would need a function to make sure that dummy building bonus stay active in any of America's cities (Conquered or reconquered)
 
What happens when America builds/conquers a city AFTER the tech is researched?
 
Couldn't you do this by adding a second Trait to the civ, that activates upon researching Flight and assigns the dummy building as a free building in each city?
 
Back
Top Bottom