Jump to content

XML Help


TimJ

Recommended Posts

Im playing with xml at the moment, but what im trying to do is get the players name as the name of the subnode and the content to be their current vehicle but its not working... Heres the code:

function xml ( source ) 
local name = getPlayerNametagText ( source ) 
local content = getPlayerOccupiedVehicle ( source ) 
  
local xmlFile=xmlLoadFile("xmlfile.xml") 
 local node=xmlCreateSubNode(xmlfile, name) 
 local success=xmlNodeSetValue(node, content) 
                if success then 
                        xmlSaveFile(xmlFile) 
  
                end 
end 
  
addCommandHandler("test", xml) 

i had a previous version that worked and made a subnode of their player name but put the content as "content" but after changing it to try and work how i wanted to it doesnt work :S

Link to comment

K ive changed that:

function xml ( source ) 
local name = getPlayerNametagText(source) 
local vehicle = getPlayerOccupiedVehicle(source) 
local content = getVehicleName(vehicle) 
  
local xmlFile=xmlLoadFile("xmlfile.xml") 
 local node=xmlCreateSubNode(xmlfile, name) 
 local success=xmlNodeSetValue(node, content) 
                if success then 
                        xmlSaveFile(xmlFile) 
  
                end 
end 
  
addCommandHandler("test", xml) 

but i get these errors:

Bad argument @ 'xmlCreateSubNode' - Line: 7 
Bad argument @ 'xmlNodeSetValue' -Line: 8 

Link to comment
function xml ( player ) 
local name = getPlayerNametagText(player) 
local vehicle = getPlayerOccupiedVehicle(player) 
local content = getVehicleName(vehicle) 
  
local xmlFile=xmlLoadFile("xmlfile.xml") 
 local node=xmlCreateSubNode(xmlfile, name) 
 local success=xmlNodeSetValue(node, content) 
                if success then 
                        xmlSaveFile(xmlFile) 
  
                end 
end 
  
addCommandHandler("test", xml) 

Try replacing source with player. (like I did above) Should help. And if it didn't, it would still be a good reminder to NOT define source yourself. It'll only get you in trouble... =/

Link to comment

Thanks all, ive got it working. Now im on the next bit of the script, which "co-incidently" im having trouble with too lol:

function getcar ( source ) 
local name = getPlayerNametagText(source) 
local xmlFile=xmlLoadFile("xmlfile.xml")  
  
if xmlFile then --If it's indeed opened: 
        local node=xmlFindSubNode(xmlFile,"somesubnode",0)  
        local success=xmlNodeGetValue(node) 
                if success then  
                    outputChatBox(tostring(success)) 
                end  
        end 
outputChatBox( "done", source ) 
  
warpPlayerIntoVehicle ( playerSource, success )  
end 
  
addCommandHandler("getcar", getcar) 
  
  

i get this error: Bad Argument @ 'warpPlayerIntoVehicle' - Line: 31

Whats wrong with it :(?

Link to comment
Thanks all, ive got it working. Now im on the next bit of the script, which "co-incidently" im having trouble with too lol:

function getcar ( source ) 
local name = getPlayerNametagText(source) 
local xmlFile=xmlLoadFile("xmlfile.xml")  
  
if xmlFile then --If it's indeed opened: 
        local node=xmlFindSubNode(xmlFile,"somesubnode",0)  
        local success=xmlNodeGetValue(node) 
                if success then  
                    outputChatBox(tostring(success)) 
                end  
        end 
outputChatBox( "done", source ) 
  
warpPlayerIntoVehicle ( playerSource, success )  
end 
  
addCommandHandler("getcar", getcar) 
  
  

i get this error: Bad Argument @ 'warpPlayerIntoVehicle' - Line: 31

Whats wrong with it :(?

Try:

function getcar ( source ) 
local name = getPlayerNametagText(source) 
local xmlFile=xmlLoadFile("xmlfile.xml")  
  
if xmlFile then --If it's indeed opened: 
        local node=xmlFindSubNode(xmlFile,"somesubnode",0)  
        local success=xmlNodeGetValue(node) 
                if success then  
                    outputChatBox(tostring(success)) 
                end  
        end 
outputChatBox( "done", source ) 
  
warpPlayerIntoVehicle ( source, success )  
end 
  
addCommandHandler("getcar", getcar) 
  
  

Link to comment

Have no idea what vivalavido tried, but TimJ, you are trying to warp a player into a string...

local success=xmlNodeGetValue(node) 

and later on

warpPlayerIntoVehicle ( playerSource, success ) 

Wiki gives this syntax:

bool warpPlayerIntoVehicle ( player thePlayer, vehicle theVehicle, [ int seat=0 ] ) 

Which means that you need to put a variable pointing at vehicle element to the second place not a string.

And to be honest, you don't have playerSource variable defined anywhere either, so basically you are doing

warpPlayerIntoVehicle(nil, "somestring")

No wonder it doesn't work..

And on another look you actually do

warpPlayerIntoVehicle(nil, nil) 

since you defined

local success = blah 

inside an if statement.. Which means that it doesn't exist outside it

EDIT: If you can say what you want to achieve with the script, we might help a bit more than only find errors in your script.

Link to comment

Well basicly the first part gets the car your in and saves it in a meta file like this:

car name

e.g <{TJT}Tim>Police{TJT}Tim>

I've done that and it works fine, but what i want it to do now is retrieve the information so that it will give you the car saved with your name.

And i didnt really understand this:

Wiki gives this syntax:

Line number On/Off | Expand/Contract | Select all

bool warpPlayerIntoVehicle ( player thePlayer, vehicle theVehicle, [ int seat=0 ] )

Which means that you need to put a variable pointing at vehicle element to the second place not a string.

Link to comment

You shouldn't make tags which are the name of player. Your example of: <{TJT}Tim>Police{TJT}Tim> is wrong format of XML. You can't use { or } in XML tags or attributes. Use different way, like:

Police or something else.

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