[Lua] Troller0001's stupid questions that may actually not be that stupid

Troller0001

I've anxiously awaited your arrival!
Joined
Mar 9, 2016
Messages
755
Location
The Netherlands
Since I'm asking many questions, mainly regarding Lua, I've decided to start a seperate thread specifically dedicated to answering my 'stupid questions that may actually be not that stupid'. ;) Before you start ripping your hair out on these (stupid) questions, I would first like to thank you for taking your time reading this, as well helping the community by answering some of these questions!

So well, here's the first question, regarding the Player.AddNotification(...).
So I used this piece of text from the Modwiki:
Spoiler :
NOTIFICATION_WONDER_COMPLETED
Icon: Wonder icon with optional overlaid small civ icon
Sound: No Description Available
Left-Click: Zoom to plot
Extra Parameter 1: Building ID for wonder
Extra Parameter 2: Player ID; if this is -1, the overlaid civ icon does not appear

NOTIFICATION_WONDER_BEATEN
Icon: Wonder icon with optional overlaid small civ icon
Sound: No Description Available
Left-Click: Zoom to plot
Extra Parameter 1: Building ID for wonder
Extra Parameter 2: Player ID; if this is -1, the overlaid civ icon does not appear
As well as this (also from the Modwiki)
Spoiler :
Player:AddNotification(NotificationType notificationType, string description, string title, int x = -1, int y = -1, PlayerID extra1 = -1, int extra2 = -1)

Now, I used this Lua code with PlayerDoTurn (from another file) (I also set it to InGameUIAddin):
Spoiler :
Code:
-- MonGrandPrix
-- Author: Troller0001
-- DateCreated: 4/10/2016 12:23:16 PM
--------------------------------------------------------------

--function that checks if WLTKD is active, and then activates the grand prix if it is
local iGrandPrix = GameInfoTypes.BUILDING_MON_GRAND_PRIX
local iMon_ID = GameInfoTypes.CIVILIZATION_MOROCCO --will be monaco once the civ is added in the game


function MonGrandPrix(iPlayer)
	local pPlayer = Players[iPlayer]
	
	if(pPlayer:GetCivilizationType() == iMon_ID)then
		for pCity in pPlayer:Cities() do
			if(pCity:GetWeLoveTheKingDayCounter() > 0) then
				if(not pCity:IsHasBuilding(iGrandPrix))then--if the grand prix isn't already active, add a notification
					if pPlayer:IsHuman() then
						local description = ("Since 'We Love the King Day' is active, the citizens of "..pCity:GetName().." have organized a Grand Prix in their city, increasing Great People Generation by 15%")
						local descriptionShort = ("A Grand Prix has been organized")
						Players[Game.GetActivePlayer()]:AddNotification(NotificationTypes["NOTIFICATION_WONDER_BEATEN"], description, descriptionShort, pCity:GetX(), pCity:GetY(),iGrandPrix,GameInfoTypes.CIVILIZATION_MOROCCO)
					end
				end
				pCity:SetNumRealBuilding(iGrandPrix, 1)
			else
				pCity:SetNumRealBuilding(iGrandPrix, 0)
			end
		end
	end
end
The thing is, everything works perfectly, apart from the notification. The Hagia Sophia Icon always shows up, as well as the overlay 'unknown civ' icon... The text however, does appear correct...
Is there something really obvious I'm missing?

Completely other question, would it be possible to add a custom sound to a notification as well, or would that require digging in the C++ code?

-Troller0001
 
"Player ID" refers to the in-game ID of the player, not their civilization type, so instead of GameInfoTypes.CIVILIZATION_MOROCCO for Extra Parameter 2 you'd use Game.GetActivePlayer(). Also, have you double-checked that BUILDING_MON_GRAND_PRIX is the name of your building?
 
@Klisz, ah, I'll test the 2nd parameter tomorrow. As for the building, yes that's the exact name. Not only that, but it's even built/set within the same code, so surely that can't be the problem. :)
Code:
pCity:SetNumRealBuilding(iGrandPrix, 1)
Perhaps it doesn't work because it's not a wonder?
 
I think you're missing a parameter:

Player:AddNotification(NotificationType notificationType, string description, string title, int x = -1, int y = -1, PlayerID extra1 = -1, int extra2 = -1)

Players[Game.GetActivePlayer()]:AddNotification(NotificationTypes["NOTIFICATION_WONDER_BEATEN"], description, descriptionShort, pCity:GetX(), pCity:GetY(),iGrandPrix,GameInfoTypes.CIVILIZATION_MOROCCO)

if I'm understanding the parameters correctly (and no guarantees of that :mischief:) the reason you're getting the wrong icon is that it's matching to the wrong parameter.
 
PlayerID in the description refers to the first flag (although the description is wrong, as that flag is the id of the building, the second being the ID of the player).
I think Klisz solved the issue.

The Modwiki tricked me... :mad:
I'll test the thing today/tomorrow and will upload the result here! Thank you all for your replies! :)
 
The Modwiki tricked me

It frequently does that. Don't forget that the best reference for the Civ 5 Lua methods are the game core Lua files. Just get yourself a good file search tool and look for examples in the actual UI and Scenario code
 
Just get yourself a good file search tool and look for examples in the actual UI and Scenario code
Anything you would recommend? :)
 
@whoward69, Wow, that tool is amazing! Thanks W! :D
EDIT: woops, didn't see your post bane_... Anyway, thanks for the suggestion, I'll see which tool fits me better ;)
 
I started using Ransack based on Williams' recommendation a couple of years ago, and it has saved me a lot of time in trouble-shooting conflict issues as well as finding where info is at in the multiplex of scattered Firaxis base-game code fragments.

It doesn't really matter what you use just so long as you have something to use when you cannot figure out which file something is in, whether it be Firaxis code, or a mod that is in conflict. Though if you have a lot of mods in your MODS folder, like I do, it can take a while to search through all those for the offending code-bit you are looking for.
 
Hint: Agent Ransack caches the directory info - which makes a second search over the same files a lot faster then the first - so don't close it after every search!

Hint 2: If you know what you're looking for is in the core database files, just search those files matching "civ5*.xml", and if it's a TXT_KEY, just search "civ5gametext*.xml"

The other thing I like about Agent Ransack is that it uses the same regexp parser as Notepad++ - so you can copy the regexp from one to the other
 
Hint: Agent Ransack caches the directory info - which makes a second search over the same files a lot faster then the first - so don't close it after every search!
Ah, good to know! Thanks :)

Hint 2: If you know what you're looking for is in the core database files, just search those files matching "civ5*.xml", and if it's a TXT_KEY, just search "civ5gametext*.xml"
Yeah, I really like that functionality, saved me a lot of time when trying to search through the Lua files!

P.s. I like your updated profile pic whoward ;)

@LeeS Yeah, pre-william's recommendation I used windows 7's standard search tool... :blush::mischief: Not only did it take a really long time to search, but it also skipped over some (quite important) files! Thank god I asked for a recommendation.... :goodjob:

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

Anyway, I used Agent Ransack to try and search for either the specification(? (can't figure out the exact word right now...)) of 'AddNotification', or for the use of the function. However, it appeared that Firaxis only used the NOTIFICATION_GENERIC with the AddNotification function (within the dlc scenarios). I guess that would mean that the others (such as NOTIFICATION_WONDER_BEATEN) are used/specified(?) within the C++ code, wouldn't they? However, I guess I'll fiddle around with the AddNotification function (NOTIFICATION_WONDER_BEATEN and its exact parameters) once I've got some more spare time ;)

Also, since this question got hidden by all the previous replies (thanks for those btw :D), here's it again: Is it possible to add a custom sound to a notification? (NOTE: I saw there was an xml-file which contained notification-sound tags, could I add stuff to that or is it unused such as the 'Welcomeness'-tag from another notification xml-file? If it is possible to add sounds, how do I do it?
 
Anyway, I used Agent Ransack to try and search for either the specification(? (can't figure out the exact word right now...)) of 'AddNotification', or for the use of the function. However, it appeared that Firaxis only used the NOTIFICATION_GENERIC with the AddNotification function (within the dlc scenarios). I guess that would mean that the others (such as NOTIFICATION_WONDER_BEATEN) are used/specified(?) within the C++ code, wouldn't they?

If you can't find where it's called from, try looking for where the call ends up.

Searching "*.lua" for "WONDER_BEATEN" brings you to NotificationPanel.lua and this code
Code:
or type == NotificationTypes.NOTIFICATION_WONDER_BEATEN then
	if iGameValue ~= -1 then
		local portraitIndex = GameInfo.Buildings[iGameValue].PortraitIndex;
		if portraitIndex ~= -1 then
			IconHookup( portraitIndex, 80, GameInfo.Buildings[iGameValue].IconAtlas, instance.WonderConstructedAlphaAnim );				
		end
	end
	if iExtraGameData ~= -1 then
		CivIconHookup( iExtraGameData, 45, instance.CivIcon, instance.CivIconBG, instance.CivIconShadow, false, true );
		instance.WonderSmallCivFrame:SetHide(false);				
	else
		CivIconHookup( 22, 45, instance.CivIcon, instance.CivIconBG, instance.CivIconShadow, false, true );
		instance.WonderSmallCivFrame:SetHide(true);				
	end
which tells you exactly how the parameters are used
 
@whoward69, yes, I found that part as well, but doesn't that code specify the OnNotificationAdded event? (also, there's an id-argument here, which isn't in AddNotification)
Code:
-------snipped------
function OnNotificationAdded( Id, type, toolTip, strSummary, iGameValue, iExtraGameData, ePlayer )
--------snipped--------

I think I'm understanding this wrong...
 
pPlayer:AddNotification(...) calls into the DLL which does some stuff and then calls the NotificationAdded GameEvent to get the UI to actually display the notification "finger"

The important part is the use of NOTIFICATION_WONDER_BEATEN as this ties every thing together.

SOME of the values you pass into the Lua API method (summary, message, etc) end up in the event. iX and iY do not (they are used internally - which is a right PITA if you want them in the event handler), while what are labelled extra1 and extra2 in post #4 arrive as iGameValue and iExtraGameData - so you can work out what those two parameters are used for (if anything) by each of the notification types

Id is a sequential identifier the DLL uses to keep track of notifications for players (it's how it knows, for example, which one you cancelled when you right click on them)
 
@whoward69, Mind Blown. So that's how all of that links together! Thanks a lot man! :D Where would I be without this forum? (I was going to say 'without you', but that would sound a bit over-attached/creepy/romantic wouldn't it? :p)
 
So I've been fiddling around with the NOTIFICATION_WONDER_BEATEN and this is the weird stuff I found out:
Code:
Players[Game.GetActivePlayer()]:AddNotification(NotificationTypes["NOTIFICATION_WONDER_BEATEN"], description, descriptionShort, pCity:GetX(), pCity:GetY(),GameInfoTypes.BUILDING_AIRPORT,Game.GetActivePlayer())
This always makes the Hagia Sophia building icon show up, where BUILDING_AIRPORT can be any (modded or unmodded) non-wonder-building.

Code:
Players[Game.GetActivePlayer()]:AddNotification(NotificationTypes["NOTIFICATION_WONDER_BEATEN"], description, descriptionShort, pCity:GetX(), pCity:GetY(),GameInfoTypes.BUILDING_UFFIZI,Game.GetActivePlayer())
This always makes the wonder icon show up, where BUILDING_UFFIZI can be any unmodded wonder.

Code:
Players[Game.GetActivePlayer()]:AddNotification(NotificationTypes["NOTIFICATION_WONDER_BEATEN"], description, descriptionShort, pCity:GetX(), pCity:GetY(),GameInfoTypes.BUILDING_MODDED_WONDER,Game.GetActivePlayer())
This always makes the Hagia Sophia building icon show up, where BUILDING_MODDED_WONDER can be any modded wonder. (I've copied all the Uffizi building(class) stats to a building and tried displaying that. Still showed up as the Hagia Sophia)

I guess there must be something that prevents AddNotification with NOTIFICATION_WONDER_BEATEN to show the icon from a (modded) non-wonder building or a modded wonder. Can someone confirm?
I'm confused right now :confused:
 
Top Bottom