stefutz101 Posted April 3, 2016 Share Posted April 3, 2016 Hi. I work a resource what save vehicles in a xml file. vehicles.map "416" id="4478" posx="1178.0419921875" posy="-1308.537109375" posz="14.001264572144" rotx="356.05041503906" roty="0.6591796875" rotz="269.79675292969" interior="0" dimension="0" color1="1" color2="3" health="1000" fuel="100" engineState="0" lightsState="0" handbrakeState="1" lockState="0" factionid="8573" createdby="st3f101" owner="-1" tinted="0"> For example i have 1 vehicle saved in xml file. I have a function what create a vehicle and save it in xml file.But the problem is : after i created a new vehicle it appear i xml file but i must restart the resource because xmlLoadFile dont reload the file. For example i create a vehicle . When i want to park that vehicle , it modifity in xml file x y z for that vehicle. If i dont restart the resource it cant find car in resource. After i restarted resource , all works fine. How i can fix that ? This is isn't working fine because my xml file is a .map file ? Link to comment
Ab-47 Posted April 3, 2016 Share Posted April 3, 2016 Create a check each interval using setTimer() to check the location of the vehicle and save it in the XML each time. Link to comment
stefutz101 Posted April 4, 2016 Author Share Posted April 4, 2016 I cant simply load xml file save it , and unload ? BTW: i changed vehicles.map extension in vehicles.xml extension. I cant use this functions ? xmlLoadFile xmlSaveFile xmlUnloadFile And btw vehicles ARE SAVED in that file . But i dont know how to reload xml file each time i created a new vehicle. Because once i created a new vehicle it add a new child in vehicles.xml . And for example if i want to park a vehicle just created it search in xml file vehicle with the same id with my occupied vehicle and modify his x y z in xml file. This isn't working if i dont restart resource. If i will create vehicle and i will restart resource and after that i will try to park vehicle , it work fine. Link to comment
stefutz101 Posted April 5, 2016 Author Share Posted April 5, 2016 I dont want the fix , i just want i ideea how to fix this thing ... Link to comment
ALw7sH Posted April 5, 2016 Share Posted April 5, 2016 You might be not using xmlSaveFile and xmlUnloadFile right, but I suggest you to not change the xml running until the script stops since the xml is kinda slow, store everything in table so you can have a faster access to everything then save everything on the xml file when the scripts stops Link to comment
Captain Cody Posted April 5, 2016 Share Posted April 5, 2016 When you save it, first save, unload, then reload. Link to comment
stefutz101 Posted April 6, 2016 Author Share Posted April 6, 2016 Good ideea . i will try and i will post the result . Thanks. Link to comment
stefutz101 Posted April 6, 2016 Author Share Posted April 6, 2016 Good ideea . i will try and i will post the result . Thanks. Link to comment
Deepu Posted April 6, 2016 Share Posted April 6, 2016 You wanna get the data within a certain Time Interval? I didn't understand sorry Link to comment
Deepu Posted April 6, 2016 Share Posted April 6, 2016 You wanna get the data within a certain Time Interval? I didn't understand sorry Link to comment
stefutz101 Posted April 6, 2016 Author Share Posted April 6, 2016 Nope. For example i create a new veh when i create a new veh it add a new child in xml file with x y z , owner etc . When i want to park vehicle it get id of my occupied vehicle and search it in xml file. But i dont know how to reload that xml file and he cant find it. Once i restart the resource it works fine . Link to comment
stefutz101 Posted April 6, 2016 Author Share Posted April 6, 2016 Nope. For example i create a new veh when i create a new veh it add a new child in xml file with x y z , owner etc . When i want to park vehicle it get id of my occupied vehicle and search it in xml file. But i dont know how to reload that xml file and he cant find it. Once i restart the resource it works fine . Link to comment
Deepu Posted April 7, 2016 Share Posted April 7, 2016 Something that you didn't know about XML is that its just a file... and all filesystem commands take place even when the server is running.. But.. to update its contents.. you must restart the server. Try using a text file or any binary file.. The same thing happens. This cannot be done in XML no matter what. XML is not fit for Updation and stuffs related to updating the nodes every time. That's why it works after you restart the server. Try SQLite or MySQL.. it should work fine because These are Relational Database Management systems.. These are dynamic and can be updated anytime anywhere in any millisecond. But XMLs lag and they don't update. You have to restart he server to update it. Hope I answered your question Link to comment
Deepu Posted April 7, 2016 Share Posted April 7, 2016 Something that you didn't know about XML is that its just a file... and all filesystem commands take place even when the server is running.. But.. to update its contents.. you must restart the server. Try using a text file or any binary file.. The same thing happens. This cannot be done in XML no matter what. XML is not fit for Updation and stuffs related to updating the nodes every time. That's why it works after you restart the server. Try SQLite or MySQL.. it should work fine because These are Relational Database Management systems.. These are dynamic and can be updated anytime anywhere in any millisecond. But XMLs lag and they don't update. You have to restart he server to update it. Hope I answered your question Link to comment
Anubhav Posted April 7, 2016 Share Posted April 7, 2016 Better way, load everything from XML to a table. Then whenever you add things.etc do it in the table. AT THE resource stop add them into the XML file. Tables are even easier to use! Link to comment
Anubhav Posted April 7, 2016 Share Posted April 7, 2016 Better way, load everything from XML to a table. Then whenever you add things.etc do it in the table. AT THE resource stop add them into the XML file. Tables are even easier to use! Link to comment
Moderators IIYAMA Posted April 7, 2016 Moderators Share Posted April 7, 2016 You can reload a map file. Add these functions to your list: loadMapData -- restart, destory the element created by loadMapData destroyElement -- Re-use loadMapData Link to comment
Moderators IIYAMA Posted April 7, 2016 Moderators Share Posted April 7, 2016 You can reload a map file. Add these functions to your list: loadMapData -- restart, destory the element created by loadMapData destroyElement -- Re-use loadMapData Link to comment
Captain Cody Posted April 7, 2016 Share Posted April 7, 2016 A file will save while server is running I know that for a fact. I use the xmls for a mod shop to keep track of vehicles 'Easier to remove/delete while server is running' and update perfectly. Link to comment
Captain Cody Posted April 7, 2016 Share Posted April 7, 2016 A file will save while server is running I know that for a fact. I use the xmls for a mod shop to keep track of vehicles 'Easier to remove/delete while server is running' and update perfectly. Link to comment
stefutz101 Posted April 7, 2016 Author Share Posted April 7, 2016 Isnt working ... addCommandHandler({"createvehicle", "makeveh", "makevehicle", "makecar"}, function(player, cmd, name, color1, color2, tint, owner) if exports.brpExports:isPlayerLeadAdmin(player) then xml = xmlLoadFile("vehicles.xml") if name and color1 and color2 and tint then local find_ = string.find(name, "_") if tonumber(color1) >= 0 and tonumber(color1) <= 126 and tonumber(color2) >= 0 and tonumber(color2) <= 126 then local px, py, pz = getElementPosition(player) local rx, ry, rz = getElementRotation(player) local interior = getElementInterior(player) local dimension = getElementDimension(player) local model1 = getVehicleModelFromName(string.gsub(name,"_"," ")) local model2 = getVehicleModelFromName(tostring(name)) local new = xmlCreateChild(xml, "veh") local id = math.random(1,99999) if find_ then vehh = createVehicle(model1, px + 4, py, pz, rx, ry, rz) outputChatBox("Created a " .. getVehicleNameFromModel(model1) .. " with ID " .. tonumber(id) .. ".", player, 0, 255, 0, false) outputServerLog("[VEHICLE] [CMD/CREATEVEHICLE]: " .. getPlayerName(player) .. " created a " .. getVehicleNameFromModel(model1) .. " with ID " .. tonumber(id) .. ".") xmlNodeSetAttribute(new, "model", tonumber(model1)) else vehh = createVehicle(model2, px + 4, py, pz, rx, ry, rz) outputChatBox("Created a " .. getVehicleNameFromModel(model2) .. " with ID " .. tonumber(id) .. ".", player, 0, 255, 0, false) outputServerLog("[VEHICLE] [CMD/CREATEVEHICLE]: " .. getPlayerName(player) .. " created a " .. getVehicleNameFromModel(model2) .. " with ID " .. tonumber(id) .. ".") xmlNodeSetAttribute(new, "model", tonumber(model2)) end local vpx, vpy, vpz = getElementPosition(vehh) local vrx, vry, vrz = getElementRotation(vehh) xmlNodeSetAttribute(new, "id", tonumber(id)) xmlNodeSetAttribute(new, "posx", tonumber(vpx)) xmlNodeSetAttribute(new, "posy", tonumber(vpy)) xmlNodeSetAttribute(new, "posz", tonumber(vpz)) xmlNodeSetAttribute(new, "rotx", tonumber(vrx)) xmlNodeSetAttribute(new, "roty", tonumber(vry)) xmlNodeSetAttribute(new, "rotz", tonumber(vrz)) xmlNodeSetAttribute(new, "interior", tonumber(interior)) xmlNodeSetAttribute(new, "dimension", tonumber(dimension)) xmlNodeSetAttribute(new, "color1", tonumber(color1)) xmlNodeSetAttribute(new, "color2", tonumber(color2)) xmlNodeSetAttribute(new, "health", 1000) xmlNodeSetAttribute(new, "fuel", 100) xmlNodeSetAttribute(new, "engineState", 0) xmlNodeSetAttribute(new, "lightsState", 0) xmlNodeSetAttribute(new, "handbrakeState", 1) xmlNodeSetAttribute(new, "lockState", 0) xmlNodeSetAttribute(new, "factionid", 0) xmlNodeSetAttribute(new, "createdby", getPlayerName(player)) if owner then local target = exports.brpExports:findPlayer(owner, player) if target then local acc = getPlayerAccount(target) xmlNodeSetAttribute(new, "owner", getAccountName(acc)) setElementData(vehh, "vehicle.owner", getAccountName(acc)) else outputChatBox("Failed to set the owner. Default set.", player, 255, 0, 0, false) end else xmlNodeSetAttribute(new, "owner", 0) setElementData(vehh, "vehicle.owner", 0) end if tonumber(tint) == 0 then xmlNodeSetAttribute(new, "tinted", 0) elseif tonumber(tint) == 1 then xmlNodeSetAttribute(new, "tinted", 1) else xmlNodeSetAttribute(new, "tinted", 0) end xmlSaveFile(xml) xmlUnloadFile(xml) reload = xmlLoadFile("vehicles.xml") xmlSaveFile(reload) xmlUnloadFile(reload) -- Set current in-game datas setElementData(vehh, "vehicle.id", id) setElementData(vehh, "vehicle.engine", 0) setElementData(vehh, "vehicle.lights", 0) setElementData(vehh, "vehicle.lock", 0) setElementData(vehh, "vehicle.fuel", 100) setElementData(vehh, "vehicle.handbrake", 1) setElementData(vehh, "vehicle.faction", 0) setElementData(vehh, "factions.vehicle", 0) setElementData(vehh, "vehicle.tint", tint) setVehicleColor(vehh, tonumber(color1), tonumber(color2), 0, 0) else outputChatBox("Color values must be 0-126.", player, 255, 0, 0, false) end else outputChatBox("Syntax: /" .. cmd .. " []", player, 220, 220, 0, false) outputChatBox("If the vehicle name has spaces, just put on an underscore: _ and it will automaticly detect it.", player, 255, 255, 255, false) outputChatBox("Tints: 0 = false, 1 = true", player, 255, 255, 255, false) end end end ) Heres the function... Link to comment
stefutz101 Posted April 7, 2016 Author Share Posted April 7, 2016 Isnt working ... addCommandHandler({"createvehicle", "makeveh", "makevehicle", "makecar"}, function(player, cmd, name, color1, color2, tint, owner) if exports.brpExports:isPlayerLeadAdmin(player) then xml = xmlLoadFile("vehicles.xml") if name and color1 and color2 and tint then local find_ = string.find(name, "_") if tonumber(color1) >= 0 and tonumber(color1) <= 126 and tonumber(color2) >= 0 and tonumber(color2) <= 126 then local px, py, pz = getElementPosition(player) local rx, ry, rz = getElementRotation(player) local interior = getElementInterior(player) local dimension = getElementDimension(player) local model1 = getVehicleModelFromName(string.gsub(name,"_"," ")) local model2 = getVehicleModelFromName(tostring(name)) local new = xmlCreateChild(xml, "veh") local id = math.random(1,99999) if find_ then vehh = createVehicle(model1, px + 4, py, pz, rx, ry, rz) outputChatBox("Created a " .. getVehicleNameFromModel(model1) .. " with ID " .. tonumber(id) .. ".", player, 0, 255, 0, false) outputServerLog("[VEHICLE] [CMD/CREATEVEHICLE]: " .. getPlayerName(player) .. " created a " .. getVehicleNameFromModel(model1) .. " with ID " .. tonumber(id) .. ".") xmlNodeSetAttribute(new, "model", tonumber(model1)) else vehh = createVehicle(model2, px + 4, py, pz, rx, ry, rz) outputChatBox("Created a " .. getVehicleNameFromModel(model2) .. " with ID " .. tonumber(id) .. ".", player, 0, 255, 0, false) outputServerLog("[VEHICLE] [CMD/CREATEVEHICLE]: " .. getPlayerName(player) .. " created a " .. getVehicleNameFromModel(model2) .. " with ID " .. tonumber(id) .. ".") xmlNodeSetAttribute(new, "model", tonumber(model2)) end local vpx, vpy, vpz = getElementPosition(vehh) local vrx, vry, vrz = getElementRotation(vehh) xmlNodeSetAttribute(new, "id", tonumber(id)) xmlNodeSetAttribute(new, "posx", tonumber(vpx)) xmlNodeSetAttribute(new, "posy", tonumber(vpy)) xmlNodeSetAttribute(new, "posz", tonumber(vpz)) xmlNodeSetAttribute(new, "rotx", tonumber(vrx)) xmlNodeSetAttribute(new, "roty", tonumber(vry)) xmlNodeSetAttribute(new, "rotz", tonumber(vrz)) xmlNodeSetAttribute(new, "interior", tonumber(interior)) xmlNodeSetAttribute(new, "dimension", tonumber(dimension)) xmlNodeSetAttribute(new, "color1", tonumber(color1)) xmlNodeSetAttribute(new, "color2", tonumber(color2)) xmlNodeSetAttribute(new, "health", 1000) xmlNodeSetAttribute(new, "fuel", 100) xmlNodeSetAttribute(new, "engineState", 0) xmlNodeSetAttribute(new, "lightsState", 0) xmlNodeSetAttribute(new, "handbrakeState", 1) xmlNodeSetAttribute(new, "lockState", 0) xmlNodeSetAttribute(new, "factionid", 0) xmlNodeSetAttribute(new, "createdby", getPlayerName(player)) if owner then local target = exports.brpExports:findPlayer(owner, player) if target then local acc = getPlayerAccount(target) xmlNodeSetAttribute(new, "owner", getAccountName(acc)) setElementData(vehh, "vehicle.owner", getAccountName(acc)) else outputChatBox("Failed to set the owner. Default set.", player, 255, 0, 0, false) end else xmlNodeSetAttribute(new, "owner", 0) setElementData(vehh, "vehicle.owner", 0) end if tonumber(tint) == 0 then xmlNodeSetAttribute(new, "tinted", 0) elseif tonumber(tint) == 1 then xmlNodeSetAttribute(new, "tinted", 1) else xmlNodeSetAttribute(new, "tinted", 0) end xmlSaveFile(xml) xmlUnloadFile(xml) reload = xmlLoadFile("vehicles.xml") xmlSaveFile(reload) xmlUnloadFile(reload) -- Set current in-game datas setElementData(vehh, "vehicle.id", id) setElementData(vehh, "vehicle.engine", 0) setElementData(vehh, "vehicle.lights", 0) setElementData(vehh, "vehicle.lock", 0) setElementData(vehh, "vehicle.fuel", 100) setElementData(vehh, "vehicle.handbrake", 1) setElementData(vehh, "vehicle.faction", 0) setElementData(vehh, "factions.vehicle", 0) setElementData(vehh, "vehicle.tint", tint) setVehicleColor(vehh, tonumber(color1), tonumber(color2), 0, 0) else outputChatBox("Color values must be 0-126.", player, 255, 0, 0, false) end else outputChatBox("Syntax: /" .. cmd .. " []", player, 220, 220, 0, false) outputChatBox("If the vehicle name has spaces, just put on an underscore: _ and it will automaticly detect it.", player, 255, 255, 255, false) outputChatBox("Tints: 0 = false, 1 = true", player, 255, 255, 255, false) end end end ) Heres the function... Link to comment
Moderators IIYAMA Posted April 7, 2016 Moderators Share Posted April 7, 2016 A table wut? There is no information about that. function createVehicleByKeyName (player, cmd, name, color1, color2, tint, owner) --... end local createVehicleKeyNames = {"createvehicle", "makeveh", "makevehicle", "makecar"} for i=1, #createVehicleKeyNames do addCommandHandler(createVehicleKeyNames[i], createVehicleByKeyName) end local xml = xmlLoadFile("vehicles.xml") Why global? Makes no sense. local reload = xmlLoadFile("vehicles.xml") local mapRootElement = loadMapData ( reload, root ); --xmlSaveFile(reload) -- No need for double save. xmlUnloadFile(reload) Link to comment
Moderators IIYAMA Posted April 7, 2016 Moderators Share Posted April 7, 2016 A table wut? There is no information about that. function createVehicleByKeyName (player, cmd, name, color1, color2, tint, owner) --... end local createVehicleKeyNames = {"createvehicle", "makeveh", "makevehicle", "makecar"} for i=1, #createVehicleKeyNames do addCommandHandler(createVehicleKeyNames[i], createVehicleByKeyName) end local xml = xmlLoadFile("vehicles.xml") Why global? Makes no sense. local reload = xmlLoadFile("vehicles.xml") local mapRootElement = loadMapData ( reload, root ); --xmlSaveFile(reload) -- No need for double save. xmlUnloadFile(reload) Link to comment
stefutz101 Posted April 7, 2016 Author Share Posted April 7, 2016 Nope , not that is the problem. The command is working but i want to know what i must change to reload the xml file after i create a new veh. 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