Evening chaps,
Been working on a small thing for my addon, want to to roll out an update for it now but I've ran into a small problem:
I use a SetModel() function inside a hook, like this:
if attacker:GetNWInt('RepAmount') <= PlayerManager.RepBanditSkinRep then
timer.Create("RepSetSkinDelay", 0.5, 1, function()
attacker:SetModel(PlayerManager.RepBanditSkinPath)
end)
end
However, I want it to remember/save the last playermodel the player had before it got changed. I tried to use a local variable that does GetModel() however, it doesn't work as it saves the current PM (In this case the RepBanditPath.). Any help? I'm honestly very confused (And to be fair very tired today.) so I can't figure out whats going on. Any help would be appreciated!
if the GetModel() function works correctly inside the hook, just create a variable outside of the hook, and reassign it in the hook?
Thats the exact thing I tried, doesn’t work. Tried it outside of the hook, tried it inside another hook.
make some print statements to see the content of the variable at each state. print it at the first assignment, print it inside the hook before it changes the variable and after it changes it, and print it again outside of the hook after the hook ran
Will try that tomorrow. Will report back at ya once I can. Thanks for that!
Alright, so here is what I tried:
Setting a local variable to use GetModel() inside a PlayerSpawn hook. Printed out correctly, didn't work later inside the other hook. (Printed nil, obviously.)
Printing inside the hook that I want it to work (OnNPCKilled). Worked but only for the skin that got set.
Printing BEFORE it set the skin, like this:
local RepPlayerCurrentModel = attacker:GetModel() //Here
print(RepPlayerCurrentModel)
if PlayerManager.RepEnableBanditSkin == true then
if attacker:GetNWInt('RepAmount') <= PlayerManager.RepBanditSkinRep then
timer.Create("RepSetSkinDelay", 0.5, 1, function()
attacker:SetModel(PlayerManager.RepBanditSkinPath)
end)
end
if attacker:GetNWInt('RepAmount') == 0 then
print(RepPlayerCurrentModel)
attacker:SetModel(RepPlayerCurrentModel)
end
end
Sadly, didn't work either.
Isn't that because you set the local inside one hook and printing it in another one?
your not showing the part where you create hooks or end them...
but from what I see you create the variables INSIDE some hooks. Thats not what i ment. you have to define a varibale outside of any hook, and reassign it values inside the hook
local variableidk = nil
hook.Add("Hooknameidk", "idkstill", function()
variableidk = GetModel()
end)
Whoops yeah sorry about that, but I’ll try this now. Could work.
Make sure that your if statements work as they should
little basic tip: doing this, you are checking if true == true.
If you just have a variable, or function that is true, you just gave to do
if variable then
since the variable is true, the if statement is true. If you do "if variable == true then", you simply as if true is true. or if false is true. which is just useless. It doesnt have much impact on performance or anything, but its useless
They work right from my testing. Using GetModel() in another hook errors out and shows that it WANTS to change the model but cant cause its nil.
Sorry, you need to Log In to post a reply to this thread.