Jump to content

addPedClothes


Agon

Recommended Posts

Hi. I made this script with some help of the wiki but it doesn't save my cj's clothes. it says bad argument @addPedClothes. i know i have to use this:

addPedClothes(source, "clothesTexture", "clothesModel", playerShirt) --- if i use this it won't add clothes i think. 

Please help me with this

function playerLeave() 
      local playerAccount = getPlayerAccount(source) 
      if (playerAccount) then 
            local playerMoney = getPlayerMoney(source) 
            local playerSkin = getElementModel(source) 
            local playerShirt = getPedClothes(source, 0) 
            local playerHead = getPedClothes(source, 1) 
            local playerTrousers = getPedClothes(source, 2) 
            local playerShoes = getPedClothes(source, 3) 
            local playerTattoosLeftUpperArm = getPedClothes(source, 4) 
            local playerTattoosLeftLowerArm = getPedClothes(source, 5) 
            local playerTattoosRightUpperArm = getPedClothes(source, 6) 
            local playerTattoosRightLowerArm = getPedClothes(source, 7) 
            local playerTattoosBack = getPedClothes(source, 8 ) 
            local playerTattoosLeftChest = getPedClothes(source, 9) 
            local playerTattoosRightChest = getPedClothes(source, 10) 
            local playerTattoosStomach = getPedClothes(source, 11) 
            local playerTattoosLowerBack = getPedClothes(source, 12) 
            local playerNecklace = getPedClothes(source, 13) 
            local playerWatch = getPedClothes(source, 14) 
            local playerGlasses = getPedClothes(source, 15) 
            local playerHat = getPedClothes(source, 16) 
            local playerExtra = getPedClothes(source, 17) 
            setAccountData(playerAccount, "player.money", playerMoney) 
            setAccountData(playerAccount, "player.skin", playerSkin) 
            setAccountData(playerAccount, "player.shirt", playerShirt) 
            setAccountData(playerAccount, "player.head", playerHead) 
            setAccountData(playerAccount, "player.trousers", playerTrousers) 
            setAccountData(playerAccount, "player.shoes", playerShoes) 
            setAccountData(playerAccount, "player.tattoosLeftUpperArm", playerTattoosLeftUpperArm) 
            setAccountData(playerAccount, "player.tattoosLeftLowerArm", playerTattoosLeftLowerArm) 
            setAccountData(playerAccount, "player.tattoosRightUpperArm", playerTattoosRightUpperArm) 
            setAccountData(playerAccount, "player.tattoosRightLowerArm", playerTattoosRightLowerArm) 
            setAccountData(playerAccount, "player.tattoosBack", playerTattoosBack) 
            setAccountData(playerAccount, "player.tattoosLeftChest", playerTattoosLeftChest) 
            setAccountData(playerAccount, "player.tattoosRightChest", playerTattoosRightChest) 
            setAccountData(playerAccount, "player.tattoosStomach", playerTattoosStomach) 
            setAccountData(playerAccount, "player.tattoosLowerBack", playerTattoosLowerBack) 
            setAccountData(playerAccount, "player.necklace", playerNecklace) 
            setAccountData(playerAccount, "player.watch", playerWatch) 
            setAccountData(playerAccount, "player.glasses", playerGlasses) 
            setAccountData(playerAccount, "player.hat", playerHat) 
            setAccountData(playerAccount, "player.extra", playerExtra) 
             
      end 
end 
addEventHandler("onPlayerQuit", getRootElement(), playerLeave) 
  
