Lua help with floating text above cities

TheLunarArmy

Chieftain
Joined
Jul 9, 2014
Messages
59
Location
South-Africa
Hi guys,

I'm busy working on my first civ mod and got the Lua mechanics working perfectly, but now I want to get a little fancy and add some floating text pop-up whenever I found a new city.

Spoiler What the hell is he talking about? :

^This floating text :crazyeye:


The plan is whenever a Non- city is founded it gets +2 and +15 . It would be great if I get some text to go with it, but the for the life of me I cannot find the appropriate Lua references to do this.

Below I posted my working Lua code for the actual mechanics (free feel to try it out/use it) but now I just want to add my little fancy message that says something along the lines: "Universal Health Care: +2 , +15 ."

Thanks!

Code:
GameEvents.PlayerCityFounded.Add(
function (iPlayer, iCityX, iCityY)
	local pPlayer = Players[iPlayer];
	local pPlot = Map.GetPlot(iCityX, iCityY);
	local pCity = pPlot:GetPlotCity();
	local cPop = pCity:GetPopulation();
	local cFood = pCity:GetFood();

	if (pPlayer:IsAlive()) then
		if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_CANADA) then
			if ( pPlayer:GetNumCities() > 1 and not pCity:IsOriginalCapital() ) then
				pCity:SetPopulation(cPop + 2, true);
				pCity:SetFood(cFood + 15);
				-- TODO: Fancy little floating text message 
			end
		end
	end
end)
 
Funny, because it was first thing I asked about on forum.
Luckily for you, this thread will be actually answered. :)

Effect:


Code:
[COLOR="Red"]--This is important
include("FLuaVector.lua")
--[/COLOR]

GameEvents.PlayerCityFounded.Add(
function (iPlayer, iCityX, iCityY)
	local pPlayer = Players[iPlayer];
	local pPlot = Map.GetPlot(iCityX, iCityY);
	local pCity = pPlot:GetPlotCity();
	local cPop = pCity:GetPopulation();
	local cFood = pCity:GetFood();

	if (pPlayer:IsAlive()) then
		if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_CANADA) then
			if ( pPlayer:GetNumCities() > 1 and not pCity:IsOriginalCapital() ) then
				pCity:SetPopulation(cPop + 2, true);
				pCity:SetFood(cFood + 15);
				
[COLOR="Red"]--Here Check if Human
if iPlayer == Game.GetActivePlayer() then
	Events.AddPopupTextEvent(HexToWorld(ToHexFromGrid(Vector2(iCityX,iCityY))), "New [ICON_CITIZEN] Citizen", 0)
end
--[/COLOR]

			end
		end
	end
end)
 
Funny, because it was first thing I asked about on forum.
Luckily for you, this thread will be actually answered. :)

Effect:


Code:
[COLOR="Red"]--This is important
include("FLuaVector.lua")
--[/COLOR]

GameEvents.PlayerCityFounded.Add(
function (iPlayer, iCityX, iCityY)
	local pPlayer = Players[iPlayer];
	local pPlot = Map.GetPlot(iCityX, iCityY);
	local pCity = pPlot:GetPlotCity();
	local cPop = pCity:GetPopulation();
	local cFood = pCity:GetFood();

	if (pPlayer:IsAlive()) then
		if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_CANADA) then
			if ( pPlayer:GetNumCities() > 1 and not pCity:IsOriginalCapital() ) then
				pCity:SetPopulation(cPop + 2, true);
				pCity:SetFood(cFood + 15);
				
[COLOR="Red"]--Here Check if Human
if iPlayer == Game.GetActivePlayer() then
	Events.AddPopupTextEvent(HexToWorld(ToHexFromGrid(Vector2(iCityX,iCityY))), "New [ICON_CITIZEN] Citizen", 0)
end
--[/COLOR]

			end
		end
	end
end)

Perfect! Thanks.

/Thread.

edit: result:
 
Top Bottom