Jump to content

About Save system


SkatCh

Recommended Posts

hi guys pleas i need some help i want to create save system for my Cj clothes shop , because when i reconnect all clothes lost this is a part of the script .

addEvent( "onChangeClothesCJ", true ) 
addEventHandler( "onChangeClothesCJ", root, 
function ( CJClothesTable, CJClothesString ) 
    if ( CJClothesTable ) then 
        for int, index in pairs( CJClothesTable ) do 
            local texture, model = getClothesByTypeIndex ( int, index ) 
            if ( texture ) then 
                addPedClothes ( source, texture, model, int ) 
            end 
        end 
     end 
end 
) 

i want to use setAccountData but i don't know exactly how can i put it here .

Link to comment

You can try using this, but I'm not entirely sure if it will work.

-- save 
addEventHandler ( "onPlayerQuit", root, function ( ) 
    local account = getPlayerAccount ( source ) 
    if ( isGuestAccount( account ) ) then return end 
  
    local clothes = { } 
    for i=0, 17 do  
        clothes[i] = { getPedClothes ( source, i ) } 
    end  
    clothes = toJSON ( clothes ) 
    setAccountData ( account, "Clothes", clothes ) 
  
end ) 
  
addEventHandler ( "onPlayerLogin", root, function ( _, account ) 
    local clothes = getAccountData ( account, "Clothes" ) 
    if not clothes then return end 
    for i, v in pairs ( fromJSON ( clothes )  do 
        local text, id = unpack ( v ) 
        addPedClothes ( source, text, id, i ) 
    end  
end ) 

Link to comment

ok bro i will try it please i want to ask you one more question ; i create a Gui button and i want when the player click it all his clothes will gone .

i tried many function like removePedClothes , with "onClientGUIClick" but nothing happen , thank you

edit: nvm i fix it

Link to comment

For @ xXMADEXx your save script is working fine but i got some warnings when someone join the server :

addEventHandler ( "onPlayerLogin", root, function ( _, account ) 
    local clothes = getAccountData ( account, "Clothes" ) 
    if not clothes then return end 
    for i, v in pairs ( fromJSON ( clothes )  do 
        local text, id = unpack ( v ) 
        addPedClothes ( source, text, id, i )  <---- here this line 
    end 
end ) 

bad argument @ 'addPedClothes' [Expected String at argument 2 , got boolean]

Link to comment

try this .. :

addEventHandler ( "onPlayerQuit", root, function (    ) 
    local pAcc = getPlayerAccount ( source ) 
    if ( pAcc and not isGuestAccount ( pAcc ) ) then 
      for i = 1, 17 do 
           local c, t = getPedClothes ( source, i ) 
           setAccountData ( pAcc, "ClothesData", { c, t } ) 
      end 
   end 
end ) 
  
addEventHandler ( "onPlayerLogin", root, function ( _,acc ) 
    local cData = getAccountData ( acc, "ClothesData" ) 
    if ( cData ) then 
      for k, v in ipairs ( cData ) do 
            addPedClothes ( source, v[1], v[2], k ) 
      end 
   end 
end ) 
Link to comment

didn't work you script can't save clothes , but xXMADEXx script is working fine i can see the same clothes when i login but when other players join i got this error

bad argument @ 'addPedClothes' [Expected String at argument 2 , got boolean]

Link to comment

my code is right .. but MADE forget )

try this

-- save 
addEventHandler ( "onPlayerQuit", root, function ( ) 
    local account = getPlayerAccount ( source ) 
    if ( isGuestAccount( account ) ) then return end 
  
    local clothes = { } 
    for i=0, 17 do 
        clothes[i] = { getPedClothes ( source, i ) } 
    end 
    clothes = toJSON ( clothes ) 
    setAccountData ( account, "Clothes", clothes ) 
  
end ) 
  
addEventHandler ( "onPlayerLogin", root, function ( _, account ) 
    local clothes = getAccountData ( account, "Clothes" ) 
    if not clothes then return end 
    for i, v in pairs ( fromJSON ( clothes ) ) do 
        local text, id = unpack ( v ) 
        addPedClothes ( source, text, id, i ) 
    end 
end ) 
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...