Detecting player movement and detecting if bug bait touches someone

Hey there, me…again…, I have this code I wrote but it crashes the server :frowning:



hook.Add( "Move", "player_move", function( ply, mv )

	while(gameStarted) do
		if(ply:Team() == 2) then
			while(mv:GetForwardSpeed() <= 10) do
				alpha = alpha + 0.01
			end
			while(mv:GetForwardSpeed() > 10) do
				alpha = alpha - 0.0001
			end
		end
	end	
end ) 


basically, if they game has started, and your on team 2, and you stand still, or almost still, a variable called alpha increases, (I already have all that setup) and if you move over 10 speed it goes down, but at a slower rate
This crashes when game starts,

Another thing is, I can’t detect when bug bait hits someone, I have tried



function GM:PlayerShouldTakeDamage( ply, attacker )


But the bug bait does 0 damage, where is the code for bug bait? cause I could make the damage 5 but then return false in PlayerShouldTakeDamage, and that would work right? or is there an easier way

I still have no idea, google isn’t cooperating

You code crashes the server because the hook move never actually finishes. You created an infinite loop and until it end (which it wont), the game can’t continue.

Instead of ’ while ( this ) do’ use ‘if this then’ in exactly the same way.

Server doesn’t agree with you, still crashes :/, thanks for trying though

It’s probably because you are still using while loops that never ends…
[lua]
hook.Add( “Move”, “player_move”, function( ply, mv )
if gameStarted and ply:Team() == 2 then
alpha = alpha + (mv:GetForwardSpeed() <= 10 and 0.01 or -0.0001)
end
end)
[/lua]

Okay, so it doesn’t crash now, the only problem now is that, there alpha isn’t changing, here is the code I have



local alpha = 10

-- Under PlayerLoadout function
ply:SetRenderMode(4)
ply:SetColor( Color(255,255,255,alpha) )

-- then the script BlackVoid said


And where do you have that code? What hook?

Here is all the important code




local alpha = 10

hook.Add( "Move", "player_move", function( ply, mv )

	if gameStarted and ply:Team() == 2 then
		alpha = alpha + (mv:GetForwardSpeed() <= 10 and 0.01 or -0.0001)
	end
end ) 

function GM:PlayerLoadout( ply )
	if ( ply:Team() == 2 ) then
		ply:SetRenderMode(4)
		ply:SetColor( Color(255,255,255,alpha) )
	end
end


My spacing messes up on here so sorry if it’s spacing is all messed up

btw, im not even sure if mv:GetForwardSpeed() is an actual thing, according to google it is, but according to wiki it isn’t.

Just do SetColor after your alpha=alpha, PlayerLoadout is only called when you spawn.

And that will set everyone’s alpha.

No it won’t.

In all honesty I think you should make a custom SWEP and Entity

Okay, time to hit the tutorials, wiki and google.
this will be fun.

[editline]20th January 2014[/editline]

There is an if statement making it team 2 only.

[editline]20th January 2014[/editline]

Oh yeah… I should of thought of that… silly me.

Sorry, I meant to put ‘won’t’ :stuck_out_tongue: