text writing/reading and setModel

So lately I came up with a great idea. I should make a Player Model Store! So I went ahead and made the derma, except I have absolutely no knowledge on text file reading/writing. If anyone could help me make a method that gets the player who clicks the Spawnicon steamid and gets what spawnicon they clicked, and if they have enough of the NWInt “money” it will log the steamid to a text file and every time the player spawns it will read that text file and if it returns with a playermodel then it will setModel the player to the playermodel in the text file. It would also be awesome if you could make it so if they already have a playermodel it would write another line in the text file with their second model and if they have two models it would allow them to set their model with a console command like colz_model 1. Wow thats a lot of stuff. Help would be greatly appreciated. Even if you do one small thing it helps me a lot.

My Derma File:
[lua]
Models = {}
Models[“models/player/Kleiner.mdl”] = {COST = 5000, NAME = “Kleiner”, DESCRIP = “Unlock your inner mingebag”}
Models[“models/player/mossman.mdl”] = {COST = 10000, NAME = “Mossman”, DESCRIP = “Be a traitor”}
Models[“models/player/alyx.mdl”] = {COST = 10000, NAME = “Alyx”, DESCRIP = “The lead of the rebel force”}
Models[“models/player/barney.mdl”] = {COST = 15000, NAME = “Barney”, DESCRIP = “Be a none-Animal Lover”}
Models[“models/player/breen.mdl”] = {COST = 50000, NAME = “Dr Breen”, DESCRIP = “Control Earth”}
Models[“models/player/odessa.mdl”] = {COST = 15000, NAME = “Odessa”, DESCRIP = “Be a fisherman”}
Models[“models/player/monk.mdl”] = {COST = 10000, NAME = “Monk”, DESCRIP = “To Ravenholm”}
Models[“models/player/eli.mdl”] = {COST = 10000, NAME = “Eli”, DESCRIP = “You are one wierd fellow”}
Models[“models/player/corpse1.mdl”] = {COST = 15000, NAME = “Corpse”, DESCRIP = “I lold”}
Models[“models/player/classic.mdl”] = {COST = 15000, NAME = “Zombie”, DESCRIP = “Brains”}
Models[“models/player/charple01.mdl”] = {COST = 20000, NAME = “Charple”, DESCRIP = “Hail to the almighty Charple”}
Models[“models/player/combine_soldier.mdl”] = {COST = 25000, NAME = “Combine Soldier”, DESCRIP = “Be awesome”}
Models[“models/player/combine_soldier_prisonguard.mdl”] = {COST = 20000, NAME = “Combine Soldier Prison Guard”, DESCRIP = “Be awesome”}
Models[“models/player/combine_super_soldier.mdl”] = {COST = 30000, NAME = “Combine Super Soldier”, DESCRIP = “Nice”}
Models[“models/player/gman_high.mdl”] = {COST = 80000, NAME = “Gman”, DESCRIP = “You are the almighty Gman”}
Models[“models/player/soldier_stripped.mdl”] = {COST = 1000, NAME = “Wierd Guy”, DESCRIP = “You are the lowest level of society”}
Models[“models/player/zombie_soldier.mdl”] = {COST = 1000000, NAME = “Zombine”, DESCRIP = “You are a zombie god if you can afford this WHOA”}
Models[“models/player/Zombiefast.mdl”] = {COST = 18000, NAME = “Fast Zombie”, DESCRIP = “Unlock your inner puff-face”}
Models[“models/player/Group01/female_01.mdl”] = {COST = 5000, NAME = “Female 1”, DESCRIP = “I lold”}
Models[“models/player/Group01/female_02.mdl”] = {COST = 5000, NAME = “Female 2”, DESCRIP = “I lold”}
Models[“models/player/Group01/female_03.mdl”] = {COST = 5000, NAME = “Female 3”, DESCRIP = “I lold”}
Models[“models/player/Group01/female_04.mdl”] = {COST = 5000, NAME = “Female 4”, DESCRIP = “I lold”}
Models[“models/player/Group01/female_05.mdl”] = {COST = 5000, NAME = “Female 5”, DESCRIP = “I lold”}
Models[“models/player/Group01/female_06.mdl”] = {COST = 5000, NAME = “Female 6”, DESCRIP = “I lold”}
Models[“models/player/Group01/female_07.mdl”] = {COST = 5000, NAME = “Female 7”, DESCRIP = “I lold”}
Models[“models/player/Group03/female_01.mdl”] = {COST = 5000, NAME = “Female 8”, DESCRIP = “I lold”}
Models[“models/player/Group03/female_02.mdl”] = {COST = 5000, NAME = “Female 9”, DESCRIP = “I lold”}
Models[“models/player/Group03/female_03.mdl”] = {COST = 5000, NAME = “Female 10”, DESCRIP = “I lold”}
Models[“models/player/Group03/female_04.mdl”] = {COST = 5000, NAME = “Female 11”, DESCRIP = “I lold”}
Models[“models/player/Group03/female_05.mdl”] = {COST = 5000, NAME = “Female 12”, DESCRIP = “I lold”}
Models[“models/player/Group03/female_06.mdl”] = {COST = 5000, NAME = “Female 13”, DESCRIP = “I lold”}
Models[“models/player/Group03/female_07.mdl”] = {COST = 5000, NAME = “Female 14”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_01.mdl”] = {COST = 5000, NAME = “Male 1”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_02.mdl”] = {COST = 5000, NAME = “Male 2”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_03.mdl”] = {COST = 5000, NAME = “Male 3”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_04.mdl”] = {COST = 5000, NAME = “Male 4”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_05.mdl”] = {COST = 5000, NAME = “Male 5”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_06.mdl”] = {COST = 5000, NAME = “Male 6”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_07.mdl”] = {COST = 5000, NAME = “Male 7”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_08.mdl”] = {COST = 5000, NAME = “Male 8”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_09.mdl”] = {COST = 5000, NAME = “Male 9”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_01.mdl”] = {COST = 5000, NAME = “Male 10”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_02.mdl”] = {COST = 5000, NAME = “Male 11”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_03.mdl”] = {COST = 5000, NAME = “Male 12”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_04.mdl”] = {COST = 5000, NAME = “Male 13”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_05.mdl”] = {COST = 5000, NAME = “Male 14”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_06.mdl”] = {COST = 5000, NAME = “Male 15”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_07.mdl”] = {COST = 5000, NAME = “Male 16”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_08.mdl”] = {COST = 5000, NAME = “Male 17”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_09.mdl”] = {COST = 5000, NAME = “Male 18”, DESCRIP = “I lold”}
Models[“models/player/gasmask.mdl”] = {COST = 30000, NAME = “Gasmask Guy”, DESCRIP = “Nice suit you have there”}
Models[“models/player/riot.mdl”] = {COST = 35000, NAME = “Riot Patrol”, DESCRIP = “Nice suit you have there”}
Models[“models/player/swat.mdl”] = {COST = 40000, NAME = “Swat”, DESCRIP = “Sir yes sir”}
Models[“models/player/urban.mdl”] = {COST = 15000, NAME = “Urban Terrorist”, DESCRIP = “Your a psycho”}
Models[“models/player/phoenix.mdl”] = {COST = 15000, NAME = “Phoenix Terrorist”, DESCRIP = “Your a psycho”}
Models[“models/player/arctic.mdl”] = {COST = 25000, NAME = “Ninja”, DESCRIP = “Nice model”}
Models[“models/player/guerilla.mdl”] = {COST = 10000, NAME = “Guerilla Terrorist”, DESCRIP = “Your a psycho”}
Models[“models/player/leet.mdl”] = {COST = 150000, NAME = “Leet Haxor”, DESCRIP = “HAX!!”}
Models[“models/player/hostage/hostage_01.mdl”] = {COST = 20000, NAME = “Citizen 1”, DESCRIP = “Your average citizen”}
Models[“models/player/hostage/hostage_02.mdl”] = {COST = 20000, NAME = “Citizen 2”, DESCRIP = “Your average citizen”}
Models[“models/player/hostage/hostage_03.mdl”] = {COST = 20000, NAME = “Citizen 3”, DESCRIP = “Your average citizen”}
Models[“models/player/hostage/hostage_04.mdl”] = {COST = 20000, NAME = “Citizen 4”, DESCRIP = “Your average citizen”}
Models[“models/player/zelda.mdl”] = {COST = 300000, NAME = “Zelda”, DESCRIP = “Hail to Zelda”}
Models[“models/player/left4dead/zoey.mdl”] = {COST = 500000, NAME = “Zoey”, DESCRIP = “Cure the world of infection”}

