136 lines
4.4 KiB
Lua
136 lines
4.4 KiB
Lua
-- server/appearance.lua
|
|
print("^2[turfwar]^7 appearance.lua loaded (server)")
|
|
|
|
local function getLicense(src)
|
|
for _, id in ipairs(GetPlayerIdentifiers(src)) do
|
|
if id:sub(1, 8) == "license:" then
|
|
return id
|
|
end
|
|
end
|
|
return nil
|
|
end
|
|
|
|
local function defaultRow(license)
|
|
return {
|
|
license = license,
|
|
gender = "m",
|
|
hair_drawable = 0,
|
|
hair_texture = 0,
|
|
hair_color = 0,
|
|
hair_highlight = 0
|
|
}
|
|
end
|
|
|
|
RegisterNetEvent("turfwar:appearance:request", function()
|
|
local src = source
|
|
local license = getLicense(src)
|
|
if not license then
|
|
print(("^1[turfwar]^7 appearance: missing license for src %d"):format(src))
|
|
return
|
|
end
|
|
|
|
local row = exports.oxmysql:singleSync(
|
|
"SELECT gender, hair_drawable, hair_texture, hair_color, hair_highlight FROM turfwar_appearance WHERE license = ?",
|
|
{ license }
|
|
)
|
|
|
|
local isNew = false
|
|
|
|
if not row then
|
|
isNew = true
|
|
local def = defaultRow(license)
|
|
exports.oxmysql:insertSync(
|
|
"INSERT INTO turfwar_appearance (license, gender, hair_drawable, hair_texture, hair_color, hair_highlight) VALUES (?, ?, ?, ?, ?, ?)",
|
|
{ def.license, def.gender, def.hair_drawable, def.hair_texture, def.hair_color, def.hair_highlight }
|
|
)
|
|
row = def
|
|
end
|
|
|
|
row.isNew = isNew
|
|
TriggerClientEvent("turfwar:appearance:update", src, row)
|
|
end)
|
|
|
|
RegisterNetEvent("turfwar:appearance:setGender", function(gender)
|
|
local src = source
|
|
local license = getLicense(src)
|
|
if not license then return end
|
|
|
|
gender = (gender == "f") and "f" or "m"
|
|
|
|
exports.oxmysql:updateSync(
|
|
"UPDATE turfwar_appearance SET gender = ? WHERE license = ?",
|
|
{ gender, license }
|
|
)
|
|
|
|
local row = exports.oxmysql:singleSync(
|
|
"SELECT gender, hair_drawable, hair_texture, hair_color, hair_highlight FROM turfwar_appearance WHERE license = ?",
|
|
{ license }
|
|
)
|
|
row.isNew = false
|
|
TriggerClientEvent("turfwar:appearance:update", src, row)
|
|
end)
|
|
|
|
RegisterNetEvent("turfwar:appearance:setHair", function(drawable, texture, color, highlight)
|
|
local src = source
|
|
local license = getLicense(src)
|
|
if not license then return end
|
|
|
|
drawable = tonumber(drawable) or 0
|
|
texture = tonumber(texture) or 0
|
|
color = tonumber(color) or 0
|
|
highlight = tonumber(highlight) or color
|
|
|
|
exports.oxmysql:updateSync(
|
|
"UPDATE turfwar_appearance SET hair_drawable=?, hair_texture=?, hair_color=?, hair_highlight=? WHERE license=?",
|
|
{ drawable, texture, color, highlight, license }
|
|
)
|
|
|
|
local row = exports.oxmysql:singleSync(
|
|
"SELECT gender, hair_drawable, hair_texture, hair_color, hair_highlight FROM turfwar_appearance WHERE license = ?",
|
|
{ license }
|
|
)
|
|
row.isNew = false
|
|
TriggerClientEvent("turfwar:appearance:update", src, row)
|
|
end)
|
|
|
|
RegisterNetEvent("turfwar:appearance:setGender", function(gender)
|
|
local src = source
|
|
local license = getLicense(src)
|
|
if not license then return end
|
|
|
|
gender = (gender == "f") and "f" or "m"
|
|
|
|
exports.oxmysql:updateSync(
|
|
"UPDATE turfwar_appearance SET gender = ? WHERE license = ?",
|
|
{ gender, license }
|
|
)
|
|
|
|
local row = exports.oxmysql:singleSync(
|
|
"SELECT gender, hair_drawable, hair_texture, hair_color, hair_highlight FROM turfwar_appearance WHERE license = ?",
|
|
{ license }
|
|
)
|
|
TriggerClientEvent("turfwar:appearance:update", src, row)
|
|
end)
|
|
|
|
RegisterNetEvent("turfwar:appearance:setHair", function(drawable, texture, color, highlight)
|
|
local src = source
|
|
local license = getLicense(src)
|
|
if not license then return end
|
|
|
|
drawable = tonumber(drawable) or 0
|
|
texture = tonumber(texture) or 0
|
|
color = tonumber(color) or 0
|
|
highlight = tonumber(highlight) or color
|
|
|
|
exports.oxmysql:updateSync(
|
|
"UPDATE turfwar_appearance SET hair_drawable=?, hair_texture=?, hair_color=?, hair_highlight=? WHERE license=?",
|
|
{ drawable, texture, color, highlight, license }
|
|
)
|
|
|
|
local row = exports.oxmysql:singleSync(
|
|
"SELECT gender, hair_drawable, hair_texture, hair_color, hair_highlight FROM turfwar_appearance WHERE license = ?",
|
|
{ license }
|
|
)
|
|
TriggerClientEvent("turfwar:appearance:update", src, row)
|
|
end)
|