Jump to content

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
https://forums.kleientertainment.com/forums/topic/60765-help-with-prefab-check/
Share on other sites

@Rincevvind That's the error I get : prefab is a nil value. What I want is check what kind of boat prefab is used to create the widget. I'm guessing it's really easy but since I have 0 knowledge of programming, I don't know how to achieve that :(

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)
Edited by kiopho

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
Edited by kiopho

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...