Jump to content
Sign in to follow this  
Gpwjhlkdcf

PosToStorage e StorageToPos

Recommended Posts

Gpwjhlkdcf    21
Gpwjhlkdcf

function PosToStorage(pos, max)
 local x, y, z = tostring(pos.x), tostring(pos.y), tostring(pos.z)
 return tonumber("1" .. (string.rep("0", max-#x)..x) .. (string.rep("0", max-#y)..y) .. (string.rep("0", max-#z)..z))
end

function StorageToPos(s)
 s = tostring(s)
 local max = (#s-1)/3
 return {x=tonumber(s:sub(2+max*0, 1+max*1)), y=tonumber(s:sub(2+max*1, 1+max*2)), z=tonumber(s:sub(2+max*2, 1+max*3))}
end

 

local str = PosToStorage({x=100, y=100, z=7}, 4)
local pos = StorageToPos(str)
print(str)
print(pos.x, pos.y, pos.z)

 

Só vai funcionar se o max for menor ou igual a 4, senão o número e o sistema vão bugar, isso significa que só armazena de posições menores ou igual a 9999.

Gambiarra para aqueles que querem guardar uma posição inteira em uma storage só. Eu prefiro guardar em 3 storages distintas, mas tá ai pra quem quiser, foi o Conde2 que pediu...

Share this post


Link to post
Share on other sites
Conde2    0
Conde2

Parabens ótimo jeito de ser por uma posição em uma storage

Só tem que tomar cuidado com o tamanho da string pra não sobrecarregar o storage e buga

Mais ficou boa, porem tem outros jeitos xD

Share this post


Link to post
Share on other sites
Mock    32
Mock

Hum

ok legal :P

eu fiz uma vez usando 3 storages

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×