Jump to content

[HELP]save and load skins


Anulesked

Recommended Posts

Posted

Help me please, guys:

  
local playerDataTable =  
{ 
  {"torso"} 
} 
  
function saveSkin(player,clothesType) 
local account = getPlayerAccount(player) 
local tex, mod = getPedClothes(player, clothesType) 
  for i, data in ipairs(playerDataTable) do 
    setAccountData(account, data[1], "\""..tex.."\",\""..mod.."\"") 
    outputChatBox("saved #"..i..": "..getAccountData(account, data[1])) 
  end 
end 
addCommandHandler("s", saveSkin) 
  
function loadSkin(player) 
local account = getPlayerAccount(player) 
for i, data in ipairs(playerDataTable) do 
    local account = getPlayerAccount(player) 
    addPedClothes (player, getAccountData(account, data[1]), 0) 
    outputChatBox("saved #"..i..": "..getAccountData(account, data[1])) 
end 
end 
addCommandHandler("x", loadSkin) 
  

  • Moderators
Posted
local playerDataTable = 
{ 
  {"torso"} 
} 
  
--too: 
local playerDataTable = 
{ 
  "torso"--, 
--"stuff" 
} 
  

setAccountData(account, data[1], "\""..tex.."\",\""..mod.."\"") 
  
--Too: 
  
 setAccountData(account, data, tex..",".. mod .. "," .. clothesType) 
  

  
addPedClothes (player, getAccountData(account, data[1]), 0) 
  
--Too: 
  
local clothing = getAccountData(account, data) 
if clothing and getElementModel(player) == 0 then 
local table = split(clothing,",") 
addPedClothes (player,table[1] , table[2],tonumber(table[3])) 
end 
  

And don't forget this function:

isGuestAccount 

Posted

IIYAMA, very thank for ur reply! but in my full script table is that:

  
local playerDataTable = { 
  {"torso"}, 
  {"something"}, 
  {"yet something"}, 
  ... 
} 
  

what i must rewrite in ur code with that table?

 

I'm very sorry for my bad english.

  • Moderators
Posted

It is useless to index a table inside a table with just 1 item and that multiply by all items.

So yes, you better rewrite the table.

Next to that you must know what you are doing. But it seems you are only editing other people their property.

Sorry, but I am not going to edit other players their scripts without permission of the owner...........

Posted (edited)

IIYAMA, i get "bad argument @ addPedClothes" as before.

local playerDataTable = 
  {"torso"} 
  
function saveSkin(player,clothesType) 
local account = getPlayerAccount(player) 
local tex, mod = getPedClothes(player, clothesType) 
  for i, data in ipairs(playerDataTable) do 
    setAccountData(account, data, tex..",".. mod .. "," .. clothesType) 
    --outputChatBox("saved #"..i..": "..getAccountData(account, data[1])) 
  end 
end 
addCommandHandler("s", saveSkin) 
  
function loadSkin(player) 
local account = getPlayerAccount(player) 
  for i, data in ipairs(playerDataTable) do 
  local account = getPlayerAccount(player) 
  local clothing = getAccountData(account, data) 
    if clothing and getElementModel(player) == 0 then 
    local table = split(clothing,",") 
      addPedClothes (player,table[1] , table[2],tonumber(table[3])) 
    end 
    --outputChatBox("saved #"..i..": "..getAccountData(account, data[1])) 
  end 
end 
addCommandHandler("x", loadSkin) 

and yet i don't know must i get player account before cycle or after.

Edited by Guest
  • Moderators
Posted
function saveSkin(player,clothesType) 
local account = getPlayerAccount(player) 
if not isGuestAccount(account) and getElementModel(player) == 0 and clothesType then 
for i, data in ipairs(playerDataTable) do 
  local tex, mod = getPedClothes(player, clothesType) 
  if tex and mod then 
    setAccountData(account, data, tex..",".. mod .. "," .. clothesType) 
    --outputChatBox("saved #"..i..": "..getAccountData(account, data[1])) 
  else 
    outputChatBox("no tex and mod") 
  end 
end 
end 
end 
addCommandHandler("s", saveSkin) 

/s 0

function loadSkin(player) 
local account = getPlayerAccount(player) 
  if not isGuestAccount(account) and getElementModel(player) == 0 then 
  for i, data in ipairs(playerDataTable) do 
  local clothing = getAccountData(account, data) 
    if clothing  then 
    local table = split(clothing,",") 
      if table then 
      outputChatBox(tostring(table[1]) .. " " .. tostring(table[2]) .. " " .. tostring(table[3])) 
      addPedClothes (player,table[1] , table[2],tonumber(table[3])) 
      end 
    end 
    --outputChatBox("saved #"..i..": "..getAccountData(account, data[1])) 
  end 
  end 
end 
addCommandHandler("x", loadSkin) 

Well debug it. Sorry (can't use tabs because I am running mac at the moment)

  • Moderators
Posted

if you debug your script for every step you take, you hardly can make mistakes.

It is learning from your mistakes, retry, debug again till you got the problem.

You can't fix a problem caused by a problem when you don't see it.

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