Jump to content

Help with prefab check.


Recommended Posts

Hi, I'm fairly new to modding and LUA in general and I'm having a problem checking for a prefab in inventory.lua.

I wanna customise the boatwidget depending on what type of boat is mounted.

So there's this line

 

if self.boatwidget then

   self.boatwidget:SetPosition(whatever)

end

 

I wanna add a check for what prefab is used to create boatwidget. Like so

 

if self.boatwidget and self.boatwidget.prefab = "armouredboat" then

   self.boatwidget:SetPosition(whatever)

end

 

But it crashes and I'm lost :(

 

Any help is appreciated as I'm a noobie. Thanks

Link to comment
Share on other sites

I'm working on that exact thing. It's better to do it from modmain.lua like so

local function BoatBadgeFix(self)     local oldOpen = self.Open        function self:Open(container, doer, boatwidget)         oldOpen(self, container, doer, boatwidget)         local boatwidget_pos = self:GetPosition()         if self.container == GLOBAL.GetPlayer().components.driver.vehicle then             if container.prefab == "cargoboat" then                self:SetPosition(boatwidget_pos.x + your_x_value1, boatwidget_pos.y1 + your_y_value, 0)            elseif container.prefab == "armouredboat" or container.prefab == "rowboat" then                self:SetPosition(boatwidget_pos.x + your_x_value2, boatwidget_pos.y2 + your_y_value, 0)            elseif container.prefab == "lograft" or container.prefab == "raft" then                self:SetPosition(boatwidget_pos.x + your_x_value3, boatwidget_pos.y3 + your_y_value, 0)            end        end    endend AddClassPostConstruct("widgets/containerwidget", BoatBadgeFix)
Link to comment
Share on other sites

Cargoboat is the one with slots.

Armouredboat and rowboat only have equip slots.

Raft and lograft don't have any slots.

 

You have to change "your_x_value" and "your_y_value" fof each one.

 

This line is to avoid modifying the widget's position when you're not on the boat

if self.container == GLOBAL.GetPlayer().components.driver.vehicle then
Link to comment
Share on other sites

Archived

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...