SetJumpPower not working


autorun/client.lua:14: attempt to call method 'SetJumpPower' (a nil value)

is the error I get ingame when I attempt to set the jump height with the function
[lua]function PlayerJumpHeightFunc( height )
player:SetJumpPower( height )
end[/lua]

This should work, could be wrong.



 function PlayerJumpHeightFunc( height )
	ply:SetJumpPower( height )
end

No,


autorun/client.lua:14: attempt to index global 'ply' (a nil value)
 

Try this:



 function PlayerJumpHeightFunc( height )
	Player:SetJumpPower( number jumpPower )
end

Source:

God no.

[editline]22nd June 2013[/editline]

OP, I see no sign of what that player variable is. Mind posting the part that assigns the variable ‘player’.

That’s probably why it’s not working, How do I assign the variable to the player that issued the concommand? Is it done in the function args?

Show how the function is being called. I see no sign of ConCommands in the snippet you posted.

[lua]

local condefs = {
HPlayer_JumpHeight = 200, --Default Height
}

function PlayerJumpHeightFunc( height )
ply:SetJumpPower( height )
end

concommand.Add( “HPlayer_JumpHeight”, PlayerJumpHeightFunc )

[/lua]

Probably should have posted this in the op, Sorry.

Also might need a way to declare height as an int.

So you want to use that condef as the jump power, correct?

Right, Not sv_gravity.



concommand.Add( "HPlayer_JumpHeight", function ( ply, cmd, args )
    ply:SetJumpPower( args[1] )
end )


This will set jump height to whatever the player specifies to whoever calls the console command. I still can’t see what you are trying to do though.

concommand.Add passes a few parameters but the only one we need in this case is the player who ran the concommand. You also can’t make up your own parameters.

[LUA]

local condefs = {
HPlayer_JumpHeight = 200, --Default Height
}

function PlayerJumpHeightFunc( ply )
ply:SetJumpPower( condefs[“HPlayer_JumpHeight”] )
end

concommand.Add( “HPlayer_JumpHeight”, PlayerJumpHeightFunc )
[/LUA]

[editline]22nd June 2013[/editline]

Ninja’d, if you want to use args rather than your condef - see above.

Okay, thanks. So I know in the future, do commands care if the args are set as strings or ints in the console?

You can’t specify if the argument is an int or a string in console. It’s all strings. I believe if tonumber( arg ) succeeds, then it is returned as an integer in the argument table.

Okay, I’m not getting any errors now, but I don’t see any difference in jump height when I use the command to change my jump height to 1500 (default is 200, wiki says 1500 is a very noticeable difference).

The only other commands in my code are parts that add the console command as a slider to an options entry.

Is the command broken?

This isn’t a console variable. And it is not admin only, keep those it mind.
Make sure you call the function on server.