(TTT) 400% PlayerSpeed

I wanted give all living players on the server a playerspeed of 400%. But the Speed does not change. It´s still normal. Here is the code:

[lua] function RandomatSuperBlitz()
RandomatBroadcast("Randomat: ", Color(255,255,255), “Let´s change your speed!”)
for k,v in pairs(player.GetAll()) do
v.RandomatSuperSpeed = true
end
hook.Remove(“TTTPlayerSpeedModifier”, “RandomatTTTSuperSpeed” )
hook.Add(“TTTPlayerSpeedModifier”, “RandomatTTTSpeed” , function(ply)
if ply.RandomatSpeed and !ply.RandomatSuperSpeed then
return 4
end
end )
end[/lua]

Where am I mistaken ?

Possible mistakes:

  • ply.RandomatSpeed is never true when it has to be. (if ply.RandomatSpeed )
  • ply.RandomatSuperSpeed is true when it should be false. (and !ply.RandomatSuperSpeed)
  • All that code is inside the function called RandomatSuperBlitz() which you don’t seem to execute.
  • Oh and you gotta use the hook called TTTPlayerSpeed.

Untested but this might work:



function RandomatSuperBlitz()
    RandomatBroadcast("Randomat: ", Color(255,255,255), "Let´s change your speed!")
    for k,v in pairs(player.GetAll()) do
      v.RandomatSuperSpeed = true
    end    
  end
hook.Add("TTTPlayerSpeed", "RandomatTTTSpeed" , function(ply, slowed)
	if ply.RandomatSuperSpeed then
	  return 4
	end
end )


That will change next update: https://github.com/Facepunch/garrysmod/pull/1387

Here’s how I would have done it (and I suck at coding but doesn’t matter if it works :smug:):



function RandomatSuperBlitz()

RandomatBroadcast("Randomat: ", Color(255,255,255), "Let´s change your speed!")

for k,v in pairs(player.GetAll()) do

	if (v:Alive() and v.RandomatSuperSpeed == true) then	
	v:SetWalkSpeed( v:GetWalkSpeed()/4 )
	v:SetRunSpeed( v:GetRunSpeed()/4 )
	v.RandomatSuperSpeed = false
	end
	
	if (v:Alive() and v.RandomatSuperSpeed != true) then		
	v:SetWalkSpeed( v:GetWalkSpeed()*4 )
	v:SetRunSpeed( v:GetRunSpeed()*4 )
	v.RandomatSuperSpeed = true
	end	

end

end


This code won’t work in TTT because (atleast in the current version) it uses SetWalkSpeed every tick. You NEED to use the hook TTTPlayerSpeed (In the future version TTTPlayerSpeedModifier).

Ah, didn’t know that, never touched TTT.

The problem with the original code is probably that you are returning only if the ply doesn’t have the super speed var true, but before that you set it for all players as true

TTTPlayerSpeedModifier is going to be released next update, for now you need to add a hook in both client and server states like so:
[lua]
hook.Add(“TTTPlayerSpeed”, “Your Hook Name”, function() return 4 end)
[/lua]