main Posted February 11, 2020 Share Posted February 11, 2020 To com um problema no servidor referente ao spawn no 'limbo' ( pos { 0, 0, 0 } ); Alguns jogadores spawnam no 'limbo' após cair do servidor por perda de pacote ou algo relacionado a isso; Parece que antes de acontecer isso ele é direcionado pro limbo por padrão. Tentei uma forma de solucionar no meu save-system, porém não obtive sucesso. Há alguma forma melhor de solucionar isso? local joinX, joinY, joinZ = 1481.1440429688, -1766.98828125, 18.795755386353 local spawnX, spawnY, spawnZ, rotZ = 2029.8, -1406.0, 23.1, 180 function loadAccountData(source) if isElement(source) then local account = getPlayerAccount(source) local position = getAccountData(account, "funmodev2-position") or toJSON({joinX, joinY, joinZ}) local rotation = getAccountData(account, "funmodev2-rotation") or 0 local interior = getAccountData(account, "funmodev2-int") or 0 local dimensao = getAccountData(account, "funmodev2-dim") or 0 local skin = getAccountData(account, "funmodev2-skin") or 0 local health = getAccountData(account, "funmodev2-health") or 100 local armor = getAccountData(account, "funmodev2-armor") or 0 local money = getAccountData(account, "funmodev2-money") or 0 local wanted = getAccountData(account, "funmodev2-wantedlevel") or 0 local clothes = getAccountData(account, "funmondev2-clothes") local stats = getAccountData(account, "funmodev2-stats") local weapons = getAccountData(account, "funmodev2-weapons") local firstLogin = getAccountData(account, "Registrado") local x, y, z = unpack(fromJSON(position)) spawnPlayer(source, x, y, z, rotation, skin, interior, dimensao) setElementHealth(source, health) setPedArmor(source, armor) setPlayerWantedLevel(source, wanted) if not firstLogin then setAccountData(account, "Registrado", true) givePlayerMoney(source, 2000) else setPlayerMoney(source, money) end if clothes then removeAllPedClothes(source) for _, clothe in pairs(fromJSON(clothes)) do local tipo, texture, model = unpack(clothe) addPedClothes(source, texture, model, tipo) end end if stats then for stat, value in pairs(fromJSON(stats)) do setPedStat(source, stat, value) end end if weapons then takeAllWeapons(source) for weapon, ammo in pairs(fromJSON(weapons)) do giveWeapon(source, weapon, ammo, false) end end end end function saveAccountData(source) if isElement(source) then local account = getPlayerAccount(source) local x, y, z = getElementPosition(source) local _, _, rz = getElementRotation(source) local interior = getElementInterior(source) local dimensao = getElementDimension(source) local skin = getElementModel(source) local health = getElementHealth(source) local armor = getPedArmor(source) local money = getPlayerMoney(source) local wanted = getPlayerWantedLevel(source) local clothes = getAllPedClothes(source) local stats = getAllPedStats(source) local weapons = getAllPedWeapon(source) setAccountData(account, "funmodev2-position", toJSON({x, y, z})) setAccountData(account, "funmodev2-rotation", rz) setAccountData(account, "funmodev2-int", interior) setAccountData(account, "funmodev2-dim", dimensao) setAccountData(account, "funmodev2-skin", skin) setAccountData(account, "funmodev2-health", health) setAccountData(account, "funmodev2-armor", armor) setAccountData(account, "funmodev2-money", money) setAccountData(account, "funmodev2-wantedlevel", wanted) setAccountData(account, "funmondev2-clothes", toJSON(clothes)) setAccountData(account, "funmodev2-stats", toJSON(stats)) setAccountData(account, "funmodev2-weapons", toJSON(weapons)) end end addEventHandler("onPlayerSpawn", root, function() local posPlayer = Vector3(getElementPosition(source)) if posPlayer.x == 0 and posPlayer.y == 0 then setElementPosition(source, spawnX, spawnY, spawnZ) end fadeCamera(source, true) setCameraTarget(source, source) end) addEventHandler("onResourceStart", resourceRoot, function() for _, thePlayer in ipairs(getElementsByType("player")) do local account = getPlayerAccount(thePlayer) if not isGuestAccount(account) then loadAccountData(thePlayer) end end end) addEventHandler("onResourceStop", resourceRoot, function() for _, thePlayer in ipairs(getElementsByType("player")) do local account = getPlayerAccount(thePlayer) if not isGuestAccount(account) then saveAccountData(thePlayer) end end end) addEventHandler("onPlayerLogin", root, function() loadAccountData(source) end) addEventHandler("onPlayerQuit", root, function() local account = getPlayerAccount(source) if not isGuestAccount(account) then saveAccountData(source) end end) addEventHandler("onPlayerLogout", root, function() saveAccountData(source) end) addEventHandler("onPlayerWasted", root, function() takePlayerMoney(source, math.random(250, 500)) setTimer(spawnPlayer, 2500, 1, source, spawnX+math.random(-3,3), spawnY+math.random(-3,3), spawnZ, rotZ, getElementModel(source)) end) ---------------------------------------------------------------------------------------------------- --- FUNCTIONS --- ---------------------------------------------------------------------------------------------------- function getAllPedClothes(thePed) local clothes = { } for i=0, 17 do local texture, model = getPedClothes(thePed, i) if (texture) and (model) then table.insert(clothes, {i, texture, model}) end end return clothes end function removeAllPedClothes(thePed) for i=0, 17 do removePedClothes(thePed, i) end return true end function getAllPedStats(thePed) local stats = {} for stat=0, 230 do local value = getPedStat(thePed, stat) if (value) and (value > 0) then stats[stat] = value end end return stats end function getAllPedWeapon(thePed) local weapons = {} for slot=1, 12 do local weapon = getPedWeapon(thePed, slot) local ammo = getPedTotalAmmo(thePed, slot) if (weapon > 0) and (ammo > 0) then weapons[weapon] = ammo end end return weapons end Link to comment
Angelo Pereira Posted February 11, 2020 Share Posted February 11, 2020 (edited) Já tentou colocar verificações de outputDebugString() das coordenadas x,y,z ao cair do servidor? e ao logar? para saber se as coordenadas estão sendo salva ao cair? e ao logar se são verdadeiras? Edited February 11, 2020 by Angelo Pereira Link to comment
main Posted February 11, 2020 Author Share Posted February 11, 2020 Depurei o código e sim, estão sendo salvas porém na pos { 0, 0, 0 }. Link to comment
Angelo Pereira Posted February 11, 2020 Share Posted February 11, 2020 15 hours ago, MainSCR said: Depurei o código e sim, estão sendo salvas porém na pos { 0, 0, 0 }. Algo improvável está ocorrendo com conflito de outro resource, impossível, ele ao cair do servidor, salvar em 0,0,0. Porem, até não descobrir o problema, daria de fazer uma correção temporária, caso verificasse em x,y,z em 0, teleporta-lo para o hospital Este isElement(source) é realmente necessário? o jogador sempre será verdadeiro ao da quit do servidor, mas, testei em um servidor teste, e funciona, mesmo caindo do servidor. ou seja, possa ser um conflito, e muito artificial, teria que saber como realmente isso ocorre 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now