I have some problems with my spectator mode
when 4+ alive i can switch between players
when i have 3 alive i can only see the first player
and when i can switch it switch extrem fast and when i click i get a random player because when i click once the game gets 14 clicks for example how can i fix it?
[CODE]
//SpectatorSwitch
plySpecMode = 0
plySpecName = ""
plySpec = ""
local plyi = 0
function GM:KeyPress( ply, key )
local plCount = 0
local specPl = 0
local t = 0
local interval = 0.3
for k, plyn in pairs( player.GetAll() ) do
if ( key == IN_ATTACK2 ) and ply:Team() != 1 then
if t < CurTime() then
t=CurTime()+interval
if plySpecMode < 2 then
plySpecMode = plySpecMode+1
else
plySpecMode = 0
end
end
net.Start("Spec_ChangeMode")
net.WriteInt( plySpecMode, 4 )
net.SendToServer()
end
if ( key == IN_ATTACK ) and ply:Team() != 1 then
if t < CurTime() then
t = CurTime()+interval
plyi = plyi + 1
plym = player.GetAll()[plyi]
if plym != nil and plym:Team() == 1 then
plySpecName = plym:GetName()
plySpec = plym
print(LocalPlayer():Nick() .. " specs at " .. plySpecName .. " | " .. plySpecMode)
net.Start("Spec_ChangePly")
net.WriteEntity(plym)
net.SendToServer()
else
plyi = 0
end
end
end
end
end[/CODE]
need help at this :D
I'm begginer on lua
before GM:KeyPress
[code]
keyDown = false
[/code]
after GM:KeyPress
[code]
if !keyDown and key == IN_ATTACK then
makeChangePlayerHere!!!()
keyDown = true
elseif keyDown then
keyDown = false
end
[/code]
I don't understand what your code is doing. It's looping through all the players but then not using them at all!
The 14-clicks-per-click thing is probably caused by [url=http://wiki.garrysmod.com/page/Prediction]Prediction[/url], but I'm not sure.
Think thoroughly about what you want your code to do, and how you want to do it.
[code]function GM:KeyPress( ply, key )
local plCount = 0
local specPl = 0
local maxply = 0
for k, plyn in pairs( player.GetAll() ) do
maxply = maxply + 1
end
if ( key == IN_ATTACK2 ) and ply:Team() != 1 then
if RC < 2 then
RC = RC + 1
else
RC = 0
end
net.Start("Spec_ChangeMode")
net.WriteInt( RC, 4 )
net.SendToServer()
plySpecMode = RC
end
if ( key == IN_ATTACK ) and ply:Team() != 1 then
if LC < maxply then
LC = LC + 1
else
LC = 0
end
plym = player.GetAll()[LC]
if plym != nil and plym:Team() == 1 then
plySpecName = plym:GetName()
plySpec = plym
print(LocalPlayer():Nick() .. " specs at " .. plySpecName .. " | " .. plySpecMode)
net.Start("Spec_ChangePly")
net.WriteEntity(plym)
net.SendToServer()
else
plyi = 0
end
end
end
[/code]
this code works now :D
Sorry, you need to Log In to post a reply to this thread.