HanSmith Posted January 2, 2015 Share Posted January 2, 2015 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
MTA Team botder Posted January 2, 2015 MTA Team Share Posted January 2, 2015 You never close the XML files after you opened them. xmlUnloadFile(xml) And you open the same file twice in one run. Link to comment
HanSmith Posted January 2, 2015 Author Share Posted January 2, 2015 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 botder Posted January 2, 2015 MTA Team Share Posted January 2, 2015 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
HanSmith Posted January 2, 2015 Author Share Posted January 2, 2015 nazwa = nazwa:gsub("%s", "_") Use that to replace whitespace with an underscore. and my "Hunting Backpack" item change to "Hunting_Backpack" ? and thats same, the database item it's read "Hunting Backpack" not "Hunting_Backpack" Link to comment
MTA Team botder Posted January 2, 2015 MTA Team Share Posted January 2, 2015 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
HanSmith Posted January 2, 2015 Author Share Posted January 2, 2015 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) read pm. Link to comment
HanSmith Posted January 2, 2015 Author Share Posted January 2, 2015 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 local itemy = { {"MAX_Slots"}, {"12 Gauge 20 Rounds Buckshot"}, {".357 20 Rounds"}, {".22 20 Rounds"}, {"7.62x39mm 20 Rounds"}, {"7.62x51mm 20 Rounds"}, {".45ACP 20 Rounds"}, {"5.56mm 20 Rounds"}, {"9mm 20 Rounds"}, {".357"}, {"7.62x39mm"}, {"7.62x51mm"}, {".45ACP"}, {"5.56mm"}, {"Bolt"}, {"9mm"}, {"Blaze 95 Pellet"}, {"2Rnd. Buckshot"}, {"12 Gauge Buckshot"}, {".22"}, {"Launcher Grenade"}, {"M107 Mag"}, {"MP5-K Mag"}, {"PDW Mag"}, {"Sawn-Off IZH-43"}, {"IZH-43"}, {"Mosin 9130"}, {"Magnum"}, {"FNX45"}, {"Blaze 95"}, {"MP5-K"}, {"M107"}, {"TEC-9"}, {"CR75"}, {"М4А1"}, {"AK 101"}, {"PDW"}, {"AKM"}, {"Crossbow"}, {"SKS"}, {"Sporter 22"}, {"Grenade Launcher"}, {"Steyr AUG"}, {"Baseball Bat"}, {"Brass Knuckles"}, {"Baseball Bat with Nails"}, {"Firefighter Axe"}, {"Hunting Knife"}, {"Crowbar"}, {"Machete"}, {"Chainsaw"}, {"Meat Cleaver"}, {"Shovel"}, {"Axe"}, {"Smoke Grenade"}, {"Grenade"}, {"Exploder (С4)"}, {"Dynamite"}, {"Land Mine"}, {"С4"}, {"Molotov Cocktail"}, {"Empty Vodka"}, {"Empty Water Bottle"}, {"Potato"}, {"Orange"}, {"Banana"}, {"Pasta Can (open)"}, {"Can of Bacon (open)"}, {"Beans Can (open)"}, {"Can of Sardines (open)"}, {"Pasta Can (close)"}, {"Can of Bacon (close)"}, {"Beans Can (close)"}, {"Can of Sardines (close)"}, {"Tuna"}, {"Coke"}, {"Sprite"}, {"Pepsi"}, {"Chivas"}, {"Chips"}, {"Milk Powder"}, {"Rice"}, {"Pile of Guts"}, {"Empty Canteen"}, {"Empty Can"}, {"Empty Soda Can"}, {"Water Bottle"}, {"Cooked Meat"}, {"Raw Meat"}, {"Cooked Human Steak"}, {"Raw Human Steak"}, {"Canteen"}, {"Absorbent carbon"}, {"Painkiller"}, {"Blood Bag"}, {"Antibiotics"}, {"Albendazole"}, {"Thermometer"}, {"Ibuprofen"}, {"Vitamin"}, {"First Aid Kit"}, {"Morphine"}, {"Heater"}, {"Vodka"}, {"Bandage"}, {"Full Gas Canister"}, {"Empty Gas Canister"}, {"Engine"}, {"Tank Parts"}, {"Tire"}, {"Headlights"}, {"Wooden Stick"}, {"Nitroglycerin"}, {"Nails"}, {"Hacksaw"}, {"Rope"}, {"Stone"}, {"Log"}, {"Stones"}, {"Powder"}, {"Bag"}, {"Firewood"}, {"Huna"}, {"Molotov Cocktail"}, {"Homemade Molotov Cocktail"}, {"Powder Bottle"}, {"Powder Bottle with Nails"}, {"Can of Powder"}, {"Wirefence"}, {"Infrared Goggles"}, {"Toolbox"}, {"Pliers"}, {"Can Opener"}, {"Flare"}, {"Tent"}, {"Binoculars"}, {"Parachute"}, {"Flashlight*"}, {"Flashlight"}, {"Battery"}, {"Matchbox"}, {"Map"}, {"Radio"}, {"Watch"}, {"GPS"}, {"Nightvision Goggles"}, {"Handcuff"}, {"Keys"}, {"Epinephrine"}, {"Head Flashlight"}, {"Head Flashlight*"}, {"Motorcycle Helmet"}, {"Tactical Vest"}, {"Kevlar Vest"}, {"Rocket Aviators"}, {"Cowboy Hat"}, {"Metal Gear Helm"}, {"Police Hat"}, {"Mask 'Hoxton'"}, {"Mask 'Dallas'"}, {"Mask 'Wolf'"}, {"Round Cap"}, {"Flat Cap"}, {"Military Helmet"}, {"Doctor Mask"}, {"Gas Mask"}, {"Ghillie Suit"}, {"Earflaps"}, {"Panama"}, {"Cap"}, {"Beret"}, {"Childern's Bag"}, {"Homemade Bag"}, {"Improvised Bag"}, {"Taloon Backpack"}, {"Hunting Backpack"}, {"Mountain Backpack"}, } function automat(gracz) if gracz and isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(gracz)), aclGetGroup("Save")) then outputChatBox("Saving of tents was initiated!",gracz,0,255,0,true) else return end namiot = xmlCreateFile("tents.xml","root") id = 0 ilosc = 0 for i, col in ipairs(getElementsByType("colshape")) do if col then local tent = getElementData(col, "tent") if tent then local namiotek = getElementData(col, "parent") local x, y, z = getElementPosition(namiotek) local rx, ry, rz = getElementRotation(namiotek) local namiote = xmlCreateChild (namiot,"Namiot") local namiot = xmlCreateChild (namiote,"wsp") local namioti = xmlCreateChild (namiote,"itemy") xmlNodeSetValue (xmlCreateChild ( namiot, "PX"), tostring(x) ) xmlNodeSetValue (xmlCreateChild ( namiot, "PY"), tostring(y) ) xmlNodeSetValue (xmlCreateChild ( namiot, "PZ"), tostring(z) ) xmlNodeSetValue (xmlCreateChild ( namiot, "RX"), tostring(rx) ) xmlNodeSetValue (xmlCreateChild ( namiot, "RY"), tostring(ry) ) xmlNodeSetValue (xmlCreateChild ( namiot, "RZ"), tostring(rz) ) id = 0 for i, v in ipairs(itemy) do local item = getElementData(col, v[1]) if item then if item >= 1 then itemID = (v[1]) xmlNodeSetValue (xmlCreateChild ( namioti, tostring(itemID)), tostring(item) ) end end end end end end xmlSaveFile(namiot) xmlUnloadFile(namiot) if gracz then outputChatBox("Tents saved!",gracz,0,255,0,true) end end addCommandHandler("save",automat) load local itemy = { {"MAX_Slots"}, {"12 Gauge 20 Rounds Buckshot"}, {".357 20 Rounds"}, {".22 20 Rounds"}, {"7.62x39mm 20 Rounds"}, {"7.62x51mm 20 Rounds"}, {".45ACP 20 Rounds"}, {"5.56mm 20 Rounds"}, {"9mm 20 Rounds"}, {".357"}, {"7.62x39mm"}, {"7.62x51mm"}, {".45ACP"}, {"5.56mm"}, {"Bolt"}, {"9mm"}, {"Blaze 95 Pellet"}, {"2Rnd. Buckshot"}, {"12 Gauge Buckshot"}, {".22"}, {"Launcher Grenade"}, {"M107 Mag"}, {"MP5-K Mag"}, {"PDW Mag"}, {"Sawn-Off IZH-43"}, {"IZH-43"}, {"Mosin 9130"}, {"Magnum"}, {"FNX45"}, {"Blaze 95"}, {"MP5-K"}, {"M107"}, {"TEC-9"}, {"CR75"}, {"М4А1"}, {"AK 101"}, {"PDW"}, {"AKM"}, {"Crossbow"}, {"SKS"}, {"Sporter 22"}, {"Grenade Launcher"}, {"Steyr AUG"}, {"Baseball Bat"}, {"Brass Knuckles"}, {"Baseball Bat with Nails"}, {"Firefighter Axe"}, {"Hunting Knife"}, {"Crowbar"}, {"Machete"}, {"Chainsaw"}, {"Meat Cleaver"}, {"Shovel"}, {"Axe"}, {"Smoke Grenade"}, {"Grenade"}, {"Exploder (С4)"}, {"Dynamite"}, {"Land Mine"}, {"С4"}, {"Molotov Cocktail"}, {"Empty Vodka"}, {"Empty Water Bottle"}, {"Potato"}, {"Orange"}, {"Banana"}, {"Pasta Can (open)"}, {"Can of Bacon (open)"}, {"Beans Can (open)"}, {"Can of Sardines (open)"}, {"Pasta Can (close)"}, {"Can of Bacon (close)"}, {"Beans Can (close)"}, {"Can of Sardines (close)"}, {"Tuna"}, {"Coke"}, {"Sprite"}, {"Pepsi"}, {"Chivas"}, {"Chips"}, {"Milk Powder"}, {"Rice"}, {"Pile of Guts"}, {"Empty Canteen"}, {"Empty Can"}, {"Empty Soda Can"}, {"Water Bottle"}, {"Cooked Meat"}, {"Raw Meat"}, {"Cooked Human Steak"}, {"Raw Human Steak"}, {"Canteen"}, {"Absorbent carbon"}, {"Painkiller"}, {"Blood Bag"}, {"Antibiotics"}, {"Albendazole"}, {"Thermometer"}, {"Ibuprofen"}, {"Vitamin"}, {"First Aid Kit"}, {"Morphine"}, {"Heater"}, {"Vodka"}, {"Bandage"}, {"Full Gas Canister"}, {"Empty Gas Canister"}, {"Engine"}, {"Tank Parts"}, {"Tire"}, {"Headlights"}, {"Wooden Stick"}, {"Nitroglycerin"}, {"Nails"}, {"Hacksaw"}, {"Rope"}, {"Stone"}, {"Log"}, {"Stones"}, {"Powder"}, {"Bag"}, {"Firewood"}, {"Huna"}, {"Molotov Cocktail"}, {"Homemade Molotov Cocktail"}, {"Powder Bottle"}, {"Powder Bottle with Nails"}, {"Can of Powder"}, {"Wirefence"}, {"Infrared Goggles"}, {"Toolbox"}, {"Pliers"}, {"Can Opener"}, {"Flare"}, {"Tent"}, {"Binoculars"}, {"Parachute"}, {"Flashlight*"}, {"Flashlight"}, {"Battery"}, {"Matchbox"}, {"Map"}, {"Radio"}, {"Watch"}, {"GPS"}, {"Nightvision Goggles"}, {"Handcuff"}, {"Keys"}, {"Epinephrine"}, {"Head Flashlight"}, {"Head Flashlight*"}, {"Motorcycle Helmet"}, {"Tactical Vest"}, {"Kevlar Vest"}, {"Rocket Aviators"}, {"Cowboy Hat"}, {"Metal Gear Helm"}, {"Police Hat"}, {"Mask 'Hoxton'"}, {"Mask 'Dallas'"}, {"Mask 'Wolf'"}, {"Round Cap"}, {"Flat Cap"}, {"Military Helmet"}, {"Doctor Mask"}, {"Gas Mask"}, {"Ghillie Suit"}, {"Earflaps"}, {"Panama"}, {"Cap"}, {"Beret"}, {"Childern's Bag"}, {"Homemade Bag"}, {"Improvised Bag"}, {"Taloon Backpack"}, {"Hunting Backpack"}, {"Mountain Backpack"}, } 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) xmlUnloadFile("tents.xml") 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 Link to comment
MTA Team botder Posted January 2, 2015 MTA Team Share Posted January 2, 2015 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. Link to comment
HanSmith Posted January 2, 2015 Author Share Posted January 2, 2015 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
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