Logout for kashacters/Unload from server

I’m trying to add a logout feature for my kashacters script. I have gotten to the point where it brings the user back to the character selection. But when they select their character & spawn back, it still has them as their previous character.

it is possible, with my framework i have it setup so when the player issues a command it basically unloads him from everything (acting like he disconnected from the server) then places him back into the character selection screen from there he can select a new character and the system then loads him back into the server

This guy did it but wouldn’t say how since he said his framework is custom…

Basically, I need to unload someone from my server for this to work. How would I go about doing this?

This is what I have right now:

    if ESX ~= nil then
        if NetworkIsSessionStarted() and ESX.IsPlayerLoaded() then
            TriggerEvent('kashactersC:ReloadCharacters')          
            
            return
        end
    end
end)
1 Like

Client -

local IsChoosing = true

Citizen.CreateThread(function ()

    while true do

        Citizen.Wait(0)

        if IsChoosing then

            TriggerScreenblurFadeIn(0)

        end

        for i=1, #Config.Logouts, 1 do

            local player = GetPlayerPed(-1)

            local playerloc = GetEntityCoords(player, 0)

            local logoutspot = Config.Logouts[i]

            local logoutdistance = GetDistanceBetweenCoords(logoutspot['x'], logoutspot['y'], logoutspot['z'], playerloc['x'], playerloc['y'], playerloc['z'], true)

            if logoutdistance <= 8 then

                DrawText3Ds(logoutspot.x,logoutspot.y,logoutspot.z + 0.10, "type /logout to swap characters.")

            end

        end

    end

end)

Blip -

Citizen.CreateThread(function()

    for i=1, #Config.Logouts, 1 do

        local logoutspot = Config.Logouts[i]

        local blip = AddBlipForCoord(logoutspot)

        SetBlipSprite(blip, 480)

        SetBlipDisplay(blip, 4)

        SetBlipScale(blip, 0.7)

        SetBlipColour(blip, 4)

        SetBlipAsShortRange(blip, true)

        BeginTextCommandSetBlipName("STRING")

        AddTextComponentString("Logout")

        EndTextCommandSetBlipName(blip)

    end

end)

COMMAND -

RegisterCommand('logout', function(source, args, rawCommand)

    for i=1, #Config.Logouts, 1 do

        local player = GetPlayerPed(-1)

        local playerloc = GetEntityCoords(player, 0)

        local logoutspot = Config.Logouts[i]

        local logoutdistance = GetDistanceBetweenCoords(logoutspot['x'], logoutspot['y'], logoutspot['z'], playerloc['x'], playerloc['y'], playerloc['z'], true)

        if logoutdistance <= 3 then

            TriggerEvent('kashactersC:ReloadCharacters')

        end

    end

end)

If it helped , mark as solution

I’ll give it a go when I jump on my PC in the morning. Hopefully this works. Appreciate it buddy!

Does not work, does the same thing, goes back to character selection, lets me choose my character, then when I spawn in it is still the same character. Also, there were some errors in that. I don’t want there to be location, I’d rather a user be able to logout where ever they are.

RegisterCommand(‘logout’, function(source)
TriggerEvent(‘kashactersC:ReloadCharacters’)
return
end)

This right here SHOULD work, but it does what I mentioned above. Is there a way to unload someone from the server as if they were disconnecting?

When I “switch” characters, it loads the character to it’s previous location, so it’s got that right. It’s just not actually updating my characters skin/loadout.

1 Like

Any chance you can help me out and explain where this is going, i created a resource, made a client.lua and put all this in and it says it cant find my resource

You’ve got to make your own config file & add in the coords for logouts & __resource.lua or xmanifest.lua, or just throw it in another resource.

Sooo

Config = {}

Config.Logouts
{
x = 465.35, y = -735.54, z = 26.36, h = 90.85
}

in a config and then a resoure.lua to start it all?

pretty much, make sure you add in the nessacary code in the rescourse.lua though.

this worked for me earlier also and i made another for you!
DOWNLOAD HERE-
logout.zip (1.7 KB)

When i use this and switch character, it techincally changes characters but not the job, money, or inventory