[NFP] [RESOLVED] I would like to know the cost of that district when a district is added.

HKCiv

Chieftain
Joined
Mar 1, 2021
Messages
3
Before creating other mods, I would like to know the cost of the district's production when a district is added.

Code:
function OnDistrictAddedToMap( playerID:number, districtID:number, cityID:number, districtX:number, districtY:number, districtType:number, percentComplete:number )
    local city = CityManager.GetCity(playerID, cityID); -- collect
    local districtInfo = GameInfo.Districts[districtType]; -- collect
    local pBuildQueue = city:GetBuildQueue(); -- collect (not error)

    print( string.format("TARGET DISTRICT : %s", districtInfo.DistrictType) ); -- PRINT
    local cost = pBuildQueue:GetDistrictCost(districtInfo.Index); -- line 8, error

    print( string.format("COST : %d", cost) ); -- NOT PRINT
end


function Initialize()
Events.DistrictAddedToMap.Add( OnDistrictAddedToMap );
end

Initialize();


After applying this lua code, when I actually build the District, the log is as shown below.

Code:
...
My_Lua: TARGET DISTRICT : DISTRICT_CAMPUS
Runtime Error: "LUA_FILE_PATH":8: function expected instead of nil
stack traceback:"LUA_FILE_PATH":8: in function 'OnDistrictAddedToMap'
    [C]: in function 'func'
    [C]: in function '(anonymous)'

...


I understand that there is no GetDistrictCost function, but I couldn't find another alternative.

Any help on how to fix the error would be appreciated.
 
Ok, I found the right way to call that function.

Code:
    // as-is
    <AddGameplayScripts id="Script_Core">
        <Properties>
            <LoadOrder>19999</LoadOrder>
        </Properties>
      <File priority="19999">Script/Script.lua</File>
    </AddGameplayScripts>

    // to-be
    <AddUserInterfaces id="Script_Core">
        <Properties>
            <LoadOrder>20000</LoadOrder>
            <Context>InGame</Context>
        </Properties>
      <File priority="20000">Script/Script.lua</File>
      <File priority="20000">Script/Script.xml</File>
    </AddUserInterfaces>

By changing the tag for that lua file in modInfo I have confirmed that it is called normally.


But if I change it like this, some of the functions that worked before the change do not work.

(function like city:GetBuildQueue():FinishProgress())
 
Last edited:
Top Bottom