Jump to content

Recommended Posts

I want to extract the wait times from fishingrod.lua for other uses

    inst:AddComponent("fishingrod")
    inst.components.fishingrod:SetWaitTimes(4, 40)

 

I know that I have to add these function to fishingrod component so that I can extract the wait times. But I don't know how to add new function to / change existing components. Can anyone help? thanks

function FishingRod:GetMinWaitTimes()
    return self.minwaittime
end

function FishingRod:GetMaxWaitTimes()
    return self.maxwaittime
end

 

modmain.lua is where you need to do this

AddComponentPostInit("fishingrod", function(self)
	--adding a new fn
	function self:GetMaxWaitTimes()
		return self.maxwaittime
	end
	--overwriting an existing fn
	local oldSetWaitTimes = self.SetWaitTimes --self.<functionName>
	function self:SetWaitTimes(min, max)
        print("New Min: " .. min .. " | New Max: " .. max)--runs before old function
      	oldSetWaitTimes(self, min, max)--call the old function with the same parameters except adding self as the first parameter, since it is not being invoking via colon(:)
      	print("WaitTimes Changed")--runs after old function
  end
end)

BUT, if you want to just fetch those values without doing the above, you could also just do this where ever you need them

inst:AddComponent("fishingrod")
inst.components.fishingrod:SetWaitTimes(4, 40)

local minwait = inst.components.fishingrod.minwaittime--will be 4
local maxwait = inst.components.fishingrod.maxwaittime--will be 40

 

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