I made a "DListView" and I want to make a new line for each VIP. I'm trying to add a line with the information "Name, SteamID, Amount of Months Issued, Time Left" for each VIP. How would I go about doing this? Use this:
[lua]
table.insert( VIPList, { VIPList.Name = v:Name(), VIPList.SteamID = v:SteamID(), VIPList.Time = months, --VIPList.TimeLeft =
} )
local DermaListView = vgui.Create("DListView")
DermaListView:SetParent(DermaPanel)
DermaListView:SetPos(25, 50)
DermaListView:SetSize(450, 625)
DermaListView:SetMultiSelect(false)
DermaListView:AddColumn("Name")
DermaListView:AddColumn("SteamID")
DermaListView:AddColumn("Amount of Months")
DermaListView:AddColumn("Time Left")
[/lua]
Another question that most people probably can't answer, and if you can't don't but please answer first one.
First of all, I hope I've done this correctly, if not, don't hesitate to correct! Anyways, I got this table that I want to insert so I can make a list of VIPs and shit. But the thing is, I need help finding out how long the cron has left... Anyone got any ideas?
[lua]
VIPList = {}
cron.RegisterJob( "unvip", function( sid )
v:SetUserGroup( "user" )
PrintMessage( HUD_PRINTTALK, v:Name().."'s VIP has expired and revoked." )
end )
local function addVIP( ply, text )
local sep = string.Explode( " ", text )
if sep[1] == ("!ad" or "!add" or "!addv" or "!addvi")
draw.SimpleText( "!addvip <name> <# of months>", "Trebuchet20", 130, ScrH()*0.827, Color(0,0,0,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
end
if sep[1] == "!addvip" and ply:IsUserGroup( "owner" ) then
local months = tonumber( sep[3] )
if not months then return ply:PrintMessage( HUD_PRINTTALK, "Invalid amount of months." ) end
local name = table.concat( sep, " ", 2 )
for k,v in pairs( player.GetAll() ) do
if v:Name():lower():find( name:lower() ) then
v:SetUserGroup( "VIP" )
local t = os.date( "*t" )
local conf = {
Minutes = t.min,
Hours = t.hour,
Days = t.day,
Months = (t.month%12 + months)
}
cron.Add( "unvip_" .. v:SteamID(), conf, "unvip", v:SteamID() )
table.insert( VIPList, { VIPList.Name = v:Name(), VIPList.SteamID = v:SteamID(), VIPList.Time = months, --VIPList.TimeLeft =
} )
PrintMessage( HUD_PRINTTALK, ply:Name() .. " made player ".. v:Name() .. " a VIP for "..months.." months." )
break
end
end
end
end
hook.Add ( "PlayerSay", "addVIP", addVIP )
[/lua]
About the DListView (I haven't tested):
[lua]
-- Global Table
VIPList = {}
-- adding a new vip(sent through usermessage?)
-- I'M ASSUMING YOU ALREADY HAVE "ply" VARIABLE, WHICH IS A PLAYER ENTITY
local newvip = {}
newvip["Name"] = ply:GetName()
newvip["SteamID"] = ply:SteamID()
newvip["Months"] = months
newvip["TimeLeft"] = ??
table.insert(VIPList, newvip)
local DermaListView = vgui.Create("DListView", DermaPanel)
DermaListView:SetPos(25, 50)
DermaListView:SetSize(450, 625)
DermaListView:SetMultiSelect(false)
DermaListView:AddColumn("Name")
DermaListView:AddColumn("SteamID")
DermaListView:AddColumn("Amount of Months")
DermaListView:AddColumn("Time Left")
for k,v in pairs(VIPList) do
DermaListView:AddLine(v.Name, v.SteamID, v.Months, v.TimeLeft)
end
[/lua]
Do you know how to check if they click one of the columns?
[b][url=http://wiki.garrysmod.com/?title=DListView.OnClickLine]DListView.OnClickLine [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
I believe that is it. Correct me if I am wrong.
Okay, so I have that, but after thinking about it, I have no idea what to do next. I want to check if a line is chosen and a button is pressed, then it does something... But I have no idea how to start, mind helping?
like this?
[lua]
...
local button = vgui.Create("DButton", DermaPanel)
button:SetTitle("Info")
button:SetPos() -- Your pos
button:SetSize() -- Your size
button.DoClick = function(btn)
local id = DermaListView:GetSelectedLine() -- Getting the line id
print("Test with: "..VIPList[id].Name.."\n")
end
...
[/lua]
[QUOTE=Athos;28085121]like this?
[lua]
...
local button = vgui.Create("DButton", DermaPanel)
button:SetTitle("Info")
button:SetPos() -- Your pos
button:SetSize() -- Your size
button.DoClick = function(btn)
local id = DermaListView:GetSelectedLine() -- Getting the line id
print("Test with: "..VIPList[id].Name.."\n")
end
...
[/lua][/QUOTE]
That is exactly what I want. Thank you! If I had known he function to get the selected line I woulda tried myself. . .
Sorry, you need to Log In to post a reply to this thread.