How can I save variables and keep them applied after a perma-prop
5 replies, posted
I have this door that stays open for a certain amount of time that has to be defined by default at init to 3.
I want to be able to change this value while the entity still exists, and once I perma prop it, the number to stay the same.
The problem is that when I perma prop something, it refreshes it, re-initializing it, and setting that value back to 3, how can I make the variable from the not perma propped version apply to the version that has just been perma propped?
Maybe it is worth making the declaration of variable outside of initialization? To the variable is not overridden at initialization entity...
I see what you are saying, but how can I make the variable attached to the entity itself, while also not having to initialize the variable inside of the initialize function. I tried to make it only assign it in the ENT:AcceptInput function, but it still resets back to the default value, meaning it is deleting itself every time the entity is reloaded, I need a way to save it between "reloads" which is actually just a recreation of the entity from init
The value I want to save is self.TimerRunOut
function ENT:AcceptInput(input, activator, ply)
local takenWeapons =
if (IsValid(ply) and table.HasValue(takenWeapons,ply:GetActiveWeapon():GetClass())) then
if (self.TimerRunOut == nil) then
self.TimerRunOut = 3
self.TimerRunOut = self.TimerRunOut
self.TimerRunOut = self.TimerRunOut + 1
if (ply:IsSuperAdmin()) then
Well I found a solution, basically I just made a global variable that gets set when the prop is removed, saving the timer value, and loading it back as the value it set when it is spawned again (This happens when you perma prop, as it makes a new prop entirely), the immediately after, sets the value back to the default value.
Instead of table.HasValue use key = true expression (See here)
Move takenWeapons outside the ENT function
Instead of self.TimerRunOut == nil use if not self.TimerRunOut or self.TimerRunOut = self.TimerRunOut or 3
Thanks, I've seen the key = true thing before, but couldn't remember what it was / called, but yeah I got the perma prop to work, but now the value gets reset on a server restart cause I don't wanna make any kind of database for it
Sorry, you need to Log In to post a reply to this thread.