# esx\_kasharacter

### Guide how to edit rcore\_identity to fit esx\_kascharacter

**esx\_kasharacter/server/main.lua** *When user will try to create new character start rcore\_identity*

```lua
RegisterServerEvent("kashactersS:CharacterChosen")
AddEventHandler('kashactersS:CharacterChosen', function(charid, ischar)
    local src = source
    local new = true
    local spawn = {}

    SetLastCharacter(src, tonumber(charid))
    SetCharToIdentifier(GetRockstarID(src), tonumber(charid))

    if ischar == "true" then
        new = false
        spawn = GetSpawnPos(src)
        
--Spawn only when a character is created
        TriggerClientEvent("kashactersC:SpawnCharacter", src, spawn, new)
    else
        --start rcore_identity register
        TriggerClientEvent('rcore_identity:startRegistration', src)

        --Old code
    --TriggerClientEvent('skinchanger:loadDefaultModel', src, true, cb)
        --spawn = { x = 195.55, y = -933.36, z = 29.90 } -- DEFAULT SPAWN POSITION
    end
end)
```

**rcore\_identity/server/main.lua** *Comment sending startRegistration*

```lua
AddEventHandler(Config.ESX['esx:playerLoaded'], function(_source)
    local xPlayer = ESX.GetPlayerFromId(_source)

    getUser(xPlayer, function(user)
        if user ~= nil then
            if #Config.FieldsEmpty == 0 then
                dbg.critical('Register cannot start cause you have empty Config.FiedlsEmpty field!')
            end

            local allFields = true
            for _, field in pairs(Config.FieldsEmpty) do
                local data = user[field];
                if nullOrEmpty(data) then
                    allFields = false
                    break
                end
            end

            if allFields == false then
                sendCustomDiscordMessage(SConfig.DiscordWebhook, 'User register', string.format('Player %s is now register!', xPlayer.getName()), 0x00FF00, 'rcore_identity')
                --TriggerClientEvent(triggerName('startRegistration'), _source)
            else
                sendDiscordMessage(SConfig.DiscordWebhook, 'User login', string.format('Player %s is now logged in!', xPlayer.getName()), 0x00FFFF, 'rcore_identity')
                updateXPlayer(xPlayer, user) -- Update xPlayer values
                TriggerClientEvent(triggerName('loadCharacter'), _source, json.decode(user.skin))
            end
        else
            dbg.critical('Trying to open registration even that users row does not exists yet!')
            sendCustomDiscordMessage(SConfig.DiscordWebhook, 'User register', string.format('Player %s is now register!', xPlayer.getName()), 0x00FF00, 'rcore_identity')
            --TriggerClientEvent(triggerName('startRegistration'), _source)
        end
    end)
end)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.rcore.cz/paid-resources/rcore_identity/esx-kasharacter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