function playerLogin() 
      local playerAccount = getPlayerAccount(source) 
      if (playerAccount) then 
            local playerMoney = getAccountData(playerAccount, "player.money") 
            local playerSkin = getAccountData(playerAccount, "player.skin") 
            local playerShirt = getAccountData(playerAccount, "player.shirt") 
            local playerHead = getAccountData(playerAccount, "player.head") 
            local playerTrousers = getAccountData(playerAccount, "player.trousers") 
            local playerShoes = getAccountData(playerAccount, "player.shoes") 
            local playerTattoosLeftUpperArm = getAccountData(playerAccount, "player.tattoosLeftUpperArm") 
            local playerTattoosLeftLowerArm = getAccountData(playerAccount, "player.tattoosLeftLowerArm") 
            local playerTattoosRightUpperArm = getAccountData(playerAccount, "player.tattoosRightUpperArm") 
            local playerTattoosRightLowerArm = getAccountData(playerAccount, "player.tattoosRightLowerArm") 
            local playerTattoosBack = getAccountData(playerAccount, "player.tattoosBack") 
            local playerTattoosLeftChest = getAccountData(playerAccount, "player.tattoosLeftChest") 
            local playerTattoosRightChest = getAccountData(playerAccount, "player.tattoosRightChest") 
            local playerTattoosStomach = getAccountData(playerAccount, "player.tattoosStomach") 
            local playerTattoosLowerBack = getAccountData(playerAccount, "player.tattoosLowerBack") 
            local playerNecklace = getAccountData(playerAccount, "player.necklace") 
            local playerWatch = getAccountData(playerAccount, "player.watch") 
            local playerGlasses = getAccountData(playerAccount, "player.glasses") 
            local playerHat = getAccountData(playerAccount, "player.hat") 
            local playerExtra = getAccountData(playerAccount, "player.extra") 
            if (playerMoney) then 
                  setPlayerMoney(source, playerMoney) 
                  setElementModel(source, playerSkin) 
                  addPedClothes(source, playerShirt) 
                  addPedClothes(source, playerHead) 
                  addPedClothes(source, playerTrousers) 
                  addPedClothes(source, playerShoes) 
                  addPedClothes(source, playerTattoosLeftUpperArm) 
                  addPedClothes(source, playerTattoosLeftLowerArm) 
                  addPedClothes(source, playerTattoosRightUpperArm) 
                  addPedClothes(source, playerTattoosRightLowerArm) 
                  addPedClothes(source, playerTattoosBack) 
                  addPedClothes(source, playerTattoosLeftChest) 
                  addPedClothes(source, playerTattoosRightChest) 
                  addPedClothes(source, playerTattoosStomach) 
                  addPedClothes(source, playerTattoosLowerBack) 
                  addPedClothes(source, playerNecklace) 
                  addPedClothes(source, playerWatch) 
                  addPedClothes(source, playerGlasses) 
                  addPedClothes(source, playerHat) 
                  addPedClothes(source, playerExtra) 
  
            end 
      end 
end 
addEventHandler("onPlayerLogin", getRootElement(), playerLogin) 

Link to comment
addEventHandler( "onPlayerQuit", root,  
    function( ) 
        local playerAccount = getPlayerAccount( source ) 
        if playerAccount then 
            local playerMoney = getPlayerMoney( source ) 
            local playerSkin = getElementModel( source ) 
            for i = 0,17 do 
                local arg1,arg2 = getPedClothes( source, i ) 
                setAccountData( playerAccount, "player.clothes."..tostring( i ),tostring( arg1 )..","..tostring( arg2 ) ) 
            end 
            setAccountData( playerAccount, "player.money", playerMoney ) 
            setAccountData( playerAccount, "player.skin", playerSkin ) 
        end 
    end 
)     
  
addEventHandler( "onPlayerLogin", root,  
    function( ) 
        local playerAccount = getPlayerAccount( source ) 
        if playerAccount then 
            local playerMoney = getAccountData( playerAccount, "player.money" ) 
            local playerSkin = getAccountData( playerAccount, "player.skin" ) 
            if playerMoney then 
                setPlayerMoney( source, playerMoney ) 
                setElementModel( source, playerSkin ) 
                for i = 0,17 do 
                    local acc = getAccountData( playerAccount, 'player.clothes.'..i ) 
                    if not acc:find 'false'  then 
                        addPedClothes( source,acc:sub( 1,acc:find( ',' ) - 1 ),acc:sub( acc:find( ',' ) + 1,acc:len( ) ),i ) 
                    end 
                end 
            end 
        end  
    end 
) 

Link to comment

Thank you it works :D

but can you explain what they are:

for i = 0,17 do -- is it a table? 
                local arg1,arg2 = getPedClothes( source, i ) 
                setAccountData( playerAccount, "player.clothes."..tostring( i ),tostring( arg1 )..","..tostring( arg2 ) ) -- what is tostring for? 
  

for i = 0,17 do 
                    local acc = getAccountData( playerAccount, 'player.clothes.'..i ) 
                    if not acc:find 'false'  then -- does that check if player has clothes on it? 
                        addPedClothes( source,acc:sub( 1,acc:find( ',' ) - 1 ),acc:sub( acc:find( ',' ) + 1,acc:len( ) ),i ) -- and this is very confusing 

Thank you again :D

Link to comment
for i = 0,17 do -- cycle from 0 to 17 
    local arg1,arg2 = getPedClothes( source, i ) -- get ped Clothes ( 0 - 17 ) 
    setAccountData(  
        playerAccount, -- player account 
        "player.clothes."..tostring( i ), -- setAccountData in cycle from 0 to 17 
        tostring( arg1 )..","..tostring( arg2 ) -- tostring( because function getPedClothes can return false ( boolean type , not string ) ) 
    ) 
