Zegangani
King
- Joined
- Oct 9, 2020
- Messages
- 898
I'm currently working on a Mod that makes Units require multiple resources (for Costs and Maintenance, for example: Unit_A requires 10 Iron, 10 Coal and consumes 1 Niter, and 1 Coal per turn). To get this on a New Table: is not a big Deal. Make the Resources consumed by the Game (via Lua): can be done. But how to make the production panel Hide a Unit to not get produced if there is not enough resources available (the code to hide a unit/mark it as can not be produced)? I've searched all the lua files that have something to do with production in a City, but couldn't fegure it out. I've only found a luaObject that is maybe already defined: buildQueue:CanProduce( kBuildParameters, true ). I've tried to change it to false but I get a lua Error.
So Now I'm asking you Guys how I can accomplish this(What's the code for it)? Any Help is appreciated!
I also have another problem: when I try to add a lua funcion in order to match the UnitType from Units Table with the UnitType in my new Table, the UnitType from Units Table attempt to index a number value.
Here is the code:
I've no Clue how to solve this.
Edit: I used the Event: TurnBegin, because I didn't find any Event that coud fire when selecting the production panel or intering the citypanel.
So Now I'm asking you Guys how I can accomplish this(What's the code for it)? Any Help is appreciated!
I also have another problem: when I try to add a lua funcion in order to match the UnitType from Units Table with the UnitType in my new Table, the UnitType from Units Table attempt to index a number value.
Here is the code:
Code:
function RecourceAmountAvailable(unitReference)
if (GameInfo.Units_BonusesAndResourceCosts~= nil) then
for row in GameInfo.Units_BonusesAndResourceCosts() do
if (row.UnitType == unitReference.UnitType) then
local AdditionalStrategicResource = GameInfo.Resources[row.AdditionalStrategicResource];
if (AdditionalStrategicResource ~= nil) then
local AdditionalStrategicResourceCost = row.AdditionalStrategicResourceCost;
if (AdditionalStrategicResourceCost > 0) then
print("Unit Can Be Built");
return false ;
else
bCanProduce = buildQueue:CanProduce( row.Hash, false );
print("Unit Can not Be Built");
return true ;
end
end
end
end
end
end
Events.TurnBegin.Add( RecourceAmountAvailable );
I've no Clue how to solve this.
Edit: I used the Event: TurnBegin, because I didn't find any Event that coud fire when selecting the production panel or intering the citypanel.
Last edited: