I am trying to make a script where it will appear like players are lagging by teleporting them back every few seconds. I'm not exactly sure where to start, but what I was thinking so far was:
[CODE]
function Lag ()
for k,v in pairs(player.GetAll()) do
local pvar v:GetPos()
timer.Create("RandomTime",math.random(3,5),0,function() v:SetPos(pvar) end)
end
end
concommand.Add( "user_lag",function Lag )
[/CODE]
If anyone had some suggestions or could point me in the right direction that would be great.
I think that function would work if you changed it a tiny bit to something like this:
[CODE]
local function Lag()
for k,v in pairs( player.GetAll() ) do
v.pvar = v:GetPos()
timer.Create( "RandomTime", math.random(3,5), 0, function() v:SetPos( v.pvar ) end )
end
end
concommand.Add( "user_lag", Lag )
[/CODE]
[editline]15th May 2016[/editline]
I haven't tested that code though, I'm testing it now...
[editline]15th May 2016[/editline]
Yeah, that seems to work. Just a little note though, the math.random( 3,5 ) thing you're doing doesn't get re-randomized every time the timer is called, so if it generates 3 the first time the timer is called, it won't take 4 or 5 seconds next time
[QUOTE=MPan1;50323742]I think that function would work if you changed it a tiny bit to something like this:
[CODE]
local function Lag()
for k,v in pairs( player.GetAll() ) do
v.pvar = v:GetPos()
timer.Create( "RandomTime", math.random(3,5), 0, function() v:SetPos( v.pvar ) end )
end
end
concommand.Add( "user_lag", Lag )
[/CODE]
[editline]15th May 2016[/editline]
I haven't tested that code though, I'm testing it now...
[editline]15th May 2016[/editline]
Yeah, that seems to work. Just a little note though, the math.random( 3,5 ) thing you're doing doesn't get re-randomized every time the timer is called, so if it generates 3 the first time the timer is called, it won't take 4 or 5 seconds next time[/QUOTE]The only way to make timer.create "random" is to have the number delay at 0 or 1 then check if the last time the player got tp:ed was longer than the random number.
You'd probably want to make an unique identifier for the timer for each player as well. This will only create a single timer no matter how many players there are.
You're better off using a move hook. I just threw this together in sublime, but it should simulate some pretty bad lag. Mess with the numbers to find what suits you.
[lua]hook.Add("SetupMove", "FakeLag", function(player, move, user)
if (user:TickCount() % math.random(30, 50) == 0 and player.oldOrigin) then
move:SetOrigin(player.oldOrigin)
elseif (user:TickCount() % math.random(30, 50) == 0) then
player.oldOrigin = move:GetOrigin()
end
end)[/lua]
[QUOTE=man with hat;50324666]You're better off using a move hook. I just threw this together in sublime, but it should simulate some pretty bad lag. Mess with the numbers to find what suits you.
[lua]hook.Add("SetupMove", "FakeLag", function(player, move, user)
if (user:TickCount() % math.random(30, 50) == 0 and player.oldOrigin) then
move:SetOrigin(player.oldOrigin)
elseif (user:TickCount() % math.random(30, 50) == 0) then
player.oldOrigin = move:GetOrigin()
end
end)[/lua][/QUOTE]
Thank you, this is exactly what I was looking for.
Sorry, you need to Log In to post a reply to this thread.