creation clientside
local alreadyCreated = false
RegisterNUICallback('create-new', function(data, cb)
TriggerEvent('esx_selezione:closemenu')
if not alreadyCreated then
TriggerServerEvent('esx_selezione:creaPersonaggio', data)
end
cb('ok')
end)
Creation Server Side
RegisterServerEvent('esx_selezione:creaPersonaggio')
AddEventHandler('esx_selezione:creaPersonaggio', function(data)
local dati = data
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local identifier = xPlayer.getIdentifier()
local money = 1000
local bank = 3000
local black_money = 0
local job = "unemployed"
local gang = "none"
local job_grade = 0
local gang_grade = 0
local loadout = '[]'
local position = json.encode({ x = -257.88, y = -980.68, z = 31.22 })
local jail = false
local jail_time = 0
local isDead = false
local phone_number = math.random(10000, 99999)
local phone_contacts = '{}'
local inventory = '{}'
local licenze = '{}'
local slot = 0
local skin = json.encode({sex = 0, face = 0, skin = 0, wrinkles = 0, wrinkle_thickness = 0, beard_type = 0, beard_size = 0, beard_color_1 = 0, beard_color_2 = 0, hair_1 = 0, hair_2 = 0, hair_color_1 = 0, hair_color_2 = 0, eyebrow_size = 0, eyebrow_type = 0, eyebrow_color_1 = 0, eyebrow_color_2 = 0, makeup_type = 0, makeup_thickness = 0, makeup_color_1 = 0, makeup_color_2 = 0, lipstick_type = 0, lipstick_thickness = 0, lipstick_color_1 = 0, lipstick_color_2 = 0, ear_accessories = -1, ear_accessories_color = 0, tshirt_1 = 0, tshirt_2 = 0, torso_1 = 0, torso_2 = 0, decals_1 = 0, decals_2 = 0, arms = 0, pants_1 = 0, pants_2 = 0, shoes_1 = 0, shoes_2 = 0, mask_1 = 0, mask_2 = 0, bproof_1 = 0, bproof_2 = 0, chain_1 = 0, chain_2 = 0, helmet_1 = -1, helmet_2 = 0, glasses_1 = 0, glasses_2 = 0, bag = 0, bag_color = 0})
MySQL.Async.fetchAll('SELECT `slot` FROM `characters` WHERE identifier = @identifier', {['@identifier'] = identifier}, function(result)
Wait(1)
if result ~= 1 and result ~= 2 and result ~= 3 then
slot = 1
end
for i = 1, #result do
if i == 2 and (result[i].slot == 2 or result[i].slot == 3) then
slot = 1
else
slot = i+1
end
end
MySQL.Async.execute('UPDATE `users` SET `firstName` = @firstName, `lastName` = @lastName, `dateOfBirth` = @dateOfBirth, `sex` = @sex, `money` = @money, `bank` = @bank, `black_money` = @black_money, `skin` = @skin, `job` = @job, `job_grade` = @job_grade, `gang` = @gang, `gang_grade` = @gang_grade, `loadout` = @loadout, `inventory` = @inventory, `position` = @position, `jail` = @jail, `isDead` = @isDead, `phone_number` = @phone_number, `contatti` = @phone_contacts, `licenze` = @licenze, `slot` = @slot WHERE `identifier` = @identifier',
{
['@identifier'] = identifier,
['@firstName'] = dati.firstName,
['@lastName'] = dati.lastName,
['@dateOfBirth'] = dati.dateOfBirth,
['@sex'] = dati.sex,
['@money'] = money,
['@bank'] = bank,
['@black_money'] = black_money,
['@skin'] = skin,
['@job'] = job,
['@job_grade'] = job_grade,
['@gang'] = gang,
['@gang_grade'] = gang_grade,
['@loadout'] = loadout,
['@position'] = position,
['@jail'] = jail,
['@jail_time'] = jail_time,
['@isDead'] = isDead,
['@inventory'] = inventory,
['@phone_number'] = phone_number,
['@phone_contacts'] = phone_contacts,
['@licenze'] = licenze,
['@slot'] = slot
})
MySQL.Async.execute('INSERT INTO `characters` (`identifier`, `firstName`, `lastName`, `dateOfBirth`, `sex`, `money`, `bank`, `black_money`, `skin`, `job`, `job_grade`, `gang`, `gang_grade`, `loadout`, `inventory`, `position`, `jail`, `isDead`, `slot`, `phone_number`, `phone_contacts`, `licenze`) VALUES (@identifier, @firstName, @lastName, @dateOfBirth, @sex, @money, @bank, @black_money, @skin, @job, @job_grade, @gang, @gang_grade, @loadout, @inventory, @position, @jail, @isDead, @slot, @phone_number, @phone_contacts, @licenze)',
{
['@identifier'] = identifier,
['@firstName'] = dati.firstName,
['@lastName'] = dati.lastName,
['@dateOfBirth'] = dati.dateOfBirth,
['@sex'] = dati.sex,
['@money'] = money,
['@bank'] = bank,
['@black_money'] = black_money,
['@skin'] = skin,
['@job'] = job,
['@job_grade'] = job_grade,
['@gang'] = gang,
['@gang_grade'] = gang_grade,
['@loadout'] = loadout,
['@position'] = position,
['@status'] = status,
['@jail'] = jail,
['@jail_time'] = jail_time,
['@isDead'] = isDead,
['@phone_number'] = phone_number,
['@phone_contacts'] = phone_contacts,
['@licenze'] = phone_contacts,
['@inventory'] = inventory,
['@slot'] = slot
})
wait(1)
local nuovo = {}
local nome = dati.firstName
local cognome = dati.lastName
local pos = json.decode(position)
local soldi = money
local banca = bank
local skin = json.decode(skin)
local job = job
local job_grade = job_grade
local gang = gang
local gang_grade = gang_grade
local loadout = loadout
local inventory = inventory
local black = black_money
local jail_time = jail_time
local phone_number = phone_number
local morto = isDead
local pers = dati.slot
local prig = jail
table.insert(nuovo, {id = identifier, nome = nome, cognome = cognome, inventario = inventory, black = black, tempo = jail_time, numero = phone_number, attuale = pers, pos = pos, soldi = soldi, banca = banca, skin = skin, job = job, job_grade = job_grade, gang = gang, gang_grade = gang_grade, armi = loadout, morto = morto, prig = prig})
TriggerClientEvent('esx_selezione:cambiaPersonaggio', _source, nuovo, true)
end)
end)
when i create a new character… the sql in cmd gets repeated like 10 to 500 times instead of 1