Sign in to follow this  
getPlayerName = Thirrasgo

Como automatizar este sistema de salvar roupas?

Recommended Posts

Preciso de ajuda para automatizar este sistema de Save-Clothes, preciso que ele salve as roupas na hora do player sair (ou dps q comprar) e  carregar as roupas  quando o player logar.

 

function onPlayerExit(player) 
    local account = getPlayerAccount(player) 
    local texture = {} 
    local model = {} 
    for i=0, 17 do 
        local clothesTexture, clothesModel = getPedClothes(player, i) 
        if ( clothesTexture ~= false ) then 
            table.insert(texture, clothesTexture) 
            table.insert(model, clothesModel) 
        else 
            table.insert(texture, " ") 
            table.insert(model, " ") 
        end 
    end 
    local setTextures = table.concat(texture, ",") 
    local setModels = table.concat(model, ",") 
    setAccountData(account, "setexture", setTextures) 
    setAccountData(account, "setmodel", setModels) 
    texture = {} 
    model = {} 
end 
addCommandHandler("save", save)

function load(player) 
    local textures = {} 
    local models = {} 
    local account = getPlayerAccount(player) 
    local textureLoad = getAccountData(account, "setexture") 
    local modelLoad = getAccountData(account, "setmodel") 
    local textures = split(textureLoad, 44) 
    local models = split(modelLoad, 44) 
    setElementModel(player,0) 
    for i=0, 17 do 
        if ( textures[i+1] ~= " " ) then 
            addPedClothes(player, textures[i+1], models[i+1], i) 
        end 
    end 
    textures = {} 
    models = {} 
end
addCommandHandler("load", load) 

 

Share this post


Link to post
3 minutes ago, KronoS Lettify said:

Em vez de você utilizar Command Handlers para as funções, pode usar Event Handlers.

Os eventos que podem ser úteis no seu caso, é: onPlayerLogin e onPlayerQuit

--save 
function onPlayerExit(player) 
    local account = getPlayerAccount(player) 
    local texture = {} 
    local model = {} 
    for i=0, 17 do 
        local clothesTexture, clothesModel = getPedClothes(player, i) 
        if ( clothesTexture ~= false ) then 
            table.insert(texture, clothesTexture) 
            table.insert(model, clothesModel) 
        else 
            table.insert(texture, " ") 
            table.insert(model, " ") 
        end 
    end 
    local setTextures = table.concat(texture, ",") 
    local setModels = table.concat(model, ",") 
    setAccountData(account, "setexture", setTextures) 
    setAccountData(account, "setmodel", setModels) 
    texture = {} 
    model = {} 
end 
addEventHandler("onPlayerQuit" getRootElement (), onPlayerExit ) 

function load(player) 
    local textures = {} 
    local models = {} 
    local account = getPlayerAccount(player) 
    local textureLoad = getAccountData(account, "setexture") 
    local modelLoad = getAccountData(account, "setmodel") 
    local textures = split(textureLoad, 44) 
    local models = split(modelLoad, 44) 
    setElementModel(player,0) 
    for i=0, 17 do 
        if ( textures[i+1] ~= " " ) then 
            addPedClothes(player, textures[i+1], models[i+1], i) 
        end 
    end 
    textures = {} 
    models = {} 
end
addCommandHandler("load", load) 
addEventHandler( "onPlayerLogin", getRootElement (), load )

assim?

Share this post


Link to post
33 minutes ago, getPlayerName = Thirrasgo said:

--save 
function onPlayerExit(player) 
    local account = getPlayerAccount(player) 
    local texture = {} 
    local model = {} 
    for i=0, 17 do 
        local clothesTexture, clothesModel = getPedClothes(player, i) 
        if ( clothesTexture ~= false ) then 
            table.insert(texture, clothesTexture) 
            table.insert(model, clothesModel) 
        else 
            table.insert(texture, " ") 
            table.insert(model, " ") 
        end 
    end 
    local setTextures = table.concat(texture, ",") 
    local setModels = table.concat(model, ",") 
    setAccountData(account, "setexture", setTextures) 
    setAccountData(account, "setmodel", setModels) 
    texture = {} 
    model = {} 
end 
addEventHandler("onPlayerQuit" getRootElement (), onPlayerExit ) 

function load(player) 
    local textures = {} 
    local models = {} 
    local account = getPlayerAccount(player) 
    local textureLoad = getAccountData(account, "setexture") 
    local modelLoad = getAccountData(account, "setmodel") 
    local textures = split(textureLoad, 44) 
    local models = split(modelLoad, 44) 
    setElementModel(player,0) 
    for i=0, 17 do 
        if ( textures[i+1] ~= " " ) then 
            addPedClothes(player, textures[i+1], models[i+1], i) 
        end 
    end 
    textures = {} 
    models = {} 
end
addCommandHandler("load", load) 
addEventHandler( "onPlayerLogin", getRootElement (), load )

assim?

Não. Dá uma olhada nas páginas explicativas dos dois eventos que mencionei, na wiki do MTA. Essas páginas mostrarão como deve usar o evento.

  • Like 1

Share this post


Link to post
12 minutes ago, KronoS Lettify said:

Não. Dá uma olhada nas páginas explicativas dos dois eventos que mencionei, na wiki do MTA. Essas páginas mostrarão como deve usar o evento.

Não faço a minima ideia de como eu possa fazer isso kkkkk

Você poderia editá-lo pra mim por favor?

 

Share this post


Link to post

Linha 3 e linha 26 estão erradas. player não é o parâmetro de função pros eventos onPlayerLogin e onPlayerQuit.

E não use load como nome de função, pois essa é uma palavra reservada na linguagem Lua.

  • Like 2

Share this post


Link to post

Fiz para você como ficará, diante as dicas do Lord

--/> SALVAR ROUBAS AI SAIR.
function save_player_quit ( ) 
   local texture = {} 
   local model = {} 
   for i=0, 17 do 
      local clothesTexture, clothesModel = getPedClothes(source, i) 
      if ( clothesTexture ~= false ) then 
         table.insert(texture, clothesTexture) 
         table.insert(model, clothesModel) 
      else 
         table.insert(texture, " ") 
         table.insert(model, " ") 
      end 
   end 
   local setTextures = table.concat(texture, ",") 
   local setModels = table.concat(model, ",") 
   local account = getPlayerAccount(source) 
   setAccountData(account, "setexture", setTextures) 
   setAccountData(account, "setmodel", setModels) 
   texture = {} 
   model = {} 
end 
addEventHandler("onPlayerQuit", getRootElement(), save_player_quit ) 

--/> CARREGAR ROUPAS AO LOGAR.
function load_player_login ( ) 
   local textures = {} 
   local models = {} 
   local account = getPlayerAccount(source) 
   local textureLoad = getAccountData(account, "setexture") 
   local modelLoad = getAccountData(account, "setmodel") 
   if not textureLoad and not modelLoad then --/> Adicionado !
      return --/> Adicionado !
   end --/> Adicionado !
   local textures = split(textureLoad, 44) 
   local models = split(modelLoad, 44) 
   setElementModel(source,0)
   for i=0, 17 do 
      if ( textures[i+1] ~= " " ) then 
         addPedClothes(source, textures[i+1], models[i+1], i) 
      end 
   end 
   textures = {} 
   models = {} 
end 
addEventHandler( "onPlayerLogin", getRootElement(), load_player_login )

 

  • Thanks 1

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.