• how to make a check after number variable is changed
    8 replies, posted
I'm back, and know more lua, my question is pretty simple, but I cant find any keywords on the wiki to find it I'm creating a Homeless script that once a players money is below 100 their job switches and they are pronounced homeless. That part is done, only one problem: If your money is 50, and you get it above 100, it *should* change your job to citizen, however it doesn't. Its not recognizing the change in the darkrp variable 'money'. Its through an NPC (odd choice, the addon has more to it) and because of that, I cannot put it in an autorun file (that would be stupid anyway because it would check every tick) And because I don't fully understand what autorun folders and all that do (and tbh i cant find anything explaining them) If you could link a source to better help me understand that (not to be confused with cl,sv, and shared, i know those) Thanks in advance, And if I'm being stupid and asking for basic knowledge, I'm terribly sorry.
Look into adding a function into the hook playerWalletChanged. The logic should be something like https://files.catbox.moe/8fbc64.png Untested, because i don't have a server to test it on, but that's the gist of things. Put the script somewhere serverside and you're golden.
I'll make sure to give it a try, I'll update you
it is possible to put an NPC into autorun by the way local ENT={}-- inside a entity file ENT is really just a table that is specific to that entity --some code defining your entity scripted_ents.Register(ENT,"classname")--this function registers your entity with the engine for more information about this trick see scripted_ents.Register
So I'm assuming you would like me to put scripted_ents.Register() at the end of where ever I need things to be updated? I'm new to scripted_ents.Register() and the wiki doesn't really explain, if you could go into more detail, I would deeply appreciate it
You seem to be going around this all wrong, why the hell would you want to do this in the NPC script? Even if you want some features to work with the NPC it doesn't mean it all needs to be in the same script. Also, autorun has nothing to do with how often functions in a script are called, it's got to do with loading the actual script in the first place. To me it sounds like you should just do what Lolcats said as it's a perfectly viable solution unless there's more to your script that you've told us.
Okay, to sum it up, the NPC is an employer, and he replaces the F4 menu, so if the player is homeless, he won't be able to become any job within the employer unless he has more than $100, Also, like I said, I have no idea what the different folder types do, I've searched for an explanation but I cant find one, Last night I was being stupid, and I'm trying lolcatz solution again. I wanted it to print something to console, but it was 3am and i thought it would print to the clients console XD only after a day's rest did I realize I was being retarded
It's impossible to call serverside functions clientside. For example, you can't call ply:ChangeTeam clientside, because that function only exists serverside. That's why you have to put the file/code I gave you in lua/autorun/server. You're going to trap yourself in an XY problem here. The Old Garry's Mod wiki is a great source of information regarding scripting tutorials, and I recommend you check out their tutorial on Garry's Mod Instances to familiarize yourself with the differences between clientside, serverside, and shared. The new Garry's Mod Wiki also has a shorter, more colorful article about it here.
I realize this, but thank you anyway <3
Sorry, you need to Log In to post a reply to this thread.