character creation CLIENT/SERVER
This commit is contained in:
136
character/cl_character.lua
Normal file
136
character/cl_character.lua
Normal file
@@ -0,0 +1,136 @@
|
||||
local selectedCharacter = false
|
||||
local camera = nil
|
||||
local camera2 = nil
|
||||
|
||||
local bannedNames = {}
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(0)
|
||||
|
||||
if NetworkIsSessionStarted() then
|
||||
TriggerServerEvent('gb-core:character:joined')
|
||||
TriggerEvent('gb-core:character:startCamera')
|
||||
TriggerEvent('gb-core:client:closeCharacterUI')
|
||||
TriggerEvent('gb-core:playerLogin')
|
||||
selectedCharacter(true)
|
||||
return
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('gb-core:character:selecting')
|
||||
AddEventHandler('gb-core:character:selecting', function()
|
||||
selectedCharacter(true)
|
||||
end)
|
||||
|
||||
getCID = function(source, cb)
|
||||
local src = source
|
||||
TriggerServerEvent('gb-core:getID', src)
|
||||
end
|
||||
|
||||
RegisterNUICallback('createCharacter', function(data)
|
||||
local characterData = data.CharacterData
|
||||
for theData, value in pairs(characterData) do
|
||||
if theData == 'firstname' or theData == 'lastname' then
|
||||
reason = verifyName(value)
|
||||
print(reason) -- Make sure this prints out correctly (comment // or remove later.)
|
||||
|
||||
if reason ~= '' then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if reason == '' then
|
||||
TriggerServerEvent('gb-core:server:createCharacter', characterData)
|
||||
end
|
||||
end)
|
||||
|
||||
function verifyName(name)
|
||||
for k, v in ipairs(bannedNames) do
|
||||
if name == v then
|
||||
local reason = 'Trying to use an inappropriate name. Please think about your decisions.'
|
||||
TriggerServerEvent('gb-admin:disconnect', reason)
|
||||
end
|
||||
end
|
||||
|
||||
local nameLength = string.len(name)
|
||||
if nameLength > 25 or nameLength < 2 then
|
||||
local reason = 'Name too short.'
|
||||
end
|
||||
|
||||
let count = 0
|
||||
for i in name:gmatch("[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-]") do
|
||||
count = count + 1
|
||||
end
|
||||
if count ~= nameLength then
|
||||
return "Your player name contains special characters. (a-z,A-Z add -)"
|
||||
end
|
||||
|
||||
local spacesInName = 0
|
||||
local spacesWithUpper = 0
|
||||
for word in string.gmatch(name, "%S+") do
|
||||
if string.match(word, "%u") then
|
||||
spacesWithUpper = spacesWithUpper + 1
|
||||
end
|
||||
|
||||
spacesInName = spacesInName + 1
|
||||
end
|
||||
|
||||
if spacesInName > 1 then
|
||||
return "Name contains more then 1 space."
|
||||
end
|
||||
|
||||
if spacesWithUpper ~= spacesInName then
|
||||
return "Name must start with a capital letter."
|
||||
end
|
||||
|
||||
return ""
|
||||
end
|
||||
|
||||
RegisterNUICallback('deleteCharacter', function(data)
|
||||
local characterData = data
|
||||
TriggerServerEvent('gb-core:deleteCharacter', characterData)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('gb-core:character:setupCharacter')
|
||||
AddEventHandler('gb-core:character:setupCharacter', fuction(data)
|
||||
GB.Functions.TriggerServerCallback('gb-core:getCharacter', function(data)
|
||||
SendNUIMessage({type = 'setupCharacters', characters = data})
|
||||
end)
|
||||
end)
|
||||
|
||||
RegisterNUICallback('selectCharacters', function(data)
|
||||
local cid = tonumber(data.cid)
|
||||
selectedCharacter(false)
|
||||
TriggerServerEvent('gb-core:character:serverSelect', cid)
|
||||
TriggerEvent('gb-core:openMenu')
|
||||
SetTimecycleModifier('default')
|
||||
SetCamActive(camera, false)
|
||||
DestroyCam(camera, false)
|
||||
end)
|
||||
|
||||
RegisterNUICallback('closeCharacter', function(data)
|
||||
selectedCharacter(false)
|
||||
end)
|
||||
|
||||
function selectedCharacter(value)
|
||||
SetNuiFocus(value, value)
|
||||
SendNUIMessage({
|
||||
type = 'characterSelect',
|
||||
status = value
|
||||
})
|
||||
selectingCharacter = false
|
||||
end
|
||||
|
||||
RegisterNetEvent('gb-core:character:startCamera')
|
||||
AddEventHandler('gb-core:character:startCamera', function()
|
||||
DoScreenFadeIn(10)
|
||||
SetTimecycleModifier('hud_def_blur')
|
||||
SetTimecycleModifierStrength(1.0)
|
||||
FreezeEntityPosition(GetPlayerPed(-1), true)
|
||||
cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", -358.56, -981.96, 286.25, 320.00, 0.00, -50.00, 90.00, false, 0)
|
||||
SetCamActive(camera, true)
|
||||
RenderScriptCams(true, false, 1, true, true)
|
||||
end)
|
||||
Reference in New Issue
Block a user