noobitomignon Posted December 14, 2015 Share Posted December 14, 2015 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 More sharing options...
noobitomignon Posted December 15, 2015 Author Share Posted December 15, 2015 I'm bumping this. No one to help pls ? Link to comment Share on other sites More sharing options...
Rincevvind Posted December 15, 2015 Share Posted December 15, 2015 you didn't posted your error, but let me turn on my Vanga mode and say:i guess it's here, this one is not existself.boatwidget.prefab why do you think that interface element have prefab too? Link to comment Share on other sites More sharing options...
noobitomignon Posted December 15, 2015 Author Share Posted December 15, 2015 @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 Link to comment Share on other sites More sharing options...
noobitomignon Posted December 15, 2015 Author Share Posted December 15, 2015 Or rather what boat prefab is used to create the container displayed in boatwidget. Link to comment Share on other sites More sharing options...
kiopho Posted December 15, 2015 Share Posted December 15, 2015 I'm working on that exact thing. It's better to do it from modmain.lua like solocal 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 More sharing options...
kiopho Posted December 15, 2015 Share Posted December 15, 2015 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 boatif self.container == GLOBAL.GetPlayer().components.driver.vehicle then Link to comment Share on other sites More sharing options...
noobitomignon Posted December 15, 2015 Author Share Posted December 15, 2015 It works Thanks a lot @kiopho and thanks Rincevvind for giving it a shot Link to comment Share on other sites More sharing options...
kiopho Posted December 15, 2015 Share Posted December 15, 2015 You're welcome. Link to comment Share on other sites More sharing options...
Recommended Posts
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.