1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. Photobucket has changed its policy concerning hotlinking images and now requires an account with a $399.00 annual fee to allow hotlink. More information is available at: this link.
    Dismiss Notice
  3. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  4. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  5. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  6. Dismiss Notice
  7. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Lua Objects

Discussion in 'Civ6 - Modding Tutorials & Reference' started by Gedemon, Oct 23, 2016.

  1. vectorplexus

    vectorplexus Chieftain

    Joined:
    May 11, 2017
    Messages:
    13
    Gender:
    Male
    Not sure if this is the right place to ask this, but here it goes...

    I'm trying to create a simple script to allow me to change the LeaderNameType while in game. For now I'm just testing stuff around, but my aim will be to use it to make leaders that will change their look as the Eras go by. I know this will probably break Leader specific achievements, but I cant see any other way I could change this, unlesss I can tap directly into the XMLs that specify the Leader art/BLP this is what I have so far. Using a turn event for now, aswell as normal Leader Types, just to test things out:

    Code:
    function OnPlayerTurnActivated(ePlayer:number, bFirstTimeThisTurn:boolean)
        local pPlayer = Players[ ePlayer ];
        local pPlayerConfig :table = PlayerConfigurations[ePlayer];
    
        if (pPlayer:IsAlive() == true and pPlayer:IsMajor() == true) then
            print("PlayerTurnActivated ", ePlayer, pPlayer, pPlayerConfig:GetLeaderTypeName());
            if (pPlayerConfig:GetLeaderTypeName() == "LEADER_GILGAMESH") then
                -- pPlayer:SetLeaderTypeName("LEADER_CLEOPATRA");
                -- pPlayerConfig:SetLeaderTypeName("LEADER_CLEOPATRA");
                -- PlayerConfigurations[pPlayer]:SetLeaderTypeName("LEADER_CLEOPATRA");
                -- PlayerConfigurations[ePlayer]:SetLeaderTypeName("LEADER_CLEOPATRA");
            end
        end
    end
    
    Events.PlayerTurnActivated.Add(OnPlayerTurnActivated)
    
    The commented lines are things I tried, but I always get this error:
    function expected instead of nil
    stack traceback:
    EraTracker.lua:22: in function 'OnPlayerTurnActivated'
    [C]: in function 'func'
    [C]: in function '(anonymous)'

    Not even sure if what I'm trying to achieve is possible, I wanted to go with the feature that there was on CIV: BE, which made leaders change the looks while their affinities progressed.
     
  2. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    7,108
    Location:
    France
    How's your Lua file loaded in your mod ?

    SetLeaderTypeName is available in UI contexts, not script.
     
  3. vectorplexus

    vectorplexus Chieftain

    Joined:
    May 11, 2017
    Messages:
    13
    Gender:
    Male
    Ah maybe thats it then, I dont know what I'm doing... I usually compare myself to scripting, as a monkey on the Monkey Theorem... eventually I get to do something close to Shakespear! xD

    Should I load it as AddUserInterface then?

    (Thanks for your awesome quick reply btw!)

    EDIT: Well, that didnt worked, after hitting Start Game, it "boots" me back again to the main menu =S
     
    Last edited: Jun 9, 2017
  4. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    7,108
    Location:
    France
    AddUserInterface, yes, what's in your modinfo ?
     
  5. vectorplexus

    vectorplexus Chieftain

    Joined:
    May 11, 2017
    Messages:
    13
    Gender:
    Male
    it was as Gameplay Script. But when I do with AddUserInterface, cant even start a game

    EDIT: I fixed the issue of not being able to load it by adding the property <Context>InGame</Context>

    But, the script is not running at all either, I have a simple print, and not even that is being output. I figured that part because I was looking for a mod called Current Time of Day, which also has a XML, which I dont quite get what is it for, but I'm sure I'm missing a XML to somehow "append" the script?

    EDIT 2:
    Got it working, although not sure if the XML file is properly done...

    Code:
    <GameData>
        <AlphaAnim ID="EraTracker" Cycle="Once" Speed="10" />
    </GameData>
    If you could explain me better whats happening here (I like to understand what I'm doing) I'd be appreciated ofc! But its working now. When I go to the diplomacy screen, I now get Cleopatra instead of Gilgamesh. Now all I have to do is create "fake" leaders/BLPs to have them change through the eras =D
     
    Last edited: Jun 9, 2017
  6. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    5,140
    Location:
    Illinois, USA
    This final argument appears to be a delay value
    • If I change the iDelay variable I am using to the player ID # I sometimes miss the message for the human player, and the AI player messages get more and more delayed the higher the player ID# as these successive players found their capital city.
    • However, it seems to need the previous message to have "scrolled up" for that plot before the timer starts. So for settings of '0' the second message will be instantaneous more or less but only as soon as message #1 has cleared.
    Code:
    function CityFoundedCreateMessage(iPlayer, iCityID)
        local pCities = Players[iPlayer]:GetCities();
        local pCity = pCities:FindID(iCityID)
        local iCityX, iCityY, iDelay = pCity:GetX(), pCity:GetY(), 0
        local sMessage = "Player City Founded for Player " ..  PlayerConfigurations[iPlayer]:GetCivilizationTypeName() .. " at X" .. iCityX .. ", Y" .. iCityY
        if (iPlayer ~= 0) then
            iCityX, iCityY = Players[0]:GetStartingPlot():GetX(), Players[0]:GetStartingPlot():GetY()
        else
            iDelay = 2
        end
        Game.AddWorldViewText(0, sMessage, iCityX, iCityY, iDelay)
    end
    Events.CityInitialized.Add(CityFoundedCreateMessage)
     
    Gedemon likes this.
  7. DemonEmperor

    DemonEmperor Chieftain

    Joined:
    Jan 17, 2017
    Messages:
    27
    @Gedemon So is there actually a way to get the arguments for the built in lua functions, or do we have to make educated guesses?
     
  8. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    7,108
    Location:
    France
    if there is no example of use in the game's lua files, yes, educated guesses.
     
  9. zhadingping

    zhadingping Chieftain

    Joined:
    Nov 28, 2016
    Messages:
    3
    In Civ5 lua mod, a notification can be sent like this:

    iPlayer:AddNotification(NotificationTypes.NOTIFICATION_WONDER_BEATEN, msg, tip, iCity:GetX(), iCity:GetY(), iPlayer );

    So, in CIV6 lua mod, how to implement this functionality?
     
    Last edited: Aug 1, 2017
  10. DemonEmperor

    DemonEmperor Chieftain

    Joined:
    Jan 17, 2017
    Messages:
    27
    So where are these lua files? So far I've been making do by cannibalizing other mod creators' lua code. Also, do you know where I can find tutorials on how to use FireTuner? No Idea how to use the lua console - GameCore give me errors whenever I try to access stuff (while a game is loaded and stationary in the background)
     

Share This Page