It works fine, I set all limitations to 1 and this is the result after 100000GF:
https://i.imgur.com/KVy7tZr.png
using those values:
Code:
-- AI is allowed to have max 1 brewery
enforceBuildingCount(1, BLD_BREWERY, 1, false)
-- AI is allowed to have max 1 metalworks
enforceBuildingCount(1, BLD_METALWORKS, 1, false)
-- AI is allowed to have max 2 forester
enforceBuildingCount(1, BLD_FORESTER, 1, false)
-- AI is allowed to have max 2 sawmills
enforceBuildingCount(1, BLD_SAWMILL, 1, false)
-- AI is allowed to have max 2 mills
enforceBuildingCount(1, BLD_MILL, 1, false)
-- AI is allowed to have max 2 bakeries
enforceBuildingCount(1, BLD_BAKERY, 1, false)
-- AI is allowed to have max 2 pigfarms
enforceBuildingCount(1, BLD_PIGFARM, 1, false)
-- AI is allowed to have max 2 slaughterhouses
enforceBuildingCount(1, BLD_SLAUGHTERHOUSE, 1, false)
-- AI is allowed to have max 4 woodcutters
enforceBuildingCount(1, BLD_WOODCUTTER, 1, false)
It looks like you did not use the file I uploaded but copied only some parts of it. Please either use the Script provided or copy all changes.
Zitat:
"attempt to call global" enforcebuildingcount' (a nil value)
bad format string
Tells exactly what is happening. You are trying to call the function "enforceBuildingCount" but it does not exist. The reason for that is that you did not copy the function at all. Have a look at the end of the file:
Code:
function enforceBuildingCount(player, building, limit, notify)
local sumBuildings = rttr:GetPlayer(player):GetNumBuildings(building) + rttr:GetPlayer(player):GetNumBuildingSites(building)
if (sumBuildings >= limit) then
rttr:GetPlayer(player):DisableBuilding(building)
else
rttr:GetPlayer(player):EnableBuilding(building, notify)
end
end
Thats the function which actually does limiting at all - you didn't copy it, thus the function does not exist, the script is not working at all and neither is the limiting. I personally use Notepad++ to compare files, that might help to catch all changes. But it's still the same as in the example script I provided here:
https://github.com/Spikeone/RttR_Campaigns/blob/master/OtherScripts/ExampleScript_04.LUA
As you can see it has the onGameFrame(gf) function and the enforceBuildingCount(player, building, limit, notify) function. You need both.
Zitat:
So it doesn't work exchanging (gf) with 0 also doesn't help
Well, I didn't say you should replace the gf with a 0 but the 1 with a 0.
From:
Code:
function onGameFrame(gf)
-- for AI 1
enforceBuildingCount(1, BLD_FORESTER, 1, false)
enforceBuildingCount(1, BLD_WOODCUTTER, 2, false)
enforceBuildingCount(1, BLD_SAWMILL, 2, false)
enforceBuildingCount(1, BLD_BREWERY, 1, false)
enforceBuildingCount(1, BLD_MILL, 2, false)
enforceBuildingCount(1, BLD_BAKERY, 2, false)
enforceBuildingCount(1, BLD_PIGFARM, 1, false)
enforceBuildingCount(1, BLD_SLAUGHTERHOUSE, 1, false)
enforceBuildingCount(1, BLD_IRONSMELTER, 2, false)
enforceBuildingCount(1, BLD_ARMORY, 2, false)
enforceBuildingCount(1, BLD_METALWORKS, 0, false)
enforceBuildingCount(1, BLD_MINT, 2, false)
enforceBuildingCount(1, BLD_SHIPYARD, 1, false)
end
To:
Code:
function onGameFrame(gf)
-- for Player 0 (the human player)
enforceBuildingCount(0, BLD_FORESTER, 1, false)
enforceBuildingCount(0, BLD_WOODCUTTER, 2, false)
enforceBuildingCount(0, BLD_SAWMILL, 2, false)
enforceBuildingCount(0, BLD_BREWERY, 1, false)
enforceBuildingCount(0, BLD_MILL, 2, false)
enforceBuildingCount(0, BLD_BAKERY, 2, false)
enforceBuildingCount(0, BLD_PIGFARM, 1, false)
enforceBuildingCount(0, BLD_SLAUGHTERHOUSE, 1, false)
enforceBuildingCount(0, BLD_IRONSMELTER, 2, false)
enforceBuildingCount(0, BLD_ARMORY, 2, false)
enforceBuildingCount(0, BLD_METALWORKS, 0, false)
enforceBuildingCount(0, BLD_MINT, 2, false)
enforceBuildingCount(0, BLD_SHIPYARD, 1, false)
end
Link to a tutorial about functions in LUA:
https://www.tutorialspoint.com/lua/lua_functions.htm reding this will help understanding what the code does and what my function is good for.
---
Editiert von
Spike am 14.04.2022 13:01