Displaying an Image Upon Event Trigger

AoxynCi

Chieftain
Joined
Dec 16, 2024
Messages
2
Hello!
I’m interested in creating mods for Civilization 6 and have been studying a lot about it. As a learning exercise with Lua scripting, I’m trying to make a mod that displays a 2D image on the map for a certain amount of time when a city is captured or founded.

I’ve managed to capture the events, but I’m struggling to get the image to display.

Could someone guide me on how to write the necessary script?

Initially, I planned to base it on the EventPopup system, but I found it too difficult for me to handle.

Thank you in advance for your help!
 
I am currently testing with the following very simple code, but it doesn't work.

sampleimage.xml
XML:
<?xml version="1.0" encoding="utf-8"?>
<Context>

    <Container ID="SampleMainContainer" Size="parent,parent" Offset="0,70" Anchor="C,T">
        <Image ID="SampleImage" Size="800,600" Anchor="C,T" />
    </Container>

</Context>

sampleimage.lua
Code:
function CityWasConquered(VictorID, LoserID, CityID, iCityX, iCityY)

    local pPlayer = Players[VictorID]
    
    local pCity = pPlayer:GetCities():FindID(CityID)
    
    local sCity_LOC = pCity:GetName()
    
    print("Player # " .. VictorID .. " : captured the city of " .. Locale.Lookup(sCity_LOC))
    print("Player # " .. LoserID .. " lost the city")
    print("The city is located at (or used to be located at) grid X" .. iCityX .. ", Y" .. iCityY)

    Controls.SampleImage:SetTexture("image_01.dds")
end

GameEvents.CityConquered.Add(CityWasConquered)


sample.modinfo
XML:
<?xml version="1.0" encoding="utf-8"?>
<Mod id="ead739bd-c7f5-4ed9-bb63-24786cc3bf3a" version="1">
  <Properties>
    <Name>ImageSampleMOD</Name>
    <Description>This is a brief description of the mod.</Description>
    <Created>1735088464</Created>
    <Teaser>This is a brief description of the mod.</Teaser>
    <Authors>xxxxx</Authors>
    <CompatibleVersions>1.2,2.0</CompatibleVersions>
  </Properties>
  <Dependencies>
    <Mod id="4873ebxx-dccc-4574-b784-dda455e74e68" title="Expansion: Gathering Storm" />
  </Dependencies>
  <Components>
    <AddUserInterfaces id="sample_ui">
        <Properties>
            <Context>InGame</Context>
        </Properties>
        <File>sampleimage.xml</File>
    </AddUserInterfaces>
    <AddGameplayScripts id="sample_event">
      <File>sampleimage.lua</File>
    </AddGameplayScripts>
    <ImportFiles id="sample_images">
      <File>image_01.dds</File>
    </ImportFiles>
  </Components>
  <Files>
    <File>sampleimage.lua</File>
    <File>sampleimage.xml</File>
    <File>image_01.dds</File>
  </Files>
</Mod>

The following error message is displayed in the lua.log.
> sampleimage.lua:20: attempt to index a nil value
 
Top Bottom