I am trying to learn Lua by making fun scripts that are simple, but here I am stuck. I get this error:
[CODE]
[ERROR] lua/autorun/bhop.lua:5: 'end' expected (to close 'function' at line 3) near 'else'
1. unknown - lua/autorun/bhop.lua:0
[/CODE]
I know it means it needs an "end" somewhere to close the function, but there is one at the bottom? Sorry, can someone explain and help me with this. Some of this code is from AceCools bhop script for pointshop.
[CODE]CreateClientConVar( "cl_bhop", 0, true, false)
hook.Add( "SetupMove", "BunnyHop", function( _p, _movedata, _cmd )
if GetConVarNumber > 1 then return end
else ( IsValid( _p ) ) then
local _buttons = _movedata:GetButtons( );
local _bJumping = ( bit.band( _buttons, IN_JUMP ) > 0 );
local _bCanResetJump = ( _p:GetMoveType( ) == MOVETYPE_WALK && !_p:OnGround( ) && _p:WaterLevel( ) < 1 );
if ( _bCanResetJump && _bJumping ) then
_movedata:SetButtons( bit.band( _buttons, bit.bnot( IN_JUMP ) ) );
end
end
end );[/CODE]
[code]
CreateClientConVar( "cl_bhop", 0, true, false)
hook.Add( "SetupMove", "BunnyHop", function( _p, _movedata, _cmd )
if GetConVarNumber > 1 then return end
if ( IsValid( _p ) ) then
local _buttons = _movedata:GetButtons( );
local _bJumping = ( bit.band( _buttons, IN_JUMP ) > 0 );
local _bCanResetJump = ( _p:GetMoveType( ) == MOVETYPE_WALK && !_p:OnGround( ) && _p:WaterLevel( ) < 1 );
if ( _bCanResetJump && _bJumping ) then
_movedata:SetButtons( bit.band( _buttons, bit.bnot( IN_JUMP ) ) );
end
end
end );
[/code]
[QUOTE=Invule;47343290][code]
CreateClientConVar( "cl_bhop", 0, true, false)
hook.Add( "SetupMove", "BunnyHop", function( _p, _movedata, _cmd )
if GetConVarNumber > 1 then return end
if ( IsValid( _p ) ) then
local _buttons = _movedata:GetButtons( );
local _bJumping = ( bit.band( _buttons, IN_JUMP ) > 0 );
local _bCanResetJump = ( _p:GetMoveType( ) == MOVETYPE_WALK && !_p:OnGround( ) && _p:WaterLevel( ) < 1 );
if ( _bCanResetJump && _bJumping ) then
_movedata:SetButtons( bit.band( _buttons, bit.bnot( IN_JUMP ) ) );
end
end
end );
[/code][/QUOTE]
Still doesn't work.
[editline]18th March 2015[/editline]
Ok updated code:
[CODE]CreateClientConVar( "cl_bhop", 0, true, false)
hook.Add( "SetupMove", "BunnyHop", function( _p, _movedata, _cmd )
if ( IsValid( _p ) ) and GetConVarNumber("cl_bhop") > 1 then return end
local _buttons = _movedata:GetButtons( );
local _bJumping = ( bit.band( _buttons, IN_JUMP ) > 0 );
local _bCanResetJump = ( _p:GetMoveType( ) == MOVETYPE_WALK && !_p:OnGround( ) && _p:WaterLevel( ) < 1 );
if ( _bCanResetJump && _bJumping ) then
_movedata:SetButtons( bit.band( _buttons, bit.bnot( IN_JUMP ) ) );
end
end
end );[/CODE]
Still this error
[CODE]
[ERROR] lua/autorun/bhop.lua:14: ')' expected (to close '(' at line 3) near 'end'
1. unknown - lua/autorun/bhop.lua:0
[/CODE]
You have 3 ends, but only need 2. :v:
try this:
[code]
CreateClientConVar( "cl_bhop", 0, true, false)
local function CanHop( ent )
if ( !ent:KeyDown( IN_JUMP ) ) then return false end
if ( LocalPlayer():IsOnGround() ) then return false end
if ( LocalPlayer():InVehicle() ) then return false end
if ( LocalPlayer():GetMoveType() == MOVETYPE_NOCLIP ) then return false end
if ( LocalPlayer():WaterLevel() >= 2 ) then return false end
return true
end
local function hop( ent )
if GetConVarNumber("cl_bhop") < 1 then return end
if ( CanHop( ent ) ) then
ent:SetButtons( ent:GetButtons() - IN_JUMP )
end
end
hook.Add( "CreateMove", "xd", hop )
[/code]
This should work, ive tested it.
please localize or anonymize those functions
Sorry, you need to Log In to post a reply to this thread.