function SettingsFrame()
gui.EnableScreenClicker(true)

local frame = vgui.Create(“DFrame”)
frame:SetSize(510,440)
frame:SetPos(ScrW()/2 - 205,ScrH()/2 - 215)
frame:SetTitle(“Settings Menu”)
frame:SetMouseInputEnabled(true)
frame.Close = function()
frame:Remove()
gui.EnableScreenClicker(false)
end

local sheet = vgui.Create( "DPropertySheet" )
sheet:SetParent( frame )
sheet:SetPos( 5, 30 )
sheet:SetSize( 500, 400 )

local tab1 = vgui.Create( "DPanel" )
tab1:SetVisible(true)

local tab2 = vgui.Create( "DPanel" )
tab2:SetVisible(true)

//Playermodel Menu

local plist = vgui.Create("DPanelList",tab1)
plist:SetPos(40,30)
plist:SetSize(410, 325)
plist:SetSpacing( 1 )
plist:EnableHorizontal( true )
plist:EnableVerticalScrollbar( true ) 

for k,v in pairs(Models) do
	local icon = vgui.Create( "SpawnIcon", plist )
	icon:SetModel(k)
	icon:SetSize( 64, 64 )
	icon:SetToolTip("Name: " .. v.NAME .. "

Price: " … v.COST … "
Description: " … v.DESCRIP)
icon.OnMousePressed = function(mc)
local mdl = k
frame:Remove()
RunConsoleCommand(“setplayermodel”,k)
surface.PlaySound(Sound(“buttons/button14.wav”))
end
plist:AddItem(icon)
end

sheet:AddSheet( "Models", tab1, "gui/silkicons/user", false, false, "Buy a Player Model" )

end

concommand.Add( “colz_settings”, SettingsFrame )
[/lua]

My setmodel method:
[lua]
function SetPlayerModel(ply,cmd,args)
ply:ConCommand("cl_playermodel "…args[1])
gui.EnableScreenClicker(false)
end
concommand.Add(“setplayermodel”, SetPlayerModel)
[/lua]

Thank you in advance.

[lua]
function SetPlayerModel(ply,cmd,args)
ply:ConCommand("cl_playermodel "…args[1])
gui.EnableScreenClicker(false)
ply:SetPData(“model”,args[1])
end
concommand.Add(“setplayermodel”, SetPlayerModel)
[/lua]

[lua]
hook.Add(“PlayerInitialSpawn”, “RetrieveModel”, function(ply)
ply:SetModel( ply:GetPData(“model”) )
end)
[/lua]

That should do the trick, if the shop is the only way to change model.

edit : Oh right do make sure you do all of the setting and getting client side.

Thank you SO much! never knew about the PD stuff.

Did I say client side?! I mean’t server side! :geno:

Speaking of serverside and clientside…

my current updated function is:

[lua]
for k,v in pairs(Models) do
local icon = vgui.Create( “SpawnIcon”, plist )
icon:SetModel(k)
icon:SetSize( 64, 64 )
icon:SetToolTip("Name: " … v.NAME … "
Price: " … v.COST … "
Description: " … v.DESCRIP)
icon.OnMousePressed = function(mc)
if v.COST == “” then return “” end
if not ply:CanAfford(v.COST) then
Notify(ply, 1, 4, string.format(“You can’t afford that player model!”))
return “”
end
ply:AddMoney(-v.COST)
frame:Remove()
RunConsoleCommand(“setplayermodel”,k)
surface.PlaySound(Sound(“buttons/button14.wav”))
Notify(ply, 1, 4, string.format(“Thank you for using the Colzdragon Player Model Store.”))
end
plist:AddItem(icon)
end
[/lua]

It gives the error ply = nil. I know its because its clientside. How would I go about making this work. I mean making it serverside?

Make serverside console command and have them execute it on purchase with an argument of the model.

Thanks, let me try that I will edit my post with results.

[editline]03:06AM[/editline]

Now it works without errors, but my playermodel isn’t being changed (I typed cl_playermodel in console and it shows the model directory for the model I clicked) before it worked. Also another thing is it doesn’t check to make sure you have enough money, or it doesn’t take money.

Here is my updated derma for k,v in pairs function and my update setmodel function in order

[lua]
for k,v in pairs(Models) do
local icon = vgui.Create( “SpawnIcon”, plist )
icon:SetModel(k)
icon:SetSize( 64, 64 )
icon:SetToolTip("Name: " … v.NAME … "
Price: " … v.COST … "
Description: " … v.DESCRIP)
icon.OnMousePressed = function(mc)
frame:Remove()
RunConsoleCommand(“setplayermodel”,k)
surface.PlaySound(Sound(“buttons/button14.wav”))
end
plist:AddItem(icon)
end
[/lua]

[lua]
function SetPlayerModel(ply,cmd,args)
for k,v in pairs(Models) do
if v.COST == “” then return “” end
if not ply:CanAfford(v.COST) then
Notify(ply, 1, 4, string.format(“You can’t afford that player model!”))
return “”
end
ply:AddMoney(-v.COST)
ply:ConCommand("cl_playermodel "…args[1])
gui.EnableScreenClicker(false)
ply:SetPData(“model”,args[1])
Notify(ply, 1, 4, string.format(“Thank you for using the Colzdragon Player Model Store.”))
end
end
concommand.Add(“setplayermodel”, SetPlayerModel)
[/lua]

Any help?

To set the player’s model, do ply:SetModel(“model/path”)
:eng101:

As for CanAfford and AddMoney are you sure you’ve defined them in the metatable of Player?

(Serverside)
[lua]
function WriteData(player, cmd, args)
file.Write(“ModelStore/”…tostring(args[0])…".txt", tostring(args[0])…" "…tostring(args[1])
end
concommand.Add(“WriteData”, WriteData)
[/lua]

If that’s derma code, it’s clientside. Also, for your other task:

(Serverside)
[lua]
function GetModel(ply)
if file.Exists(“ModelStore/”…ply:SteamID()…".txt") then
local data = file.Read(“ModelStore/”…ply:SteamID()…".txt")
data = string.Explode(" ", data)
ply:ConCommand("setplayermodel "…data[2])
else
ply:ConCommand(“setplayermodel DEFAULTMODEL”)
end
end
hook.Add(“PlayerInitialSpawn”, “GetModel”, GetModel)
[/lua]

Not guaranteed to work, but that’s a rough idea on how it should work, if Lua chooses to work with my way of thinking.

Tryed it. Doesn’t work for some reason. hmmmm

I currently have:

[lua]
for k,v in pairs(Models) do
local icon = vgui.Create( “SpawnIcon”, plist )
icon:SetModel(k)
icon:SetSize( 64, 64 )
icon:SetToolTip("Name: " … v.NAME … "
Price: " … v.COST … "
Description: " … v.DESCRIP)
icon.OnMousePressed = function(mc)
if not LocalPlayer():CanAfford(v.COST) then
Notify(LocalPlayer(), 1, 4, string.format(“You can’t afford that player model!”))
return “”
end
LocalPlayer():AddMoney(-v.COST)
frame:Remove()
RunConsoleCommand(“changeplayermodel”,k)
RunConsoleCommand(“WriteData”,LocalPlayer():SteamID(), k)
surface.PlaySound(Sound(“buttons/button14.wav”))
end
plist:AddItem(icon)
end
[/lua]

and:

[lua]
function ChangePlayerModel(ply,cmd,args)
for k,v in pairs(Models) do
gui.EnableScreenClicker(false)
end
end
concommand.Add(“changeplayermodel”, ChangePlayerModel)

–hook.Add(“PlayerSpawn”, “RetrieveModel”, function(ply)
– ply:SetModel( ply:GetPData(“model”) )
–end)

function WriteData(player, cmd, args)
file.Write(“ModelStore/”…tostring(args[0])…".txt", tostring(args[0])…" "…tostring(args[1])
end
concommand.Add(“WriteData”, WriteData)

function GetModel(ply)
if file.Exists(“ModelStore/”…ply:SteamID()…".txt") then
local data = file.Read(“ModelStore/”…ply:SteamID()…".txt")
data = string.Explode(" ", data)
ply:ConCommand("changeplayermodel "…data[2])
else
ply:ConCommand(“changeplayermodel male01”)
end
end
hook.Add(“PlayerInitialSpawn”, “GetModel”, GetModel)
[/lua]

colz_settings isn’t even loaded as a console command.
Also, how would I go about enforcing this. Like. You have to buy that playermodel to use the changeplayermodel --blah-- command. Except you can’t change your model to any other things?

EDIT:

DarkRP\gamemode\vgui/cl_settings.lua: 3: ‘]’ expected near ‘=’
yes theres a space there. Otherwise it would make an :3 smiley

Line 3:


Models["models/player/mossman.mdl"] = {COST = 10000, DIR = "mossman", NAME = "Mossman", DESCRIP = "Be a traitor"}

For the enforcing bit, I’d do the same thing in your setmodel function, just:

[lua]//The following is in a serverside script, not a clientside.
function WriteData(player, cmd, args)
if player:CanAfford() then
file.Write(“ModelStore/”…tostring(args[0])…".txt", tostring(args[0])…" "…tostring(args[1])
end
end
concommand.Add(“WriteData”, WriteData)[/lua]

Something like that. On another note, what is “colz_settings” supposed to be? I don’t see a concommand named that.

I didn’t post the whole file, I just posted the one for statement. Heres the whole file:

[lua]
Models = {}
Models[“models/player/Kleiner.mdl”] = {COST = 5000, NAME = “Kleiner”, DESCRIP = “Unlock your inner mingebag”}
Models[“models/player/mossman.mdl”] = {COST = 10000, NAME = “Mossman”, DESCRIP = “Be a traitor”}
Models[“models/player/alyx.mdl”] = {COST = 10000, NAME = “Alyx”, DESCRIP = “The lead of the rebel force”}
Models[“models/player/barney.mdl”] = {COST = 15000, NAME = “Barney”, DESCRIP = “Be a none-Animal Lover”}
Models[“models/player/breen.mdl”] = {COST = 50000, NAME = “Dr Breen”, DESCRIP = “Control Earth”}
Models[“models/player/odessa.mdl”] = {COST = 15000, NAME = “Odessa”, DESCRIP = “Be a fisherman”}
Models[“models/player/monk.mdl”] = {COST = 10000, NAME = “Monk”, DESCRIP = “To Ravenholm”}
Models[“models/player/eli.mdl”] = {COST = 10000, NAME = “Eli”, DESCRIP = “You are one wierd fellow”}
Models[“models/player/corpse1.mdl”] = {COST = 15000, NAME = “Corpse”, DESCRIP = “I lold”}
Models[“models/player/classic.mdl”] = {COST = 15000, NAME = “Zombie”, DESCRIP = “Brains”}
Models[“models/player/charple01.mdl”] = {COST = 20000, NAME = “charple01”, DESCRIP = “Hail to the almighty Charple”}
Models[“models/player/combine_soldier.mdl”] = {COST = 25000, NAME = “Combine Soldier”, DESCRIP = “Be awesome”}
Models[“models/player/combine_soldier_prisonguard.mdl”] = {COST = 20000, NAME = “Combine Soldier Prison Guard”, DESCRIP = “Be awesome”}
Models[“models/player/combine_super_soldier.mdl”] = {COST = 30000, NAME = “Combine Super Soldier”, DESCRIP = “Nice”}
Models[“models/player/gman_high.mdl”] = {COST = 80000, NAME = “Gman”, DESCRIP = “You are the almighty Gman”}
Models[“models/player/soldier_stripped.mdl”] = {COST = 1000, NAME = “Wierd Guy”, DESCRIP = “You are the lowest level of society”}
Models[“models/player/zombie_soldier.mdl”] = {COST = 1000000, NAME = “Zombine”, DESCRIP = “You are a zombie god”}
Models[“models/player/Zombiefast.mdl”] = {COST = 18000, NAME = “Fast Zombie”, DESCRIP = “Unlock your inner puff-face”}
Models[“models/player/Group01/female_01.mdl”] = {COST = 5000, NAME = “Female 1”, DESCRIP = “I lold”}
Models[“models/player/Group01/female_02.mdl”] = {COST = 5000, NAME = “Female 2”, DESCRIP = “I lold”}
Models[“models/player/Group01/female_03.mdl”] = {COST = 5000, NAME = “Female 3”, DESCRIP = “I lold”}
Models[“models/player/Group01/female_04.mdl”] = {COST = 5000, NAME = “Female 4”, DESCRIP = “I lold”}
Models[“models/player/Group01/female_06.mdl”] = {COST = 5000, NAME = “Female 5”, DESCRIP = “I lold”}
Models[“models/player/Group01/female_07.mdl”] = {COST = 5000, NAME = “Female 6”, DESCRIP = “I lold”}
Models[“models/player/Group03/female_01.mdl”] = {COST = 5000, NAME = “Female 7”, DESCRIP = “I lold”}
Models[“models/player/Group03/female_02.mdl”] = {COST = 5000, NAME = “Female 8”, DESCRIP = “I lold”}
Models[“models/player/Group03/female_03.mdl”] = {COST = 5000, NAME = “Female 9”, DESCRIP = “I lold”}
Models[“models/player/Group03/female_04.mdl”] = {COST = 5000, NAME = “Female 10”, DESCRIP = “I lold”}
Models[“models/player/Group03/female_06.mdl”] = {COST = 5000, NAME = “Female 11”, DESCRIP = “I lold”}
Models[“models/player/Group03/female_07.mdl”] = {COST = 5000, NAME = “Female 12”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_01.mdl”] = {COST = 5000, NAME = “Male 1”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_02.mdl”] = {COST = 5000, NAME = “Male 2”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_03.mdl”] = {COST = 5000, NAME = “Male 3”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_04.mdl”] = {COST = 5000, NAME = “Male 4”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_05.mdl”] = {COST = 5000, NAME = “Male 5”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_06.mdl”] = {COST = 5000, NAME = “Male 6”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_07.mdl”] = {COST = 5000, NAME = “Male 7”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_08.mdl”] = {COST = 5000, NAME = “Male 8”, DESCRIP = “I lold”}
Models[“models/player/Group01/male_09.mdl”] = {COST = 5000, NAME = “Male 9”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_01.mdl”] = {COST = 5000, NAME = “Male 10”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_02.mdl”] = {COST = 5000, NAME = “Male 11”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_03.mdl”] = {COST = 5000, NAME = “Male 12”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_04.mdl”] = {COST = 5000, NAME = “Male 13”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_05.mdl”] = {COST = 5000, NAME = “Male 14”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_06.mdl”] = {COST = 5000, NAME = “Male 15”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_07.mdl”] = {COST = 5000, NAME = “Male 16”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_08.mdl”] = {COST = 5000, NAME = “Male 17”, DESCRIP = “I lold”}
Models[“models/player/Group03/male_09.mdl”] = {COST = 5000, NAME = “Male 18”, DESCRIP = “I lold”}
Models[“models/player/gasmask.mdl”] = {COST = 30000, NAME = “Gasmask Guy”, DESCRIP = “Nice suit you have there”}
Models[“models/player/riot.mdl”] = {COST = 35000, NAME = “Riot Patrol”, DESCRIP = “Nice suit you have there”}
Models[“models/player/swat.mdl”] = {COST = 40000, NAME = “Swat”, DESCRIP = “Sir yes sir”}
Models[“models/player/urban.mdl”] = { = 15000, NAME = “Urban Terrorist”, DESCRIP = “A terrorist”}
Models[“models/player/phoenix.mdl”] = {COST = 15000, NAME = “Phoenix Terrorist”, DESCRIP = “A Terrorist”}
Models[“models/player/arctic.mdl”] = {COST = 25000, NAME = “Ninja”, DESCRIP = “NINJA MODE”}
Models[“models/player/guerilla.mdl”] = {COST = 10000, NAME = “Guerilla Terrorist”, DESCRIP = “Wow this guy is fat”}
Models[“models/player/leet.mdl”] = {COST = 150000, NAME = “Leet Haxor”, DESCRIP = “HAX!!”}
Models[“models/player/hostage/hostage_01.mdl”] = {COST = 20000, NAME = “Citizen 1”, DESCRIP = “Your average citizen”}
Models[“models/player/hostage/hostage_02.mdl”] = {COST = 20000, NAME = “Citizen 2”, DESCRIP = “Your average citizen”}
Models[“models/player/hostage/hostage_03.mdl”] = {COST = 20000, NAME = “Citizen 3”, DESCRIP = “Your average citizen”}
Models[“models/player/hostage/hostage_04.mdl”] = {COST = 20000, NAME = “Citizen 4”, DESCRIP = “Your average citizen”}
Models[“models/player/zelda.mdl”] = {COST = 300000, NAME = “Zelda”, DESCRIP = “Hail to Zelda”}
Models[“models/player/left4dead/zoey.mdl”] = {COST = 500000, NAME = “Zoey”, DESCRIP = “Cure the world of infection”}
Models[“models/humans/Group01/billy.mdl”] = {COST = 60000, NAME = “Billy Mays”, DESCRIP = “ARE YOU ON THE BALL?”}

function SettingsFrame()
gui.EnableScreenClicker(true)

local frame = vgui.Create(“DFrame”)
frame:SetSize(510,440)
frame:SetPos(ScrW()/2 - 205,ScrH()/2 - 215)
frame:SetTitle(“Settings Menu”)
frame:SetMouseInputEnabled(true)
frame.Close = function()
frame:Remove()
gui.EnableScreenClicker(false)
end

local sheet = vgui.Create( "DPropertySheet" )
sheet:SetParent( frame )
sheet:SetPos( 5, 30 )
sheet:SetSize( 500, 400 )

local tab1 = vgui.Create( "DPanel" )
tab1:SetVisible(true)

local tab2 = vgui.Create( "DPanel" )
tab2:SetVisible(true)

//Playermodel Menu

local plist = vgui.Create("DPanelList",tab1)
plist:SetPos(40,30)
plist:SetSize(410, 325)
plist:SetSpacing( 1 )
plist:EnableHorizontal( true )
plist:EnableVerticalScrollbar( true ) 

for k,v in pairs(Models) do
	local icon = vgui.Create( "SpawnIcon", plist )
	icon:SetModel(k)
	icon:SetSize( 64, 64 )
	icon:SetToolTip("Name: " .. v.NAME .. "

Price: " … v.COST … "
Description: " … v.DESCRIP)
icon.OnMousePressed = function(mc)
frame:Remove()
RunConsoleCommand(“changeplayermodel”,k)
RunConsoleCommand(“WriteData”,LocalPlayer():SteamID(), k)
surface.PlaySound(Sound(“buttons/button14.wav”))
end
plist:AddItem(icon)
end

//Achievement Menu

local check = vgui.Create("DImage",tab2)
check:SetImage("gui/silkicons/wrench")
check:SetPos(31,330)
check:SizeToContents()

local label = vgui.Create("DLabel",tab2)
label:SetPos(70,330)
label:SetText("You've unlocked "..#AchievementIDs.." out of "..#Achievements.List.." achievements.")
label:SetSize(400,15)
label:SetTextColor(Color(0,0,0,255))

local list = vgui.Create("DListView",tab2)
list:SetPos(15,15)
list:SetSize(455, 300)

local c0 = list:AddColumn( "Achievement" ) 
local c1 = list:AddColumn( "Description" ) 
c0:SetMinWidth( 120 )
c0:SetMaxWidth( 120 )

for k,v in pairs(Achievements.List) do
	list:AddLine( v.Name, v.Desc )
end

list.OnRowSelected = function(ID,line) 
	if table.HasValue(AchievementIDs,""..Achievements.List[line].ID) then
		check:SetImage("gui/silkicons/check_on")
		label:SetText("You've unlocked this achievement.")
	else
		check:SetImage("gui/silkicons/check_off")
		label:SetText("You haven't unlocked this achievement.")
	end
end

sheet:AddSheet( "Models", tab1, "gui/silkicons/user", false, false, "Buy a Player Model" )
sheet:AddSheet( "Achievements", tab2, "gui/silkicons/star", false, false, "Your Achievements" )

end

concommand.Add( “colz_settings”, SettingsFrame )
[/lua]

And I have a whole seperate file that holds only this:

[lua]
function ChangePlayerModel(ply,cmd,args)
for k,v in pairs(Models) do
gui.EnableScreenClicker(false)
end
end
concommand.Add(“changeplayermodel”, ChangePlayerModel)

–hook.Add(“PlayerSpawn”, “RetrieveModel”, function(ply)
– ply:SetModel( ply:GetPData(“model”) )
–end)

function WriteData(player, cmd, args)
for k,v in pairs(Models) do
if player:CanAfford(v.COST) then
player:AddMoney(-v.COST)
file.Write(“ModelStore/”…tostring(args[0])…".txt", tostring(args[0])…" "…tostring(args[1])
end
end
end
concommand.Add(“WriteData”, WriteData)

function GetModel(ply)
if file.Exists(“ModelStore/”…ply:SteamID()…".txt") then
local data = file.Read(“ModelStore/”…ply:SteamID()…".txt")
data = string.Explode(" ", data)
ply:ConCommand("changeplayermodel "…data[2])
else
ply:ConCommand(“changeplayermodel male01”)
end
end
hook.Add(“PlayerInitialSpawn”, “GetModel”, GetModel)
[/lua]

You have to add console commands serverside ( so on the second file), and then you could use a usermessage to tell the client to open the menu.
Also you probably can’t do args[0]. It should start at 1.

Never mind, Spencer helped me! My tables were completely wrong!

Thanks Spencer