Using this for my gamemode, not good but not bad either. Works for what I want to do though.
Put in a shared file:
[CODE]local ptp_staminalossrate = CreateConVar("ptp_staminalossrate", "12.5", bit.bor(FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED, FCVAR_SERVER_CAN_EXECUTE));
local ptp_staminagainrate = CreateConVar("ptp_staminagainrate", "35", bit.bor(FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED, FCVAR_SERVER_CAN_EXECUTE));
hook.Add("SetupMove", "Stamina", function(ply, mv, cmd)
if(ply:KeyDown(IN_SPEED)) then
ply:SetNWFloat("m_flLastSpeed", CurTime());
end
local m_flLastSpeed = ply:GetNWFloat("m_flLastSpeed", 0);
if(m_flLastSpeed == 0) then
ply:SetNWFloat("m_flStamina", 100);
return;
end
local m_flStamina = ply:GetNWFloat("m_flStamina", 100);
if(ply:KeyDown(IN_SPEED) && IsFirstTimePredicted() && m_flStamina > 0) then
m_flStamina = m_flStamina - engine.TickInterval() * ptp_staminalossrate:GetFloat();
end
if(m_flStamina <= 0) then
ply:SetRunSpeed(ply:GetWalkSpeed());
else
ply:SetWalkSpeed(230);
ply:SetRunSpeed(355);
end
if((m_flLastSpeed + 2.5) <= CurTime() && IsFirstTimePredicted()) then
m_flStamina = m_flStamina + engine.TickInterval() * ptp_staminagainrate:GetFloat();
if(m_flStamina > 100) then m_flStamina = 100; end
end
ply:SetNWFloat("m_flStamina", m_flStamina);
end);[/CODE]
You shouldn't set networked variables from the client, considering this is done in a shared file. But otherwise a good base
[QUOTE=solid_jake;50981787]You shouldn't set networked variables from the client, considering this is done in a shared file. But otherwise a good base[/QUOTE]
Prediction requires stuff to happen in the same way between client and server, what you said would cause prediction errors and cause the client to stutter and teleport back and forth on high ping.
Regardless of that,OP, you're using networked variables that don't support prediction very well, to use the ones that support prediction, you need to add a "2" in between the SetNW*Float, like SetNW2Float.
This hidden system was supposed to replace the SetNW* and etc system a long time ago but didn't due to other plans.
Sorry, you need to Log In to post a reply to this thread.