Skip to content

Player's last position fails to load sometimes, making them teleported to vec3(0,0,0) after loading. #40

@nwvh

Description

@nwvh

Hey, I have this really weird issue where sometimes, after loading into my character, I am not getting teleported to my last location, but gets stuck at vector3(0,0,0) instead. My last position is however saved in the characters table in my database. This is happening randomly, sometimes I get teleported to my last location, but sometimes i get stuck at vec3(0,0,0).

I haven't configured the option to create more characters, player is automatically loaded into the first one after joining.

These is my ox_core convars:

setr ox:locale "cs"
setr ox:deathSystem false
setr inventory:target true

I had to create a small script that automatically detects this bug and teleports player to their saved location from database:

--client

AddEventHandler("ox:playerLoaded", function()
    local coords = GetEntityCoords(cache.ped)

    if #(coords - vector3(0, 0, 0)) < 5 then
        local lastCoords = lib.callback.await("core:getLastCoords", false)
        local x, y, z, heading = lastCoords.x, lastCoords.y, lastCoords.z, lastCoords.w
        SetEntityCoords(cache.ped, x or 189.0266, y or -854.7974, z or 31.3755)
        SetEntityHeading(cache.ped, heading or 354.8506)
    end
end)
--server
lib.callback.register("core:getLastCoords", function(source)
    local player = Ox.GetPlayer(source)
    if not player then return end
    local response = MySQL.query.await('SELECT `x`, `y`,`z`,`heading` FROM `characters` WHERE `charId` = ?', {
        player.charId
    })[1]
    local x, y, z, heading = response.x, response.y, response.z, response.w
    return {
        x, y, z, w
    }
end)
  • I am using the latest version of ox_core as of today (date of posting this issue).
  • I haven't modified the source code in any way
  • I am running only about 10 custom resources that in no way interfere with player's position on load.

I don't know if there's any more information that I can provide on this issue, let me know if there's anything more you'd like to know.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions