1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Are the following things possible via Lua?

Discussion in 'Civ6 - Creation & Customization' started by Angryr, Jul 24, 2018.

  1. Angryr

    Angryr Chieftain

    Joined:
    Jul 12, 2014
    Messages:
    39
    Gender:
    Male
    Location:
    Indiana, USA
    Hi, I've identified that I would need to be able to do the following things in order to achieve a mod I'd like to make.

    Just to be clear, I'm not trying to get anyone to do this for me. I would just like confirmation that these things are possible before I delve into accomplishing them as I'm not terribly familiar with the civilization lua environment.

    Things I'll need to be able to do via lua.
    1. Hook into events for Unit Promotions.
    2. Determine who owns the tile (if anyone) that a unit is on.
    3. Change who owns a unit (e.g. Convert a barbarian to another owner).
    4. Spawn a unit of a particular type.
    5. Give experience to a unit.
    6. Grant an envoy for a city-state to a player.
    7. Grant move points to a unit.
    I am open to other ways, but I highly suspect that the conditions under what I want to accomplish will be a problem via other methods. Any assistance is greatly appreciated!
     
  2. HorseshoeHermit

    HorseshoeHermit 20% accurate as usual, Morty

    Joined:
    Apr 5, 2013
    Messages:
    1,274
    Location:
    Canada
    The hard part is never something you do. It's detecting the condition where you want that thing to happen.
     
  3. Angryr

    Angryr Chieftain

    Joined:
    Jul 12, 2014
    Messages:
    39
    Gender:
    Male
    Location:
    Indiana, USA
    In my past experience the hard part was actually changing the game as there weren't any functions that I could find that set things only get. Could be that I just didn't find the right place to look though.

    The conditions I'm pretty sure should be simple as they're a mix of #1, #2, and the kill event for a unit. So as long as they two are possible conditions are covered.
     
  4. raen

    raen Coat of Arms

    Joined:
    May 12, 2003
    Messages:
    2,164
    Location:
    Portugal
    I have started mingling with civ 6 LUA and I think something like this could work (Not with right sintax):

    Unitpromoted event -> plot (x y):getowner -> (dont know about changing unit owner, maybe killing it and create a new one) -> player units Creat new unit -> unit Change Experience -> player change influence tokens to give -> units
    ChangeMovesRemaining ?

    Source:
    https://forums.civfanatics.com/threads/lua-objects.601146/
     
  5. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    6,334
    Location:
    Illinois, USA
    #3 will be problematic in that there are limited things we can do to an existing unit and when creating a new unit via lua. We cannot for example set the unit's promotion level (this is different from XP earned), and any XP we grant via lua beyond the amount needed for the unit's next promotion is wasted and does not seem to carry over to a next promotion-choice. We can give a unit correct promotions for it, but this does not automatically adjust a unit's "level", so you can create a unit via lua that has four promotions that are correct for it, but the unit would still be a Level 1 unit only needing the first 15XP to choose a promotion.

    That having been said we can create units that are "bare" of XP and promotions and extra unit abilities without any trouble, and we can kill existing units. Depending on what method you use to kill a unit, however, you can get oddball behaviors on the "NEXT TURN" / "Unit Needs Orders" part of the lower right-hand panel: you can get the "NEXT TURN" showing up when several or many units still need orders.

    #7 If you look at the "Managers" tab in the spreadsheet @raen provided the link to, there is a method to change a unit's moves. I've not used that method yet so I don't know what arguments UnitManager.ChangeMovesRemaining(args) requires.

    #1 There is a specific hook event made available to lua for a unit getting promoted: Events.UnitPromoted. I don't know what arguments are passed from the gamecore to any function subscribed to this event.
     
    raen likes this.
  6. raen

    raen Coat of Arms

    Joined:
    May 12, 2003
    Messages:
    2,164
    Location:
    Portugal
    #1 if Im not wrong the arguments are playerID and unitID

    Edited: #7 I dont know for sure but I believe it has the same arguments of #1, plus something else I dont know also.
     
    Last edited: Jul 26, 2018
  7. Angryr

    Angryr Chieftain

    Joined:
    Jul 12, 2014
    Messages:
    39
    Gender:
    Male
    Location:
    Indiana, USA
    Thanks, this have been incredibly informative.
    Ha, funny. The one I thought was going to be absolutely possible is the only one you guys say will be difficult :p

    I wasn't ecstatic about my idea for #3's use anyways so I suppose that forces me to come up with something better!
     
    raen likes this.
  8. luei333

    luei333 Warlord

    Joined:
    May 25, 2014
    Messages:
    185
    #6 I actually did myself in lua:

    Code:
    pToPlayer:GetInfluence():ChangeTokensToGive(1);
    Problem is, you can't, as far as I've found, give an extra influence token to a specific city state, only grant the player an extra one to assign.
     
  9. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    8,680
    Location:
    France
    not tested, but (where iPlayer is the CS player index)
    Code:
    pPlayer:GetInfluence():GiveFreeTokenToPlayer(iPlayer)
    ?
     

Share This Page