Hi! im wanting to save a players model that they choose in a menu using meta and that and setting it, this doesnt seem to work, can someone point me in the right direction?
my meta file:
[CODE]
local meta - FindMetaTable("Player")
function meta:SetPModel(model)
self:SetNetworkedString( "PModel", model )
self:SavePModel()
end
function meta:SavePModel()
local PModel = self:GetPModel()
self:SetPData("PModel", PModel)
end
function meta:GetPModel()
return self:GetNetworkedString( "PModel" )
end
[/CODE]
setting their model: ( I Have A Table Of Around 100 Random Models Aswell So....
[CODE]
function SetClothes( ply )
local PModels = ply:GetPModel()
local ChosenPModel = math.random( DefaultModels )
if PModels == nil then
ply:SetPModel( ChosenPModel )
ply:SetModel( PModels )
ply:SavePModels()
else
ply:SetModel( PModels )
end
end
hook.Add( "PlayerInitialSpawn", "settingClothes", SetClothes )
[/CODE]
What doesn't work? If you join the server the "PModel" NWString doesn't exist, you need to hook.Add( "PlayerInitialSpawn" and from there get his PData, and put in the NWString.
And about setting if his PModel is nil, not sure if math.random( table ) works, try table[ math.random( 1, #table ) ].
[QUOTE=Busan1;47704191]What doesn't work? If you join the server the "PModel" NWString doesn't exist, you need to hook.Add( "PlayerInitialSpawn" and from there get his PData, and put in the NWString.[/QUOTE]
ive already added a hook (bottom of setting their model)
[editline]11th May 2015[/editline]
also it brings up this error:
[CODE]
[ERROR] gamemodes/gt/gamemode/init.lua:795: attempt to call method 'GetPModel' (a nil value)
1. fn - gamemodes/gt/gamemode/init.lua:795
2. unknown - addons/ulib/lua/ulib/shared/hook.lua:108
[/CODE]
[QUOTE=TroulesHere;47704196]ive already added a hook (bottom of setting their model)[/QUOTE]
Yes, which calls this function:
function meta:GetPModel()
return self:GetNetworkedString( "PModel" )
end
You need to, on InitialSpawn, get his saved model GetPData, if its nil then give him a random model, once he picks a model you SetPData.
[CODE]
function SetClothes( ply )
local CurModel = ply:GetPData("PModel")
if CurModel == nil then
ply:SetModel( DefaultClothes[1] )
else
ply:SetModel( CurModel )
end
end
hook.Add( "PlayerInitialSpawn", "settingClothes", SetClothes )
[/CODE]
like that?
[QUOTE=TroulesHere;47704225][CODE]
function SetClothes( ply )
local CurModel = ply:GetPData("PModel")
if CurModel == nil then
ply:SetModel( DefaultClothes[1] )
else
ply:SetModel( CurModel )
end
end
hook.Add( "PlayerInitialSpawn", "settingClothes", SetClothes )
[/CODE]
like that?[/QUOTE]
yes
[QUOTE=Busan1;47704244]yes[/QUOTE]
ok il see if that works...
[editline]11th May 2015[/editline]
yeah thanks that worked, thanks for guiding me on that one!
[editline]11th May 2015[/editline]
ok it doesnt save on disconnect, ive added it to save but says its a nil value so would i beable to do this...
[CODE]
function SetClothes( ply )
local CurModel = ply:GetPData("PModel")
if CurModel == nil then
ply:SetModel( DefaultClothes[1] )
print(" <<< Creating New Player Character >>>")
print(" <<<< New Player Character Created >>>>")
ply:SetPModel( CurModel )
else
ply:SetModel( CurModel )
print(" <<< Loading Player Character >>>")
print(" <<<< Player Character Loaded >>>>")
end
end
hook.Add( "PlayerInitialSpawn", "settingClothes", SetClothes )
[/CODE]
^^ also ive added a print function to notify me through console
[editline]11th May 2015[/editline]
never mind i fixed it, heres my code for anyone intrested
[CODE]
hook.Add( "PlayerDisconnected", "SaveModel", function( ply )
ply:SetPData("PModel", ply:GetModel())
print(ply:Nick() .. " Disconnected Saving Model To SQLite")
end )
function SetClothes( ply )
local DefModel = table[ math.random( 1, #DefaultClothes ) ]
local CurModel = ply:GetPData("PModel")
if CurModel == nil then
ply:SetModel( DefModel )
print(" <<< Creating New Player Character >>>")
print(" <<<< New Player Character Created >>>>")
ply:SetPData("PModel", DefModel )
else
ply:SetModel( CurModel )
print(" <<< Loading Player Character >>>")
print(" <<<< Player Character Loaded >>>>")
end
end
hook.Add( "PlayerInitialSpawn", "settingClothes", SetClothes )
[/CODE]
Sorry, you need to Log In to post a reply to this thread.