Jump to content

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) 

 

Link to comment
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?

Link to comment
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
Link to comment

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
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...