Jump to content

Recommended Posts

Managed how to read book, but how to get uses left if not mastersim ? Nothing in replica
 

local ImageButton = require "widgets/imagebutton"

local function Read(self)
	local items = self.container.replica.container:GetItems()
	local book = items[1]
	GLOBAL.ThePlayer.replica.inventory:UseItemFromInvTile(book)
end

AddClassPostConstruct("widgets/containerwidget", function(self)
	local oldopenfn = self.Open
	function self:Open(container, doer, ...)
		oldopenfn(self, container, doer, ...)
		-- local widget = container.replica.container:GetWidget()
		if doer and doer:HasTag("reader") then
			self.buttonx = self:AddChild(ImageButton("images/ui.xml", "button_small.tex", "button_small_over.tex", "button_small_disabled.tex", nil, nil, {1,1}, {0,0}))
			self.buttonx.image:SetScale(1.07)
			self.buttonx.text:SetPosition(2,-2)
			self.buttonx:SetPosition(-200, 0)
			self.buttonx:SetText("READ")
			self.buttonx:SetTextSize(33)
			self.buttonx.text:SetColour(0, 0, 0, 1)
			self.buttonx:SetOnClick(function()
				Read(self)
			end)
			self.buttonx:Show()
		end
	end
	
	local oldclosefn = self.Close
	function self:Close(...)
		if self.container and self.container.prefab:find("bookstation") then
			self.buttonx:Kill()
		end
		
		return oldclosefn(self, ...)
	end
end)

 

Edited by CanDoIt
forgot argument for Read function

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