Author Topic: Tying to understand mods  (Read 117 times)

gbrain

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    2
    • View Profile
on: August 27, 2019, 08:17:20 PM
Hi, new to modding and read a lot but still trying to figure out the following.

There is a nice little mod to show the resource on the main page but it relies on an existing script called MusicCoordinator.

https://github.com/rinart73/Resource-Display/blob/master/data/scripts/player/client/musiccoordinator.lua

So I am trying to work out how to make this type of mod not reliant on MusicCoordinator put a personal function/namespace.

Any guidance would be appreciated.

G.



Rinart73

  • Sr. Member
  • ****
  • Status:
    Offline
    Posts:
    345
  • Discord: Rinart73#7304
    • View Profile
on: August 28, 2019, 09:17:52 AM
Keep in mind that this mod will not be 100% clientside anymore.

data/scripts/player/init.lua
Code: [Select]
if onServer() then
    Player():addScriptOnce("data/scripts/player/ui/mymodname.lua")
end

data/scripts/player/ui/mymodname.lua
Code: [Select]
-- namespace MyModName
MyModName = {}

if onClient() then

function MyModName.initialize()
    if not GameSettings().infiniteResources then
        Player():registerCallback("onPreRenderHud", "onPreRenderHud")
    end
end

function MyModName.onPreRenderHud()
    local player = Player()
    if player.infiniteResources then return end

    local resources = {player:getResources()}
    local y = 10
    local material, rect
    for i = 1, #resources do
        material = Material(i-1)
        y = y + 18
        rect = Rect(5, y, 295, y + 16)
        drawTextRect(material.name, rect, -1, -1, material.color, 15, 0, 0, 2)
        drawTextRect(createMonetaryString(resources[i]), rect, 1, -1, material.color, 15, 0, 0, 2)
    end
    y = y + 18
    rect = Rect(5, y, 295, y + 16)
    local color = ColorRGB(1, 1, 1)
    drawTextRect("Credits"%_t, rect, -1, -1, color, 15, 0, 0, 2)
    drawTextRect(createMonetaryString(player.money), rect, 1, -1, color, 15, 0, 0, 2)
end

end



gbrain

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    2
    • View Profile
on: August 28, 2019, 07:18:50 PM

Hi, many thanks for the reply.

That makes perfect sense and gives me an understanding on the structure going forward.

G.