It's not running (in lua/autorun/client) and when i type StartBhop, it says unknown command. What's wrong?
[code]function bhop(ply, command, args)
local args = args[1]
for k,v in pairs(player.GetAll()) do
if (v:IsOnGround()) then
v:ConCommand("+jump")
timer.Simple(1,function(ply) ply:ConCommand("-jump") end,v)
end
end
end
concommand.Add("StartBhop", bhop)
if bhop(args)=="on" then
a = 1
else
a = 0
end
while a==1 do
bhop()
end[/code]
You can't add a console command inside a function, move it out of that function.
If you're on the client, none of that code works, because there isn't a player table, use LocalPlayer() instead.
Args is a table and overwriting it is a bad idea.
A is global, which is a bad idea.
You really aren't following the Lua syntax, have you actually read PIL?
OMG! I forgot to add an end to the end of that... Thank you. HAHA
[editline]12:39AM[/editline]
I mostly work with Python, so I'm just basically writing it in Lython and then asking you guys for help and learning as I go...
[editline]12:50AM[/editline]
Alright, well I have this now, and it still isn't working:
[code]function bhop(ply, command, args)
local player = LocalPlayer()
if (player:IsOnGround()) then
player:ConCommand("+jump")
player:ConCommand("-jump")
end
end
concommand.Add("StartBhop", bhop)
if bhop(args[1])=="on" then
local a = 1
elseif bhop(args[1])=="off" then
local a = 0
end
while a == 1 do
bhop()
end[/code]
Use a timer or a think hook. You're just making an infinite loop.
[php]local bhop = false
hook.Add("Think", "Bunnyhop", function()
if bhop and LocalPlayer():IsOnGround() then
RunConsoleCommand("+jump")
timer.Simple( 0.2, function()
RunConsoleCommand("-jump")
end )
end
end )
concommand.Add("bhop_toggle", function() bhop = !bhop end )[/php]
Infinite loop I presume?
[code]
local On=0
function bhop(ply,_,args)
if(args[1]=="on") then
On=1
else if(args[1]=="off") then
On=0
end
if On
if(player:IsOnGround()) then
ply:ConCommand("+jump")
else
ply:ConCommand("-jump;StartBhop")
end
end
end
concommand.Add("StartBhop",bhop)
[/code]
Untested and unspaced, but should work.
[editline]11:59PM[/editline]
Alot of posts ninja'd me S:
Map, I edited yours and this is what has come out of it, but it still won't work...:
[code]local On=0
function bhop(ply,_,args)
if(args[1]=="on") then
On=1
elseif(args[1]=="off") then
On=0
end
end
if On
if(player:IsOnGround()) then
ply:ConCommand("+jump")
else
ply:ConCommand("-jump; StartBhop")
end
end
concommand.Add("StartBhop",bhop)[/code]
Combine, I am trying yours now.
[editline]01:10AM[/editline]
Also, is there any way to reload the script without restarting?
That's not what I had. You put the on check INSIDE the function D: Why did you edit it?
[editline]12:15AM[/editline]
[code]
local On=0
function bhop(ply,_,args)
if(args[1]=="on") then
On=1
elseif(args[1]=="off") then
On=0
end
if On
if(player:IsOnGround()) then
ply:ConCommand("+jump")
else
ply:ConCommand("-jump; StartBhop")
end
end
end
concommand.Add("StartBhop",bhop)
[/code]
This is what I have now and it works perfectly. Thank you to both of you for all of your help!
[lua]local bhop = false
hook.Add("Think", "Bunnyhop", function()
if (input.IsKeyDown( KEY_SPACE ) ) then
if bhop and LocalPlayer():IsOnGround() then
RunConsoleCommand("+jump")
else
RunConsoleCommand("-jump")
end
end
end )
concommand.Add("bhop", function() bhop = !bhop end )[/lua]
Sorry, you need to Log In to post a reply to this thread.