SkatCh Posted August 21, 2014 Share Posted August 21, 2014 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
xXMADEXx Posted August 21, 2014 Share Posted August 21, 2014 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
SkatCh Posted August 21, 2014 Author Share Posted August 21, 2014 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
SkatCh Posted August 22, 2014 Author Share Posted August 22, 2014 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
#DRAGON!FIRE Posted August 22, 2014 Share Posted August 22, 2014 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
SkatCh Posted August 22, 2014 Author Share Posted August 22, 2014 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
xXMADEXx Posted August 22, 2014 Share Posted August 22, 2014 Try just adding tostring to the script. Link to comment
#DRAGON!FIRE Posted August 22, 2014 Share Posted August 22, 2014 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
SkatCh Posted August 22, 2014 Author Share Posted August 22, 2014 bro i already tried it and i know that you need to add ')' in xXMADExx scrcipt in line 18 . Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now