Jump to content

sorry i need to ask again. XMLNodeGetChildern error


HanSmith

Recommended Posts

It's about load tent again.

function loadd(player,cmd,nazwa) 
    if player and isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(player)), aclGetGroup("Save")) then 
        local xml = xmlLoadFile ( "tents.xml" ) 
        pobierzinfo = xmlNodeGetChildren ( xml ) 
        for i,nam in pairs(pobierzinfo ) do 
            wsp = xmlFindChild(nam,"wsp",0) 
            item = xmlFindChild(nam,"item",0) 
            px = xmlFindChild(wsp,"PX",0) 
            py = xmlFindChild(wsp,"PY",0) 
            pz = xmlFindChild(wsp,"PZ",0) 
            rx = xmlFindChild(wsp,"RX",0) 
            ry = xmlFindChild(wsp,"RY",0) 
            rz = xmlFindChild(wsp,"RZ",0) 
            local pxx = xmlNodeGetValue ( px ) 
            local pyy = xmlNodeGetValue ( py ) 
            local pzz = xmlNodeGetValue ( pz ) 
            local rxx = xmlNodeGetValue ( rx ) 
            local ryy = xmlNodeGetValue ( ry ) 
            local rzz = xmlNodeGetValue ( rz ) 
            ilosc = ilosc + 1 
            tent = createObject(3243, pxx, pyy, pzz, rxx, ryy, rzz) 
            setObjectScale(tent, 1) 
            tentCol = createColSphere(pxx, pyy, pzz,  3) 
            attachElements(tentCol, tent, 0, 0, 0) 
            setElementData(tentCol, "parent", tent) 
            setElementData(tent, "parent", tentCol) 
            setElementData(tentCol, "tent", true) 
            setElementData(tentCol, "vehicle", true) 
            setElementData(tentCol, "MAX_Slots", 150) 
            local item = xmlNodeGetChildren(item) 
            for i,it in ipairs(itemy) do 
                local wartosc = xmlNodeGetValue (it) 
                local nazwa = xmlNodeGetName(it) 
                item = PobierzItemID(nazwa) 
                setElementData(tentCol, tostring(item), tonumber(wartosc)) 
            end  
        end 
        local xml = xmlLoadFile ( "tents.xml" ) 
        pobierzinfo = xmlNodeGetChildren ( xml ) 
        for i,nam in pairs(pobierzinfo ) do 
            wsp = xmlFindChild(nam,"wsp",0) 
            item = xmlFindChild(nam,"item",0) 
            px = xmlFindChild(wsp,"PX",0) 
            py = xmlFindChild(wsp,"PY",0) 
            pz = xmlFindChild(wsp,"PZ",0) 
            rx = xmlFindChild(wsp,"RX",0) 
            ry = xmlFindChild(wsp,"RY",0) 
            rz = xmlFindChild(wsp,"RZ",0) 
            local pxx = xmlNodeGetValue ( px ) 
            local pyy = xmlNodeGetValue ( py ) 
            local pzz = xmlNodeGetValue ( pz ) 
            local rxx = xmlNodeGetValue ( rx ) 
            local ryy = xmlNodeGetValue ( ry ) 
            local rzz = xmlNodeGetValue ( rz ) 
            ilosc = ilosc + 1 
            tent = createObject(3243, pxx, pyy, pzz, rxx, ryy, rzz) 
            outputChatBox("Loaded in the tent!",player) 
            setObjectScale(tent, 1) 
            tentCol = createColSphere(pxx, pyy, pzz,  3) 
            attachElements(tentCol, tent, 0, 0, 0) 
            setElementData(tentCol, "parent", tent) 
            setElementData(tent, "parent", tentCol) 
            setElementData(tentCol, "tent", true) 
            setElementData(tentCol, "vehicle", true) 
            setElementData(tentCol, "MAX_Slots", 150) 
            local item = xmlNodeGetChildren(item) 
            for i,it in ipairs(itemy) do 
                local wartosc = xmlNodeGetValue (it) 
                local nazwa = xmlNodeGetName(it) 
                item = PobierzItemID(nazwa) 
                setElementData(tentCol, tostring(item), tonumber(wartosc)) 
            end  
        end 
    end 
