I'm trying to reverse-engineer a script I downloaded to make something for myself just to test the new Lua feature but I don't know what should I do.
All I want to make is a command that adds, sets or whatever the momentum of the player to whatever value the player choosed.
Now, how do I make this function a console command that takes 4 arguments and executes it to the player?
I'm new to Lua, I read the tutorials and the functions page too.
Also, everytime I load the Lua, it says that the initialization of ply_mom was prevented or something like that.
I don't get the command adding part also.
---------- Post added at 10:58 PM ---------- Previous post was at 10:36 PM ----------
Fixed it!
However I'm still having a problem:
There was a problem indexing player (a nil value).
What did I do wrong?
EDIT: Fixed it. I had to put "player" as the first argument. Now everytime I use it, I have to put a giant numer to move the player a bit lower, like 555555. What its wrong now?
FINAL EDIT: Fixed it. All I had to do is multiply the value given by the player by 65535.
All I want to make is a command that adds, sets or whatever the momentum of the player to whatever value the player choosed.
Code:
ply_mom = function(op, lolx, loly, lolz)
if lolx == nil then
lolx = 0
end
if loly == nil then
loly = 0
end
if lolz == nil then
lolz = 0
end
if op == 'add' then
player.mo.momx = player.mo.momx + lolx
player.mo.momy = player.mo.momy + loly
player.mo.momz = player.mo.momz + lolz
print("You added some momentum.")
elseif op == 'set' then
player.mo.momx = lolx
player.mo.momy = loly
player.mo.momz = lolz
print("You set your momentum.")
elseif op == 'mult' then
player.mo.momx = player.mo.momx * lolx
player.mo.momy = player.mo.momy * loly
player.mo.momz = player.mo.momz * lolz
print("Stop trying to crash the game with your momentum, will you?")
else
print("Placeholder for invalid argument and some quick help.")
end
end
COM_AddCommand(momentum, ply_mom(op, lolx, loly, lolz), 0)
Now, how do I make this function a console command that takes 4 arguments and executes it to the player?
I'm new to Lua, I read the tutorials and the functions page too.
Also, everytime I load the Lua, it says that the initialization of ply_mom was prevented or something like that.
I don't get the command adding part also.
---------- Post added at 10:58 PM ---------- Previous post was at 10:36 PM ----------
Fixed it!
However I'm still having a problem:
Code:
local function newmom(ignore, op, lolx, loly, lolz)
if lolx == nil then
lolx = 0
end
if loly == nil then
loly = 0
end
if lolz == nil then
lolz = 0
end
if op == 'add' then
player.mo.momx = player.mo.momx + lolx
player.mo.momy = player.mo.momy + loly
player.mo.momz = player.mo.momz + lolz
print("You added some momentum.")
elseif op == 'set' then
player.mo.momx = lolx
player.mo.momy = loly
player.mo.momz = lolz
print("You set your momentum.")
elseif op == 'mult' then
player.mo.momx = player.mo.momx * lolx
player.mo.momy = player.mo.momy * loly
player.mo.momz = player.mo.momz * lolz
print("Stop trying to crash the game with your momentum, will you?")
else
print("Placeholder for invalid argument and some quick help.")
end
end
COM_AddCommand("momentum", newmom, 0)
There was a problem indexing player (a nil value).
What did I do wrong?
EDIT: Fixed it. I had to put "player" as the first argument. Now everytime I use it, I have to put a giant numer to move the player a bit lower, like 555555. What its wrong now?
FINAL EDIT: Fixed it. All I had to do is multiply the value given by the player by 65535.
Last edited: