Need help with this :P

So this is what I’m trying to do. I’ve got this script what auto jumps every time you land on the ground, this script does work but I’m trying to add this script to a team and want it to only work for that team.



hook.Add("Think", function()
	if player.Team == 5 then
		if input.IsKeyDown( KEY_SPACE ) then
			if LocalPlayer():IsOnGround() then
				RunConsoleCommand("+jump")
				HasJumped = 1
			else
				RunConsoleCommand("-jump")
				HasJumped = 0
			end
		elseif LocalPlayer():IsOnGround() then
			if HasJumped == 1 then
				RunConsoleCommand("-jump")
				HasJumped = 0
			end
		end
	end
end)


I’ve added what team it is but when I test it the auto jump is not working, any ideas?

you CAN call it bunny hopping… i mean people know what bunny hopping is.

a very quick google search returned some old facepunch threads which are inactive but had some useful links

I know there is old scripts but I try’d them but they slow down after short time, this one is good and I want to know how I could make that work with only 1 team.

Thanks for suggestion though :slight_smile:

well unless you are setting .Team on the player, it doesnt exist by default. do you mean player:Team()? also avoid naming variables after anything that already exists (this applies to all scripting/coding/programming conventions). player is a defined table in garrysmod. try calling your parameter ply and you might want to iterate over all players on the server since player.Team doesnt exist on its own


hook.Add("Think", function()
	if ply:Team() == 5 then
		if input.IsKeyDown( KEY_SPACE ) then
			if LocalPlayer():IsOnGround() then
				RunConsoleCommand("+jump")
				HasJumped = 1
			else
				RunConsoleCommand("-jump")
				HasJumped = 0
			end
		elseif LocalPlayer():IsOnGround() then
			if HasJumped == 1 then
				RunConsoleCommand("-jump")
				HasJumped = 0
			end
		end
	end
end)


I done what you have said but this still doesn’t auto jump.

is ply defined? change ply to LocalPlayer if not.

nice catch i completely forgot that input is client side (yet again i need sleep D:)

Ok, done what you said, just another question, I added it to the init.lua but is that right, which I use, init.lua or cl_init.lua?
The code is on it own file and I use the include( ‘bhop_autojump.lua’ ) in init.lua

well for one input is client side and localplayer is client side so it should go in any client side file.

you COULD put it in shared and wrap it in



if (CLIENT) then
...
end


but i going to assume you will run into more problems, cl_init.lua

also name your hook:



hook.Add("Think", "BHop", function()
...
end)


other wise the function will be the name of your hook and it wont get called and it will be all messed up.



if (CLIENT) then
hook.Add("Think", "BHop", function()
	if LocalPlayer:Team() == 5 then
		if input.IsKeyDown( KEY_SPACE ) then
			if LocalPlayer():IsOnGround() then
				RunConsoleCommand("+jump")
				HasJumped = 1
			else
				RunConsoleCommand("-jump")
				HasJumped = 0
			end
		elseif LocalPlayer():IsOnGround() then
			if HasJumped == 1 then
				RunConsoleCommand("-jump")
				HasJumped = 0
			end
		end
	end
end)
end


The hook is getting called but it coming up with a lot of lua errors. (still in it own file, not in shared.lua)



[ERROR] gamemodes/bhop/gamemode/bhop_autojump.lua:3: attempt to index global 'LocalPlayer' (a function value)
  1. fn - gamemodes/bhop/gamemode/bhop_autojump.lua:3
 

And then when I put ply instead of LocalPlayer it comes with




[ERROR] gamemodes/bhop/gamemode/bhop_autojump.lua:3: attempt to call method 'Team' (a nil value)
  1. fn - gamemodes/bhop/gamemode/bhop_autojump.lua:3
 

It should be LocalPlayer()

Sorted now, thanks guys :smiley: