player.GetAll() except?

Can I do player.Getall() except for a SteamID? I want the “Highest Money” on the Elite F4 Menu to not include me.

[lua]

local Players = player.GetAll( )
table.RemoveByValue( Players, player.GetBySteamID( “Your SteamID Here” ) )

– Players is now a table containing all connected players, excluding yourself

[/lua]

Haven’t tested it, but if it doesn’t work this should atleast give you the right idea.

Thanks, kind of confused though, how would I make that work with this?


	for k, v in pairs( player.GetAll() ) do
		local vMoney = v:getDarkRPVar( "money" ) or 0
		money = money + vMoney
	end

[editline]28th September 2015[/editline]

Or is it


	for k, v in pairs( player.GetAll() ) do
		table.insert( mTable, { ply = v, money = v:getDarkRPVar( "money" ) or 0 } )
	end

?

Full money code:



	local totalMoney = 0
	local highBase = 0
	local money = 0
	
	local maxBase = 0
	
	local jobs = {}
	
	for k, v in pairs( player.GetAll() ) do
		local vMoney = v:getDarkRPVar( "money" ) or 0
		money = money + vMoney
	end
	
	local mTable = {}
		
	for k, v in pairs( player.GetAll() ) do
		table.insert( mTable, { ply = v, money = v:getDarkRPVar( "money" ) or 0 } )
	end
	
	for k, v in pairs( team.GetAllTeams() ) do
		if team.NumPlayers( k ) > 0 then
			table.insert( jobs, v )
		end
	end
	
	table.SortByMember( mTable, "money" )
	
	local first = table.GetFirstValue( mTable )
	
	local jobTable = team.GetAllTeams()
	
	local teamTable = {}
	
	for k, v in pairs( jobTable ) do
		if v.Name != "Joining/Connecting" then
		
			local numPlayers = team.NumPlayers( k )
			
			teamTable[k] = numPlayers
			
		end
	end


You didn’t incorporate his code at all. Just store the player.GetAll table BEFORE looping through, then removing yourself using the code he provided.

Or use an if statement.

Doing a check for every element is going to be unneeded inefficiency.

steamids are constant, and doing a check for every element is exactly what removebyvalue and getbysteamid both do

james’ code does twice as many “unneeded inefficient” checks

Wouldn’t the table.remove do that internally anyways? If so then no real inefficiency there.

Exclude yourself from the loop like this:



for k, v in pairs( player.GetAll() ) do
  if v:SteamID() ==  "Your SteamID" then continue end

  local vMoney = v:getDarkRPVar( "money" ) or 0
  money = money + vMoney
end




for k, v in pairs( player.GetAll() ) do
  if v:SteamID() == "Your SteamID"  then continue end

  local vMoney = v:getDarkRPVar( "money" ) or 0
  money = money + vMoney
end


using a player.GetBySteamID call inside a loop of all players seems a bit wasteful, you could instead just directly check the steamID. Also, you were returning when you should have been continuing.

I answered with haste; thanks for the feedback. I altered my post to reflect the changes.

“F4 menu”
This is clientside…

Fuck steam IDs, compare player objects instead

[lua]
for k, ply in pairs(player.GetAll()) do
if ply == LocalPlayer() then continue end

-- CODE HERE IS RUN FOR EVERY PLAYER BUT YOURSELF

end
[/lua]

You can optimise this code by taking the LocalPlayer() call outside of the loop. I honestly doubt that’s worth the effort, though. Since it’s being put in an F4 menu, it’s probably only run once.

[editline]28th September 2015[/editline]

If per chance he really means him specifically, and not the local player, it’s equally simple.

[lua]for k, ply in pairs(player.GetAll()) do
if ply:SteamID() == “STEAM_0:1:7099” then continue end

-- CODE HERE IS RUN FOR EVERY PLAYER BUT YOU

end[/lua]

Why would I want every player to be excluded from the money list on their client?

Thank you. The steamid code is the solution.

[editline]28th September 2015[/editline]

Sometimes I amaze myself how much of an idiot I am that I can do way more complicated things than that but I couldn’t figure that out myself.

[editline]28th September 2015[/editline]

Doing that gives me this http://steamcommunity.com/sharedfiles/filedetails/?id=526527813 (obviously, after reading the code), but I want to be excluded from the highest money thing too, can’t quite figure out how to do that. Here is the code to do that.


		if totalMoney != money then
			totalMoney = Lerp( FrameTime() * 5, totalMoney, money )
		end
		
		if highBase != first.money then
			highBase = Lerp( FrameTime() * 5, highBase, first.money )
		end
		
		local tMoney = string.Comma(math.ceil(totalMoney)) or "Error Loading"
		local highMoney = string.Comma(math.ceil( highBase )) or "Error Loading"
		
		draw.SimpleText( "$"..tMoney.." ACTIVE ON SERVER", "RP_SubFontThick", 92, 137, Color( 0, 0, 0 ) )
		draw.SimpleText( "$"..highMoney.." HIGHEST MONEY - "..string.upper(first.ply:Nick()), "RP_SubFontThick", 92, 154, Color( 190, 190, 190 ) )

