Fix for pPlot:SetResourceType(-1)

whoward69

DLL Minion
Joined
May 30, 2011
Messages
8,727
Location
Near Portsmouth, UK
Anybody who's ever used pPlot:SetResourceType(-1) to remove a resource from a plot will know that while it works and the resource is removed, the resource icon for the plot remains.

To fix this
  1. Add an "Assets" folder to your mod, with a "UI" sub-folder, with an "InGame" sub-sub-folder (exclude the doube quotes but make sure you get the case correct!)
  2. Into the "Assets/UI/InGame" sub-folder, add the "ResourceIconManager.lua" file from the core game directory
  3. Set "Import into VFS" to true for this file
  4. Edit the file and add the following to the very end
    Code:
    -------------------------------------------------
    -------------------------------------------------
    function OnResourceRemoved(hexPosX, hexPosY)
      local iPlayerID = Game.GetActivePlayer()    
      if (g_PerPlayerResourceTables[iPlayerID] ~= nil) then
        local gridX, gridY  = ToGridFromHex(hexPosX, hexPosY)
        local index = IndexFromGrid(gridX, gridY)
    
        DestroyResource(index)
        
        for iPlayerID, playerResourceTable in pairs(g_PerPlayerResourceTables) do
          playerResourceTable[index] = nil
        end
      end
    end
    LuaEvents.SerialEventRawResourceIconDestroyed.Add(OnResourceRemoved)
    
    -------------------------------------------------
    -------------------------------------------------
    function ResetPlayerResources(iActivePlayer)
      for index, pResource in pairs(g_ActiveSet) do
        DestroyResource(index)
      end
    
      g_PerPlayerResourceTables[iActivePlayer] = nil
    end
    LuaEvents.RIM_ResetPlayerResources.Add(ResetPlayerResources)
  5. After your pPlot:SetResourceType(-1) add
    Code:
    pPlot:SetResourceType(-1)
    LuaEvents.SerialEventRawResourceIconDestroyed(iHexX, iHexY)
    (You can use the ToHexFromGrid() function to convert between plot co-ordinates and hex co-ordinates if necessary)

The LuaEvents.RIM_ResetPlayerResources(iPlayer) event can be used to remove all resource icons for a player, useful after hiding all hexes from the player, for example, if changing their start position.
 
I'm a bit ignorant on this because I have not tried disappearing/reappearing resources. But my understanding was that you can't get the 3D "landmark" graphic to disappear/reappear.

  1. Are you really talking about the landmark graphic here? (Or are you talking about strategic view "icon" or something else?)
  2. If yes, can you make a resource graphic appear as well as disappear?
 
Start up FireTuner and try it out for yourself then ;)

Resources - horses, cows, gems, iron, etc
The visual representation goes (in both the main and strategic views) - eg the cute foxes running around, but the resource icon in the main view remains (the circular graphic with the black arrow at the bottom right)

This fix removes the resource icon from the main map view
 
Back
Top Bottom