Jump to content

SetElementInterior when the player join


Recommended Posts

Hi guys, the problem is that every time you log in, it sets the player's position, interior ID, dimension, etc. from a MySql table, but no matter how well you set it and write out the correct data, for some reason I can't see anything, only my character floating in the sky, although I think it's here in the Interior, it's just not visible for some reason. I also tried to handle the problem on the client side.

---SERVER SIDE


local int = result[1]["interior"]
local dim = result[1]["dim"]
local pos = fromJSON(result[1]["pos"])
setTimer(function()
  spawnPlayer(player, pos[1], pos[2], pos[3]+1, 90, skin, tonumber(int), tonumber(dim))
  setElementInterior(player, tonumber(int))
  setElementDimension(player, tonumber(dim))
  triggerClientEvent(player, "fixClientSpawn", root, tonumber(int), tonumber(dim))
 end, 200, 1)

--CLIENT SIDE

addEvent("fixClientSpawn", true)
addEventHandler("fixClientSpawn", root, function(int, dim)
    setElementInterior(localPlayer, int)
    setElementDimension(localPlayer, dim)
    setCameraTarget(localPlayer)
    outputDebugString("CLIENT FIX: INT "..int.." DIM "..dim)
end)

 

Link to comment

This issue usually happens because the interior and dimension are set before the client finishes loading the actual map for that interior. Even if the values from MySQL are correct, MTA needs a short delay after spawning so the client can stream the interior models.

You can try:

Option 1 – Set interior/dimension before spawning :
 

setTimer(function()
    setElementInterior(player, tonumber(int))
    setElementDimension(player, tonumber(dim))
    spawnPlayer(player, pos[1], pos[2], pos[3] + 1, 90, skin)
    triggerClientEvent(player, "fixClientSpawn", root, tonumber(int), tonumber(dim))
end, 200, 1)

Option 2 – Delay camera targeting on the client :
 

addEventHandler("fixClientSpawn", root, function(int, dim)
    setElementInterior(localPlayer, int)
    setElementDimension(localPlayer, dim)
    setTimer(function()
        setCameraTarget(localPlayer)
    end, 200, 1)
end)

Also double-check that the saved position in MySQL is inside the correct interior map. If you spawn with interior = 0 while your position is in an interior location, you will only see the empty sky.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...