• How to know if a function was called within a hook
    3 replies, posted
My latest addon was a success and people liked it. I am close to getting the "MegaUpload" achievement. But with this came a lot of bug reports. I am glad that there is only 1 bug that I need to fix. So some time ago I discovered that when you set a player model it doesn't always call the PlayerSetModel hook, so I rewrote the SetModel function to make sure it always calls it. But in DarkRP they have it so PlayerSetModel calls for SetModel, leading to a loop that causes massive lag spikes. Only fix I think that should work is to make sure the function SetModel calls the PlayerSetModel hook only when it wasn't called from within the hook itself. But how?! Here's how I have it set up right now: local mEnt = FindMetaTable("Entity") mEnt.NewSetModel = mEnt.NewSetModel || mEnt.SetModel function mEnt:SetModel(model) self.NewSetModel(self, model) if(self:IsPlayer()) then hook.Run("PlayerSetModel", self) end end
My suggestion would be to make your own hook and call it something like "PlayerModelChanged". The PlayerSetModel hook is called from PlayerSpawn and it's meant to be a place where you set the playermodel, it's not supposed to be called on model change. local mEnt = FindMetaTable("Entity") mEnt.NewSetModel = mEnt.NewSetModel || mEnt.SetModel function mEnt:SetModel(model) self.NewSetModel(self, model) if(self:IsPlayer()) then hook.Run("PlayerModelChanged", self) end end And then wherever you hook.Add, replace PlayerSetModel by PlayerModelChanged
You ever have those times where you think of a problem so much that you overlook the easiest way to fix it? ...
I've just had a problem where I spent 3 hours trying to get the center of a model, even though I was aware I could get bounds by doing ent:GetModelBounds(), so yeah, I know how you feel.
Sorry, you need to Log In to post a reply to this thread.