Wrap SteamID64 clientside to fix Bots

Attempt to fix Issue #7
This commit is contained in:
sammyt291 2020-03-03 10:57:51 +00:00 committed by GitHub
parent 9d4aaba7fd
commit eb7e93f28c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -198,17 +198,28 @@ function NADMOD.AdminPanel(Panel, runByNetReceive)
Panel:Button("Cleanup World Ropes", "nadmod_cleanworldropes") Panel:Button("Cleanup World Ropes", "nadmod_cleanworldropes")
end end
-- Wrapper function as Bots return nothing clientside for their SteamID64
function SteamID64bot( ply )
if( not IsValid( ply ) ) then return end
if ply:IsBot() then
-- Calculate Bot's SteamID64 according to gmod wiki
return 90071996842377216 + tonumber( string.sub( ply:Nick(), 4) )
else
return ply:SteamID64()
end
end
net.Receive("nadmod_ppfriends",function(len) net.Receive("nadmod_ppfriends",function(len)
NADMOD.Friends = net.ReadTable() NADMOD.Friends = net.ReadTable()
for _,tar in pairs(player.GetHumans()) do for _,tar in pairs(player.GetAll()) do
CreateClientConVar("npp_friend_"..tar:SteamID64(),NADMOD.Friends[tar:SteamID()] and "1" or "0", false, false) CreateClientConVar("npp_friend_"..SteamID64bot(tar),NADMOD.Friends[tar:SteamID()] and "1" or "0", false, false)
RunConsoleCommand("npp_friend_"..tar:SteamID64(),NADMOD.Friends[tar:SteamID()] and "1" or "0") RunConsoleCommand("npp_friend_"..SteamID64bot(tar),NADMOD.Friends[tar:SteamID()] and "1" or "0")
end end
end) end)
concommand.Add("npp_applyfriends",function(ply,cmd,args) concommand.Add("npp_applyfriends",function(ply,cmd,args)
for _,tar in pairs(player.GetAll()) do for _,tar in pairs(player.GetAll()) do
NADMOD.Friends[tar:SteamID()] = GetConVar("npp_friend_"..tar:SteamID64()):GetBool() NADMOD.Friends[tar:SteamID()] = GetConVar("npp_friend_"..SteamID64bot(tar)):GetBool()
end end
net.Start("nadmod_ppfriends") net.Start("nadmod_ppfriends")
net.WriteTable(NADMOD.Friends) net.WriteTable(NADMOD.Friends)
@ -235,7 +246,7 @@ function NADMOD.ClientPanel(Panel)
else else
for _, tar in pairs(Players) do for _, tar in pairs(Players) do
if(IsValid(tar) and tar != LocalPlayer()) then if(IsValid(tar) and tar != LocalPlayer()) then
Panel:CheckBox(tar:Nick(), "npp_friend_"..tar:SteamID64()) Panel:CheckBox(tar:Nick(), "npp_friend_"..SteamID64bot(tar))
end end
end end
Panel:Button("Apply Friends", "npp_applyfriends") Panel:Button("Apply Friends", "npp_applyfriends")