Getting gold from building units

Uighur_Caesar

Comandante en Jefe
Joined
Mar 14, 2015
Messages
1,227
Location
Florida
Ok so I'm trying to make a UA and I'm having some trouble. The first half of the UA is this "Gain Gold upon constructing naval units and workboats." I kind of have an idea of how to do it but could use some help. Here's what I currently have:
Code:
local UlsterID = GameInfoTypes["CIVILIZATION_ULSTER"]
																
function GoldFromNavy(playerID, cityID, unitID)
	local player = Players[playerID];
    if (player:IsAlive() and player:GetCivilizationType() == UlsterID) then 		
		local unit = player:GetUnitByID(unitID)
		local domain = unit:GetUnitCombatType()
		if domain = GameInfoTypes["UNITCOMBAT_NAVAL"] then
		player:ChangeGold(100)
			end	
		end
	end
end

GameEvents.CityTrained.Add(GoldFromNavy)

Right now I'm using 100 because I haven't come up with an exact equation for the amount of gold gained. I'm planning to make it a fraction of the unit's production cost so that it scales naturally. I don't think that will be hard to do, I just need to know what I'm doing wrong on the first part. Right now when I test it the player doesn't get any gold. I looked at the lua logs and it said that there's an error on the line that says:
Code:
if domain = GameInfoTypes["UNITCOMBAT_NAVAL"] then

It says it expects a "then" near the "=" even though I have a "then" on that line. There's probably more errors than just that so if anyone could help me out I would really appreciate it.
 
Ok so I'm trying to make a UA and I'm having some trouble. The first half of the UA is this "Gain Gold upon constructing naval units and workboats." I kind of have an idea of how to do it but could use some help. Here's what I currently have:
Code:
local UlsterID = GameInfoTypes["CIVILIZATION_ULSTER"]
																
function GoldFromNavy(playerID, cityID, unitID)
	local player = Players[playerID];
	if (player:IsAlive() and player:GetCivilizationType() == UlsterID) then
		local unit = player:GetUnitByID(unitID)
		local domain = unit:GetUnitCombatType()
		if domain [COLOR="Red"]=[/COLOR]= GameInfoTypes["UNITCOMBAT_NAVAL"] then
			player:ChangeGold(100)
		end	
		[COLOR="Red"]end[/COLOR]
	end
end
GameEvents.CityTrained.Add(GoldFromNavy)

Right now I'm using 100 because I haven't come up with an exact equation for the amount of gold gained. I'm planning to make it a fraction of the unit's production cost so that it scales naturally. I don't think that will be hard to do, I just need to know what I'm doing wrong on the first part. Right now when I test it the player doesn't get any gold. I looked at the lua logs and it said that there's an error on the line that says:
Code:
if domain = GameInfoTypes["UNITCOMBAT_NAVAL"] then

It says it expects a "then" near the "=" even though I have a "then" on that line. There's probably more errors than just that so if anyone could help me out I would really appreciate it.
When checking for equality you need double-tap on the = symbol, as in:
Code:
if domain == GameInfoTypes["UNITCOMBAT_NAVAL"] then
Plus you've got too many 'end' commands

But in order to check for whether a newly-created unit is a workboat or naval unit I wouldn't compare to UNITCOMBAT_NAVAL because this will eliminate workboats, ranged naval units, melee naval units, submarines, and carriers:
Spoiler :
Code:
Listing for BNW
G&K is slightly different

