LUA exhaust unit

CivilizationAce

Warlord
Joined
Jan 17, 2017
Messages
240
I have added event consumption to my game that creates a new unit.

The problem is that I'd rather that the unit can't move until the next turn.

One reason for this is because of inconsistency — If the unit is created as the last move of the turn the turn ends without the player getting to move it (at least with auto-end-turn on). Otherwise the player does get to move it.

The other reason is about realism. My new unit is meant to require some training.

So does anyone know a way in LUA to exhaust a unit i.e. to get rid of its movement points for the turn?
 
IIRC there is a new function attached to UnitManager to do that, but I don't remember the syntax and it's not listed in the spreadsheet ATM.

I'll check tonight.
 
You have to try it out. I don't know the syntax, but I would try either (pUnit,iMoves) or (iUnitID,iMoves). Might even be that both versions could be supported. Also always first check if it is used by any Firaxis Lua script... Find in Files is the best feature of Notepad++ imho.
Edit. And you don't have to test in a mod, Lua console in FireTuner is best for that, you can see results immediately.
 
Find in Files is the best feature of Notepad++ imho
I have windows 10 index my .lua files (and every other text mod file extension, I can find) with text search. However, that feature of Notepad++ does look like it's more flexible :)
 
An example of it working:
Code:
pUnit = pPlayer:GetUnits():Create(iUnitIndex, iX, iY)
    print('pUnit:GetID(): '..pUnit:GetID())
    if UnitManager.ChangeMovesRemaining then
        print('UnitManager.ChangeMovesRemaining true')
    else
        print('UnitManager.ChangeMovesRemaining false')
        print(UnitManager.ChangeMovesRemaining)
    end
    print('pUnit:GetMovesRemaining: '..pUnit:GetMovesRemaining())
    UnitManager.ChangeMovesRemaining(pUnit,-(pUnit:GetMovesRemaining()))
Note that the first parameter of ChangeMovesRemaining is a unit object. The second is not what it's set to (in my first attempts I set this to zero, which did nothing without throwing an error), it's the amount it's changed by.

Thanks for all the help :)
 
it's the amount it's changed by.
This will be the standard behavior to expect from any function or method provided by Firaxis and which is called "ChangeSomething". The function will expect an integer argument that is sent as an amount to change the original value by. "SetSomething" functions or methods will expect an integer argument that is the new amount for "Something", disregarding any previous value. Any of these functions or methods may have more arguments required (as like in the one you are using) than just the integer value to implement.

So passing "0" as the integer value to a "ChangeSomething" function or method has no effect.
 
The function I was thinking of is UnitManager.FinishMoves(pUnit)

I've not tested it, I'm not sure that it does what I suppose.
 
Back
Top Bottom