hii i trying to convert this script to a sql connecting.
so as far i did i add the sql thing. and my server error is
server.lua:39: attempt to index a nil value (global 'models')
models = {identifier}
RegisterServerEvent("clothes:firstspawn")
AddEventHandler("clothes:firstspawn",function()
local source = source
local identifier = getID("steam",source)
print(identifier)
if models[identifier] ~= nil then
TriggerClientEvent("clothes:spawn", source, models[identifier])
else
local default_models = {1413662315,-781039234,1077785853,2021631368,1423699487,1068876755,2120901815,-106498753,131961260,-1806291497,1641152947,115168927,330231874,-1444213182,1809430156,1822107721,2064532783,-573920724,-782401935,808859815,-1106743555,-1606864033,1004114196,532905404,1699403886,-1656894598,1674107025,-88831029,-1244692252,951767867,1388848350,1090617681,379310561,-569505431,-1332260293,-840346158}
models[identifier] = {
model = default_models[math.random(1,tonumber(#default_models))],
new = true,
clothing = {drawables = {0,0,0,0,0,0,0,0,0,0,0,0},textures = {2,0,1,1,0,0,0,0,0,0,0,0},palette = {0,0,0,0,0,0,0,0,0,0,0,0}},
props = {drawables = {-1,-1,-1,-1,-1,-1,-1,-1}, textures = {-1,-1,-1,-1,-1,-1,-1,-1}},
overlays = {drawables = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, opacity = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}, colours = {{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0}}},
}
saveModels()
TriggerClientEvent("clothes:spawn", source, models[identifier])
end
end)
RegisterServerEvent("clothes:spawn")
AddEventHandler("clothes:spawn",function()
local source = source
local identifier = getID("steam",source)
TriggerClientEvent("clothes:spawn", source, models[identifier])
end)
RegisterServerEvent("clothes:loaded")
AddEventHandler("clothes:loaded",function()
-- Give weapons etc
end)
RegisterServerEvent("clothes:save")
AddEventHandler("clothes:save",function(player_data)
local source = source
local identifier = getID("steam",source)
models[identifier] = player_data
saveModels()
-- Give weapons etc
end)
function loadModels()
models = LoadResourceFile(GetCurrentResourceName(), "models.txt") or "[]"
models = json.decode(models)
end
function saveModels()
MySQL.Sync.execute("UPDATE modelmenu SET mpmodel = 0,model=@model, mask=@mask, mask_txt=@mtxt, shirt=@shirt, shirt_txt=@stxt, shoe=@shoe, shoe_txt=@shtxt, pants=@pants, pants_txt=@ptxt, helmet=@helmet, helmet_txt=@htxt, glasses=@glasses, glasses_txt=@gtxt, percing=@piercing, percing_txt=@petxt WHERE identifier=@user",{['@model']= model,['@mask']= user.mask,['@mtxt']= user.mask_txt,['@shirt']= user.shirt,['@stxt']= user.shirt_txt,['@shoe']= user.shoe,['@shtxt']= user.shoe_txt,['@pants']= user.pants,['@ptxt']= user.pants_txt,['@helmet']= user.helmet,['@htxt']= user.helmet_txt,['@glasses']= user.glasses,['@gtxt']= user.glasses_txt,['@piercing']= user.piercing,['@petxt']= user.piercing_txt,['@user']= identifier})
end
function getID(type, source)
for k,v in ipairs(GetPlayerIdentifiers(source)) do
if string.sub(tostring(v), 1, string.len("steam:")) == "steam:" and (type == "steam" or type == 1) then
return v
elseif string.sub(tostring(v), 1, string.len("license:")) == "license:" and (type == "license" or type == 2) then
return v
elseif string.sub(tostring(v), 1, string.len("ip:")) == "ip:" and (type == "ip" or type == 3) then
return v
end
end
return nil
end
loadModels()
line 39 The error
RegisterServerEvent("clothes:save")
AddEventHandler("clothes:save",function(player_data)
local source = source
local identifier = getID("steam",source)
**models[identifier] = player_data** this is the error...
saveModels()
-- Give weapons etc
end)