Are the following things possible via Lua?

Angryr

Chieftain
Joined
Jul 12, 2014
Messages
40
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!
 
The hard part is never something you do. It's detecting the condition where you want that thing to happen.
 
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.
 
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/
 
#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.
 
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!
 
#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.
 
not tested, but (where iPlayer is the CS player index)
Code:
pPlayer:GetInfluence():GiveFreeTokenToPlayer(iPlayer)
?
 
#7 You'll have two choices:
If you want to simply refresh the moves to full:
Code:
UnitManager.RestoreMovementToFormation(pUnit);
the argument is an object.
If you want to restore the attack too then add:
Code:
UnitManager.RestoreAttacks(pUnit);
the argument is an object.

If you want to give a specific amount of moves:
Code:
UnitManager.ChangeMovesRemaining(pUnit, moves);
the arguments are object and int. Not sure if it can grant moves over the unit's capacity.
 
Top Bottom