DOMAIN_SEA (contains the following unitcombat subtypes)
	UNITCOMBAT_NAVALRANGED
		UNITCLASS_GALLEASS
			UNIT_GALLEASS
			UNIT_VENETIAN_GALLEASS
		UNITCLASS_TRIREME
			UNIT_BYZANTINE_DROMON
		UNITCLASS_FRIGATE
			UNIT_FRIGATE
			UNIT_ENGLISH_SHIPOFTHELINE
		UNITCLASS_BATTLESHIP
			UNIT_BATTLESHIP
		UNITCLASS_MISSILE_CRUISER
			UNIT_MISSILE_CRUISER
	UNITCOMBAT_NAVALMELEE
		UNITCLASS_GALLEY
			UNIT_GALLEY
		UNITCLASS_TRIREME
			UNIT_TRIREME
			UNIT_CARTHAGINIAN_QUINQUEREME
		UNITCLASS_PRIVATEER
			UNIT_PRIVATEER
			UNIT_DUTCH_SEA_BEGGAR
		UNITCLASS_CARAVEL
			UNIT_CARAVEL
			UNIT_PORTUGUESE_NAU
			UNIT_KOREAN_TURTLE_SHIP
		UNITCLASS_IRONCLAD
			UNIT_IRONCLAD
		UNITCLASS_DESTROYER
			UNIT_DESTROYER
	UNITCOMBAT_SUBMARINE
		UNITCLASS_SUBMARINE
			UNIT_SUBMARINE
		UNITCLASS_NUCLEAR_SUBMARINE
			UNIT_NUCLEAR_SUBMARINE
	UNITCOMBAT_CARRIER
		UNITCLASS_CARRIER
			UNIT_CARRIER
As I recall I thought UNITCOMBAT_NAVAL was only used in Vanilla, but my memory could be wrong there, as in it might not have been used in Vanilla either.

I would re-write as:
Code:
local UlsterID = GameInfoTypes["CIVILIZATION_ULSTER"]
iDomainSea = GameInfoTypes.DOMAIN_SEA

function GoldFromNavy(playerID, cityID, unitID)
	local player = Players[playerID];
	if (player:IsAlive() and player:GetCivilizationType() == UlsterID) then
		local unit = player:GetUnitByID(unitID)
		if unit:GetDomainType() == iDomainSea then
			player:ChangeGold(100)
		end	
	end
end
GameEvents.CityTrained.Add(GoldFromNavy)
 
Thanks it's giving me gold now. I tried to implement having the amount of gold change by the unit's production so I currently have this code:
Code:
local UlsterID = GameInfoTypes["CIVILIZATION_ULSTER"]
local domainSea = GameInfoTypes["DOMAIN_SEA"]
																
function GoldFromNavy(playerID, cityID, unitID)
	local player = Players[playerID];
    if (player:IsAlive() and player:GetCivilizationType() == UlsterID) then 		
		local unit = player:GetUnitByID(unitID)		
		if unit:GetDomainType() == domainSea then
                local prodCost = player:GetUnitProductionNeeded(unit)
		local goldBoost = 1 * prodCost
		player:ChangeGold(goldBoost)		
			end	
		end
	end

GameEvents.CityTrained.Add(GoldFromNavy)

I'm trying to get it to give you the unit's production cost in gold. The problem with this new code is that the amount of gold given does not vary. Every naval unit produced gives 71 gold.
 
Thanks it's giving me gold now. I tried to implement having the amount of gold change by the unit's production so I currently have this code:
Code:
local UlsterID = GameInfoTypes["CIVILIZATION_ULSTER"]
local domainSea = GameInfoTypes["DOMAIN_SEA"]
																
function GoldFromNavy(playerID, cityID, unitID)
	local player = Players[playerID];
    if (player:IsAlive() and player:GetCivilizationType() == UlsterID) then 		
		local unit = player:GetUnitByID(unitID)		
		if unit:GetDomainType() == domainSea then
                local prodCost = player:GetUnitProductionNeeded([COLOR="Red"]unit[/COLOR])
		local goldBoost = 1 * prodCost
		player:ChangeGold(goldBoost)		
			end	
		end
	end

GameEvents.CityTrained.Add(GoldFromNavy)

I'm trying to get it to give you the unit's production cost in gold. The problem with this new code is that the amount of gold given does not vary. Every naval unit produced gives 71 gold.
"unit" is the unit's object for that particular individual unit. If I am reading correctly what player:GetUnitProductionNeeded(X) wants for the "X" it wants the ID # that corresponds to the unit's <Type> from the <Units> table. So you would need to do
Code:
player:GetUnitProductionNeeded(unit:GetUnitType())

-----------------------------------------------------------------------------------------------

And as an FYI, these two methods are equal to each other:
Code:
local UlsterID = GameInfoTypes["CIVILIZATION_ULSTER"]
local domainSea = GameInfoTypes["DOMAIN_SEA"]
Code:
local UlsterID = GameInfoTypes.CIVILIZATION_ULSTER
local domainSea = GameInfoTypes.DOMAIN_SEA
 
Top Bottom