DarkXero Posted January 26, 2015 Share Posted January 26, 2015 AddComponentPostInit("workable", function(self) local old = self.WorkedBy function self:WorkedBy(worker, numworks) if worker.prefab == "wilson" then local a = 0 if worker.components.inventory then a = worker.components.inventory.equipslots.hands end local item = worker.activeitem or a if item then if item.prefab == "axe" or item.prefab == "pickaxe" or item.prefab == "shovel" then numworks = (numworks or 1) / 2 elseif item.prefab == "goldenaxe" or item.prefab == "goldenpickaxe" or item.prefab == "goldenshovel" then numworks = (numworks or 1) * 2 end end end old(self, worker, numworks) end end) Link to comment Share on other sites More sharing options...
DarkXero Posted January 26, 2015 Share Posted January 26, 2015 What rezecib meant with a lookup table looks kind of like this:local Normal = { axe = true, pickaxe = true, shovel = true}local Golden = { goldenaxe = true, goldenpickaxe = true, goldenshovel = true}AddComponentPostInit("tool", function(self) local old = self.GetEffectiveness function self:GetEffectiveness(action) if self.inst.components.inventoryitem and self.inst.components.inventoryitem.owner then if self.inst.components.inventoryitem.owner.prefab == "wilson" then local actual = self.actions[action] or 0 if Normal[self.inst.prefab] then actual = actual / 2 elseif Golden[self.inst.prefab] then actual = actual * 2 end return actual end end old(self, action) endend) Link to comment Share on other sites More sharing options...
FruityKinqz Posted January 26, 2015 Share Posted January 26, 2015 AddComponentPostInit("workable", function(self) local old = self.WorkedBy function self:WorkedBy(worker, numworks) if worker.prefab == "wilson" then local a = 0 if worker.components.inventory then a = worker.components.inventory.equipslots.hands end local item = worker.activeitem or a if item then if item.prefab == "axe" or item.prefab == "pickaxe" or item.prefab == "shovel" then numworks = (numworks or 1) / 2 elseif item.prefab == "goldenaxe" or item.prefab == "goldenpickaxe" or item.prefab == "goldenshovel" then numworks = (numworks or 1) * 2 end end end old(self, worker, numworks) endend) Heyy added this worked perfectly, Thank You! Link to comment Share on other sites More sharing options...
MarshallMabee Posted March 21, 2015 Share Posted March 21, 2015 Why not go by the good ol' AddComponentPostInit and modyfing the WorkedBy function?AddComponentPostInit("workable", function (Workable, inst) Workable.old_WorkedBy = Workable.WorkedBy function Workable:WorkedBy(worker, numworks) if worker.prefab == "mycharacter" and (Workable.action == GLOBAL.ACTIONS.CHOP or Workable.action == GLOBAL.ACTIONS.MINE) then numworks = numworks/2 or 0.5 end return Workable:old_WorkedBy(worker, numworks) endend)Also, that error is caused because you are using AddComponentPostInit inside a character's prefab file. All PostInit functions (and variations) should go inside modmain.Hey, i have a similar problem. I want my character to be able to just chop wood faster, not with every other tool. If you can give me a code similar to this, where do I place it? modmain? Link to comment Share on other sites More sharing options...
rezecib Posted March 21, 2015 Share Posted March 21, 2015 @MarshallMabee, In the modmain, yes, just use his code and remove the "or Workable.action == GLOBAL.ACTIONS.MINE" part. And obviously you need to change "mycharacter" to the name of your character. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now