That code is just parsing and printing the highest money. It isn’t actually selecting the top player. If you want help with that, please post the code for it.



	local totalMoney = 0
	local highBase = 0
	local money = 0
	
	local maxBase = 0
	
	local jobs = {}
	
	for k, v in pairs( player.GetAll() ) do
--		if v:SteamID() == "STEAM_0:0:40617949" then continue end
		local vMoney = v:getDarkRPVar( "money" ) or 0
		money = money + vMoney
	end
	
	local mTable = {}
		
	for k, v in pairs( player.GetAll() ) do
--		if v:SteamID() == "STEAM_0:0:40617949" then continue end
		table.insert( mTable, { ply = v, money = v:getDarkRPVar( "money" ) or 0 } )
		
	end
	
	for k, v in pairs( team.GetAllTeams() ) do
		if team.NumPlayers( k ) > 0 then
			table.insert( jobs, v )
		end
	end
	
	table.SortByMember( mTable, "money" )
	
	local first = table.GetFirstValue( mTable )
	
	local jobTable = team.GetAllTeams()
	
	local teamTable = {}
	
	for k, v in pairs( jobTable ) do
		if v.Name != "Joining/Connecting" then
		
			local numPlayers = team.NumPlayers( k )
			
			teamTable[k] = numPlayers
			
		end
	end
	
	local maxPlayers = table.Count( player.GetAll() )
	
	local HOME_STATS = vgui.Create( "Panel", HOME_MAIN )
	HOME_STATS:SetSize( HOME_MAIN:GetWide() - 182 - 16 - 10 - 28 - 20, 290 )
	HOME_STATS:SetPos( 730, 25 )
	HOME_STATS.Paint = function( self, w, h )
		draw.RoundedBox( 2, 0, 0, w, h, Color( 239, 239, 239 ) )
		draw.RoundedBox( 2, 1, 1, w - 2, h - 2, Color( 255, 255, 255 ) )
		
		draw.SimpleText( "SERVER STATISTICS", "RP_SubFontThick", 24, 20, Color( 190, 190, 190 ) )
		
		surface.SetDrawColor( Color( 242, 242, 242 ) )
		surface.DrawLine( 24, 44, self:GetWide() - 24, 44 )
		surface.DrawLine( 24, self:GetTall() - 44, self:GetWide() - 24, self:GetTall() - 44 )
		surface.DrawLine( 24, self:GetTall() - 164, self:GetWide() - 24, self:GetTall() - 164 )
		surface.DrawLine( 24, self:GetTall() - 104, self:GetWide() - 24, self:GetTall() - 104 )
		
		surface.DrawLine( 84, 70, 84, self:GetTall() - 44 )
		
		surface.SetDrawColor( Color( 52, 152, 219 ) )
		surface.SetMaterial( Material( "elitef4menu/ribbon.png" ) )
		surface.DrawTexturedRect( 24, 80, 60, 18 )
		
		draw.SimpleText( "PLAYERS", "RP_CatFont", 30, 83, Color( 255, 255, 255 ) )
		
		draw.SimpleText( maxPlayers.." ACTIVE PLAYERS", "RP_SubFontThick", 92, 77, Color( 0, 0, 0 ) )
		draw.SimpleText( GetConVarNumber( "maxplayers" ).." PLAYER SLOTS", "RP_SubFontThick", 92, 94, Color( 190, 190, 190 ) )
		
		surface.SetDrawColor( Color( 39, 174, 96 ) )
		surface.SetMaterial( Material( "elitef4menu/ribbon.png" ) )
		surface.DrawTexturedRect( 24, 140, 60, 18 )
		
		draw.SimpleText( "ECONOMY", "RP_CatFont", 30, 143, Color( 255, 255, 255 ) )
		
		if totalMoney != money then
			totalMoney = Lerp( FrameTime() * 5, totalMoney, money )
		end
		
		if highBase != first.money then
			highBase = Lerp( FrameTime() * 5, highBase, first.money )
		end
		
		local tMoney = string.Comma(math.ceil(totalMoney)) or "Error Loading"
		local highMoney = string.Comma(math.ceil( highBase )) or "Error Loading"
		
		draw.SimpleText( "$"..tMoney.." ACTIVE ON SERVER", "RP_SubFontThick", 92, 137, Color( 0, 0, 0 ) )
		draw.SimpleText( "$"..highMoney.." HIGHEST MONEY - "..string.upper(first.ply:Nick()), "RP_SubFontThick", 92, 154, Color( 190, 190, 190 ) )

Still need help with this.

Well from what I can tell you have the lines that would exclude you from the highest money (-- if v:SteamID() == “STEAM_0:0:40617949” then continue end) commented out…

This is the part in your code where you get the players other than yourself:


local mTable = {}

for k, v in pairs( player.GetAll() ) do
  if v:SteamID() == "STEAM_0:1:40639280" then continue end
  table.insert( mTable, { ply = v, money = 0 } )
end

I’ve changed it so it just prints the names of all players instead of adding them to a table. Run this on your server. If this code prints your name, either your SteamID isn’t STEAM_0:1:40639280 or you have some crazy weird shit going on.


for k, v in pairs( player.GetAll() ) do
  if v:SteamID() == "STEAM_0:1:40639280" then continue end
  print ply:Nick()
end