end 
addCommandHandler("load",loadd) 

tent.xml

    
        
            30.89825630188
            -1528.7371826172
            3.9773645401001
            0
            0
            84.491638183594
        
        
            150
            2Meat> 
            3Human Steak> 
        
    
    
        
            33.021270751953
            -1531.4575195313
            3.9534740447998
            0
            0
            114.57266235352
        
        
            150
        
    
    
        
            43.593379974365
            -1531.1368408203
            4.3415040969849
            0
            0
            238.68133544922
        
        
            150
            3Meat> 
            2Human Steak> 
        
    
    
        
            22.687580108643
            -1529.9561767578
            4.1826195716858
            0
            0
            322.31634521484
        
        
            150
            5Backpack> 
        
    
    
        
            12.01179599762
            -1514.5050048828
            2.7208499908447
            0
            0
            192.17578125
        
        
            150
        
    

  

when i use /load

and this happen :

1.[2015-01-02 23:33:25] WARNING: loadtent.lua:194: Bad argument @ 'xmlNodeGetChildren' [Expected xml-node at argument 1, got boolean]

2.[2015-01-02 23:33:25] ERROR: loadtent.lua:195: bad argument #1 to 'pairs' (table expected, got boolean)

Link to comment
  Necktrox said:
You never close the XML files after you opened them.
xmlUnloadFile(xml) 

And you open the same file twice in one run.

still same problem

i guess it's bug because 5Backpack>

space text.

when i delete all space text.

    
        
            30.89825630188
            -1528.7371826172
            3.9773645401001
            0
            0
            84.491638183594
        
        
            150
            2
            3
        
    
    
        
            33.021270751953
            -1531.4575195313
            3.9534740447998
            0
            0
            114.57266235352
        
        
            150
        
    
    
        
            43.593379974365
            -1531.1368408203
            4.3415040969849
            0
            0
            238.68133544922
        
        
            150
            3
            2
        
    
    
        
            22.687580108643
            -1529.9561767578
            4.1826195716858
            0
            0
            322.31634521484
        
        
            150
            5
        
    
    
        
            12.01179599762
            -1514.5050048828
            2.7208499908447
            0
            0
            192.17578125
        
        
            150
        
    

  

i got this problem

[2015-01-02 23:33:25] ERROR: loadtent.lua:210: attempt to perform arithmetic on global 'ilosc' ( a nil value )

ilosc for load a tent more than 1

and almost my items in my dayz, got a space text, so how can we fix this ? why we cant add space text in a xml ?

Link to comment
  • MTA Team
nazwa = nazwa:gsub("%s", "_") 

Use that to replace whitespace with an underscore.

local xml = xmlLoadFile ( "tents.xml" ) 
        ilosc = 0 
        pobierzinfo = xmlNodeGetChildren ( xml ) 
        for i,nam in pairs(pobierzinfo ) do 

Link to comment
  • MTA Team

Well, you could save your items in that format:

<item name="Hunting Backpack" amount="2"/> 

local c = xmlCreateChild(item) 
xmlNodeSetAttribute(c, "name", "Hunting Backpack") 
xmlNodeSetAttribute(c, "amount", 2) 
  

Link to comment

ok fixed them all, now i got ERROR

[2015-01-02 23:33:25] ERROR: loadtent.lua:210: attempt to perform arithmetic on global 'ilosc' ( a nil value )

save

  Reveal hidden contents

load

  Reveal hidden contents
Link to comment
  Necktrox said:
local xml = xmlLoadFile ( "tents.xml" ) 
ilosc = 0 -- You have to reset the amount 
pobierzinfo = xmlNodeGetChildren ( xml ) 
for i,nam in pairs(pobierzinfo ) do 

Edit: You have to use the 'xml' variable on xmlUnloadFile and you should place it after item-load for.

did you tried these script ?

still error in ilosc attempt to perform

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