Jump to content

Boat Badge


Recommended Posts



Hi everyone !


As you know, when hopping on a boat, a widget is created containing the boat's equip slots, item slots, and the boat badge (health). What I'm looking to do, is change the position of the badge alone. There's a common function for all the boats, called "setupcontainer", coontaining the default position for it, which is changed depending on the type of boat the game generates the widget for.


I wanna change "widgetboatbadgepos" from modmain.lua but I'm lacking the technical knowledge to do so. Any help would be greatly appreciated.


The file is "boat.lua" in the prefabs folder and here's the function

local function setupcontainer(inst, slots, bank, build, inspectslots, inspectbank, inspectbuild, inspectboatbadgepos, inspectboatequiproot)inst:AddComponent("container")inst.components.container:SetNumSlots(#slots)inst.components.container.type = "boat"inst.components.container.side_align_tip = -500inst.components.container.canbeopened = false inst.components.container.widgetslotpos = slotsinst.components.container.widgetanimbank = bankinst.components.container.widgetanimbuild = buildinst.components.container.widgetboatbadgepos = Vector3(0, 40, 0)inst.components.container.widgetequipslotroot = Vector3(-80, 40, 0)  local boatwidgetinfo = {}boatwidgetinfo.widgetslotpos = inspectslotsboatwidgetinfo.widgetanimbank = inspectbankboatwidgetinfo.widgetanimbuild = inspectbuildboatwidgetinfo.widgetboatbadgepos = inspectboatbadgeposboatwidgetinfo.widgetpos = Vector3(200, 0, 0)boatwidgetinfo.widgetequipslotroot = inspectboatequiprootinst.components.container.boatwidgetinfo = boatwidgetinfoend
Link to comment
Share on other sites

@kiopho, the boat badge information is actually stored and located in widgets/containerwidget.lua. It specifically gets set in ContainerWidget:Open Line 141, when container.components.container.type is equal to "boat".


I'd do something like this in order to change the location of the badge, so every time the container is opened it will automatically be reset back to the position you want.

AddClassPostconstruct( "widgets/containerwidget", function( self )    local _ContainerOpen = self.ContainerOpen    self.ContainerOpen = function(self, container, doer, boatwidget)        _ContainerOpen(self, container, doer, boatwidget)        local X = 150        local Y = 150        self.boatbadge:SetPosition( X, Y )        endend)
Link to comment
Share on other sites

@Kzisor Thanks for the lightning fast answer ! I feel a little bit embarrassed because I was doing that exact thing but I wrote an "inst" instead of a "self" in the function.


I read it times and times without noticing. I ended up thinking it wasn't the right way to do it. Thanks to you I was able to see it. I guess I should take a step back and get on the mods tomorrow :s
Thank you buddy, and have a nice one.
Cheers !


PS : here's my silly mistake

local function BoatBadgeFix(inst) local oldOpen = self.Open function self:Open(container, doer, boatwidget) oldOpen(self, container, doer, boatwidget) self.boatbadge:SetPosition(100, 40, 0) end end AddClassPostConstruct("widgets/containerwidget", BoatBadgeFix)
Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

  • Create New...