Hello guys,
Input:
local memid = Player's UniqueID in string format
I'm converting tables to strings to stream --> client/server with the net library
After clicking on 'Promote Member' in the frame, it sends the specific player's uniqueid to the server (see code below)
[code]
net.Receive("gangPromoteMember", function(len, client)
if not IsValid(client) then return end
local memid = net.ReadString()
client.GangMembers = client.GangMembers or {}
client.GangOfficers = client.GangOfficers or {}
if table.HasValue(client.GangMembers, memid) then
table.remove(client.GangMembers, memid)
table.insert(client.GangOfficers, memid)
timer.Simple(2, function()
net.Start("_RefreshGangData")
net.WriteString(string.Implode(",", client.GangMembers))
net.WriteString(string.Implode(",", client.GangOfficers))
net.Send(client)
end)
else
GAMEMODE:Notify(client, 1, 4, "Invalid argument!")
end
end)
[/code]
After some checks it's converting the whole table to a string and sending it to the client again. (see code below)
[code]
net.Receive("_RefreshGangData", function(len)
LocalPlayer().GangMembers = string.Explode(",", net.ReadString())
LocalPlayer().GangOfficers = string.Explode(",", net.ReadString())
end)
[/code]
When I open the menu now, the player's uniqueid is in the Officer's DListView, but also still in the Member's DListView.
Someone knows how to fix this? I already tried to clear the DListView when you press the 'Promote Member'-button.
First of all, use
[code]
net.Start("_RefreshGangData")
net.WriteTable(client.GangMembers)
net.WriteTable(client.GangOfficers)
net.Send(client)
// Receive
net.Receive("_RefreshGangData", function(len)
LocalPlayer().GangMembers = net.ReadTable()
LocalPlayer().GangOfficers = net.ReadTable()
end)
[/code]
And table.remove takes itemid as second argument, not a value itself. So what you need to do is this:[code]
for id, val in pairs(client.GangMembers) do
if ( val == memid ) then table.remove(client.GangMembers, id)
end[/code]
[QUOTE=Robotboy655;40592688]And table.remove takes itemid as second argument, not a value itself. So what you need to do is this:[code]
for id, val in pairs(client.GangMembers) do
if ( val == memid ) then table.remove(client.GangMembers, id)
end[/code][/QUOTE]
Could also use table.RemoveByValue
Tested and working. Thank you both!
Sorry, you need to Log In to post a reply to this thread.