Problems with tables

Hey,
I’m working on a script that allows me to add a player to a table through a chat command. The adding function works fine but I’ve problems with the removing function.
The removing function doesn’t remove the player out of the table. :confused:

Perhaps you can help me. So here’s a snip of my script:

[lua]
if CLIENT then

// Initialize customer Table
local customer = {}
local PlayerName


function AddCustomer( data )
	PlayerName = data:ReadString()
	
	local NewCustomer = {}
	NewCustomer["Name"] = PlayerName
	table.insert(customer, NewCustomer)
	PrintTable( customer )
end
usermessage.Hook( "add_customer", AddCustomer )


function RemoveCustomer( data )
	PlayerName = data:ReadString()
	
	for k,v in pairs( customer ) do
		if( v.Name == PlayerName ) then
			table.remove(customer, k)
		end
	end
end
usermessage.Hook( "remove_customer", RemoveCustomer )

end
[/lua]

BTW: I use this table in the clientside code because I need the table for a derma menu.

Pls help me! :slight_smile:

This code seems fine, show the server-side part where you send the usermessage for both adding and removing.

Serverside Part:
[lua]
if SERVER then
print( “OMenu - Loading serverside stuff…” )
print( “OMenu - Checking the ConVars…” )

// Create some convars to handle options
if !ConVarExists("omenu_enable") then
	CreateConVar("omenu_enable", '1', FCVAR_REPLICATED + FCVAR_NOTIFY + FCVAR_ARCHIVE, "Enable(1)/Disable(0) Order Menu Addon (Default: 1)")
end


function AddPlayer( caller )
	
	if (GetConVarNumber("omenu_enable") == 0) then return end
	
	for k, v in pairs(player.GetAll()) do
		
		local t = v:Team()
		if not( t == TEAM_GUN ) then return end
		
		caller = tostring( caller )
		v:PrintMessage( HUD_PRINTTALK, caller.." needs your help!")
		
		umsg.Start("add_customer")
			umsg.String( caller )
		umsg.End()
		
	end
end


function OpenOrderMenu( ply )
	
	if (GetConVarNumber("omenu_enable") == 0) then return end
		
	local t = ply:Team()
	if not( t == TEAM_GUN ) then return end
		
	umsg.Start("call_vgui", ply)
	umsg.End()
end


function RemovePlayer( Caller )
	
	if (GetConVarNumber("omenu_enable") == 0) then return end
	
	caller = tostring( caller )
	
	umsg.Start("remove_customer")
		umsg.String( caller )
	umsg.End()
end


function ChatCall( ply, text, team )
	if( string.lower( text ) == "!engineer" ) then
		AddPlayer( ply:Nick() )
		ply:PrintMessage( HUD_PRINTTALK, "You are now on the order list. To remove yourself type \"!remove\" in Chat.")
	end
	
	if( string.lower( text ) == "!ordermenu" ) then
		OpenOrderMenu( ply )
	end
	
	if( string.lower( text ) == "!remove" ) then
		RemovePlayer( ply:Nick() )
		ply:PrintMessage( HUD_PRINTTALK, "Now you are not longer on the order list.")
	end
end
hook.Add( "PlayerSay", "ChatCall", ChatCall )

end
[/lua]

But I think the problem is in the clientside part because the functions will be called.

[lua]
function RemovePlayer( Caller )
[/lua]
Should be
[lua]
function RemovePlayer( caller )
[/lua]

OMG! That was the problem! Thanks!
I think the thread can be closed. ^^