Jump to content

trouble with a script


Jumba'

Recommended Posts

Hi, I;m trying to make a script here and it works for the most part, but it doesn't insert the player username into the xml file and it returns these errors, here's the script & errors.

function setLicenseData ( source, command, playername, status, license ) 
    local player = getPlayerFromNick ( playername ) 
    local username = getAccountName ( getClientAccount ( player ) ) 
    local playerlicense = xmlFindSubNode ( data, "playerlicense", 0 ) 
    local playerlicensedata = xmlFindSubNode ( playerlicense, "license", 0 )     
     
        if ( ( license == "car" ) and ( status == "grant" or "revoke" ) ) then 
            xmlNodeSetAttribute( playerlicensedata, "player", username ) 
            xmlNodeSetAttribute( playerlicensedata, "car", status ) 
            xmlSaveFile ( data ) 
            elseif ( ( license == "bike" ) and ( status == "grant" or "revoke" ) ) then 
                xmlNodeSetAttribute( playerlicensedata, "player", username ) 
                xmlNodeSetAttribute( playerlicensedata, "bike", status ) 
                xmlSaveFile ( data ) 
                elseif ( ( license == "pilot" ) and ( status == "grant" or "revoke" ) ) then 
                    xmlNodeSetAttribute( playerlicensedata, "player", username ) 
                    xmlNodeSetAttribute( playerlicensedata, "pilot", status ) 
                    xmlSaveFile ( data ) 
        else 
            outputChatBox ( "Syntax error, type /help license for more information on licenses.", source, 255, 255, 0, false ) 
        end  
end 
  
  
  
-- WARNING: license.lua: Bad argument @ 'getClientAccount' - Line: 3 
-- WARNING: license.lua: Bad argument @ 'getAccountName' - Line: 3 
-- WARNING: license.lua: Bad argument @ 'xmlNodeSetAttribute' - Line: 8 
  

Anyone know what the problem may be?

Link to comment

Well, it's fairly obvious. Bad argument means you're passing something you shouldn't be.

So, the values you're passing and getting errors on are all returned from other functions. I can't tell exactly what the issue is, but why not output some of the intermediate values - see what getPlayerFromNick returns for example - does it return nil or false? Do the same with your playerlicensedata variable.

Most likely, the playername you're specifying doesn't exist, causing getPlayerFromNick to return nil (or false). That's then passed to getClientAccount thats returning nil, causing getAccountName to give an error.

Presumably the xml error on line 8 is because you don't have a node called 'license' inside your 'playerlicense' node of your xml file.

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