How to make a .lua file only run if a command is active?

Maverick Finn

aka Mavy
I'm making a pk3, and inside my Lua folder there is a momentum.lua that I want to run only if, let's say, the momentum command is active.
So I type momentum on on the console, and only then, the game runs that specific .lua.

How do i do it?
 
I think that's pretty easy. You first need a variable that determines if the script should be run. I don't know which type of variable is recommended (a local, player or console one), but I'd probably recommend you to use a player variable.
Then, you make the command switch that variable on or off depending on the argument you give it.
And finally, you add a check in your LUA script, where if the variable is positive, it will run it, and otherwise, it won't.
Hope I explained it correctly...
 
And finally, you add a check in your LUA script, where if the variable is positive, it will run it, and otherwise, it won't.
What should that check be? Cuz its easy to make a variable, but I dont want to apply it as the first "if" statement in every single hook of my lua.
 
What should that check be? Cuz its easy to make a variable, but I dont want to apply it as the first "if" statement in every single hook of my lua.
I'm afraid I don't think there's another way rather than adding if statements on each hook.
But don't worry, there's a way to do the check in just one line (you have to put it at the beginning of the hook's script):
Lua:
if not player.momentum then return end
 

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top