end 
  
  
for i = 0,17 do -- cycle from 0 to 17 
    local acc = getAccountData( playerAccount, 'player.clothes.'..i ) -- getAccountData in cycle from 0 to 17 
    if not acc:find 'false'  then -- Check if returned value getAccountData not have false ( If getAccountData have model/texture  ) 
        addPedClothes(  
            source, -- element ( player in our case ) 
            acc:sub( 1,acc:find( ',' ) - 1 ), -- return string from 1,( to the end until you find a character ',' ) example 100,1000  
            --[[ 
                tostring( '100,1000' ):sub( 1,tostring( '100,1000' ):find( ',' ) - 1 ) 
                So it return 100 
                 
                You can test it in lua demo [url=http://www.lua.org/cgi-bin/demo]http://www.lua.org/cgi-bin/demo[/url] 
                 
                print( tostring( '100,1000' ):sub( 1,tostring( '100,1000' ):find( ',' ) - 1 ) ) 
            ]] 
            acc:sub( acc:find( ',' ) + 1,acc:len( ) ), 
            --[[ 
                -- return string from , and to string length 
                -- tostring( '100,1000' ):sub( tostring( '100,1000' ):find( ',' ) + 1,tostring( '100,1000' ):len( ) ) 
                -- return 1000 
                 
                You can test it too in lua demo [url=http://www.lua.org/cgi-bin/demo]http://www.lua.org/cgi-bin/demo[/url] 
                 
                print( tostring( '100,1000' ):sub( tostring( '100,1000' ):find( ',' ) + 1,tostring( '100,1000' ):len( ) ) ) 
                 
                -- return 1000 
            ]] 
            i  
        ) -- add Ped Clothes cycle from 0 to 17 
    end 
end 

Edited by Guest
Link to comment

line:2 bad argument @getPlayerAccount [expected element at argument 1, got nil] idk what's wrong with that :S i wanted to save skin when players type /skinsave

function changeTheSkin() 
        local playerAccount = getPlayerAccount(source) 
        if playerAccount then 
            local playerSkin = getElementModel(source) 
            for i = 0,17 do 
                local arg1,arg2 = getPedClothes( source, i ) 
                setAccountData( playerAccount, "player.clothes."..tostring( i ),tostring( arg1 )..","..tostring( arg2 ) ) 
            end 
            setAccountData( playerAccount, "player.skin", playerSkin ) 
        outputChatBox("#FF0000*INFO: #0095FFYour skin was successfully saved!", 0, 255, 0) 
        end 
    end 
addCommandHandler( "skinsave", changeTheSkin)  
  
addEventHandler( "onPlayerLogin", root, 
    function( ) 
        local playerAccount = getPlayerAccount( source ) 
        if playerAccount then 
            local playerSkin = getAccountData( playerAccount, "player.skin" ) 
            if playerSkin then 
                setElementModel( source, playerSkin ) 
                for i = 0,17 do 
                    local acc = getAccountData( playerAccount, 'player.clothes.'..i ) 
                    if not acc:find 'false'  then 
                        addPedClothes( source,acc:sub( 1,acc:find( ',' ) - 1 ),acc:sub( acc:find( ',' ) + 1,acc:len( ) ),i ) 
                    end 
                end 
            end 
        end  
    end 
) 

Link to comment
function changeTheSkin( source ) 
    local playerAccount = getPlayerAccount( source ) 
    if playerAccount and not isGuestAccount( playerAccount ) then 
        for i = 0,17 do 
            local arg1,arg2 = getPedClothes( source, i ) 
            setAccountData( playerAccount, "player.clothes."..tostring( i ),tostring( arg1 )..","..tostring( arg2 ) ) 
        end 
        setAccountData( playerAccount, "player.skin", getElementModel( source ) ) 
        outputChatBox("#FF0000*INFO: #0095FFYour skin was successfully saved!",root, 0, 255, 0) 
    end 
end 
addCommandHandler( "skinsave", changeTheSkin )  
  
addEventHandler( "onPlayerLogin", root, 
    function( ) 
        local playerAccount = getPlayerAccount( source ) 
        if playerAccount then 
            local playerSkin = getAccountData( playerAccount, "player.skin" ) 
            if playerSkin then 
                setElementModel( source, playerSkin ) 
                for i = 0,17 do 
                    local acc = getAccountData( playerAccount, 'player.clothes.'..i ) 
                    if not acc:find 'false'  then 
                        addPedClothes( source,acc:sub( 1,acc:find( ',' ) - 1 ),acc:sub( acc:find( ',' ) + 1,acc:len( ) ),i ) 
                    end 
                end 
            end 
        end  
    end 
) 

Because you not add source argument to function 'changeTheSkin'.

https://wiki.multitheftauto.com/wiki/AddCommandHandler

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