I have been working on a pointshop item that turns you invisible after you have been crouching for three seconds.
This works absolutely fine on single player and on listen servers, but the moment I go onto a dedicated server it bugs out. When I crouch it only sometimes works, same with un-crouching. I am thinking it is just un-optimized and that the dedicated servers tick rate is just too low to detect it.
Here is the code(might be a little hacky):
[CODE]ITEM.Name = 'Invisibilty Cloak'
ITEM.Price = 0
ITEM.Model = 'models/Items/HealthKit.mdl'
ITEM.NoPreview = false
function ITEM:OnEquip(ply, modifications)
visibility = 30
reset = 0
end
function ITEM:Think()
for k, v in pairs(player.GetAll()) do
if v:PS_HasItemEquipped("invis") then
ply = v
end
end
if SERVER then
wep = ply:GetActiveWeapon()
vel = ply:GetVelocity():Length()
if ply:KeyPressed(IN_DUCK) then
timer.Simple(3,function()
if ply:Crouching() then
ply:SetNWBool("TurnInvis", true)
end
end)
end
if ply:KeyReleased(IN_DUCK) then
if ply:GetNWBool("TurnedInvis") == true then
if !ply:IsValid() and ply:Alive() then return end
ply:SetNWBool("TurnInvis", false)
ply:SetNWBool("TurnedInvis", false)
ply:PrintMessage( HUD_PRINTTALK, "It works v2 :D" )
ply:SetMaterial("")
end
end
if ply:GetNWBool("TurnInvis") == true and ply:GetNWBool("TurnedInvis") == false and ply:Crouching() then
if !ply:IsValid() and ply:Alive() then return end
ply:SetNWBool("TurnedInvis", true)
ply:SetMaterial("models/props_c17/fisheyelens")
ply:PrintMessage( HUD_PRINTTALK, "It works :D" )
end
if ply:GetNWBool("TurnedInvis") == true then
if !ply:IsValid() and ply:Alive() then return end
local invis = Color(0,0,0,0)
if ply:GetActiveWeapon():IsValid() then
ply:GetActiveWeapon():SetRenderMode(RENDERGROUP_TRANSLUCENT)
ply:GetActiveWeapon():SetColor(invis)
end
else
if ply:GetActiveWeapon():IsValid() then
ply:GetActiveWeapon():SetColor(Color(255,255,255,255))
end
end
end
end
end
function ITEM:OnHolster(ply)
end[/CODE]
Any help is appreciated. Oh and just on another note it appears if anyone else has this item equipped it messes it up for you even more.
It looks like I have too many ends because I removed a few things during the post. Anyway, when I had the ply in the think function but it appeared to be calling it for every damn player on the server.
I also am not really sure about CurTime. Everytime I try and use it, it doesn't seem too work. I tried to make it so it sets a time on the when you press the keydown (invistime = CurTime() + 3) and then during the check just make it see if it was the right time. I just can't seem to get CurTime() working :S
I will try using the variables now, I will post again once I have tried the stuff you posted. Thanks for the help.
Sorry, you need to Log In to post a reply to this thread.