Captain Cody Posted February 13, 2016 Share Posted February 13, 2016 I'm working on an inventory system, and I have it so it creates an xml file, and assigns the players serial as the xmls name, what I am trying to do is load the xml server side 'So clients cannot mess with it' then send it to client side and have it converted into a grid list so it allows the players to select the items and what not. But the issue I am running into, is how would I go about doing this in general. I know how to load one xml file and use it for shops and stuff, but doing individual files for each player is an issue I have. "rentalKey" Id="1"> -- Xml file -- Script? -- In general have no clue. Link to comment
Captain Cody Posted February 13, 2016 Author Share Posted February 13, 2016 Any one? Trying to get this done, but I cannot figure this out. Link to comment
Simple0x47 Posted February 13, 2016 Share Posted February 13, 2016 You're using XML as a way to store information? That's not a good choice to store information. I would recommend you to use mySQL. Second, don't make files for every player, just keep all players in one.xml and what's the issue you have with it? Link to comment
Captain Cody Posted February 13, 2016 Author Share Posted February 13, 2016 Well the issue I had was loading each individual file server side, then sending that info file side. But as to what you said at first, I have barley any experience with sql, have mostly done xml files in the past. But I guess I'll try mysql. -- Link to comment
Simple0x47 Posted February 13, 2016 Share Posted February 13, 2016 I can help you with mySQL if you want. But please don't use XML. Link to comment
Dealman Posted February 13, 2016 Share Posted February 13, 2016 (edited) You're using XML as a way to store information? That's not a good choice to store information. I would recommend you to use mySQL. Second, don't make files for every player, just keep all players in one.xml and what's the issue you have with it? XML is a good choice for storing information, but it does have its limitations particularly when it gets really, really big - which is when, much like you said MySQL/SQL is a much better choice. Your second suggestion however, is false. Having a large single XML file for all the players is bad for multiple reasons; 1. It needs to be sent to the client every time their inventory is updated/they connect to the server. It would be significantly bigger than one small XML for that one client. 2. If the client can somehow access it, they could see the inventories of other players - this would be extremely exploitable. Well the issue I had was loading each individual file server side, then sending that info file side. But as to what you said at first, I have barley any experience with sql, have mostly done xml files in the past. But I guess I'll try mysql. Normally I would also advice you to use MySQL, but if you'd rather try XML I'd say by all means go ahead. Let's assume you create a new inventory XML when a new player connects/creates a character. You'd need to send this data to the client. You could either use triggerClientEvent or triggerLatentClientEvent. The latter of which would be preferred. But so long as the size of the XML is rather small, the first one should work as well and is a bit easier to work with if you don't have experience with latent events. Also, the absolute most important rule you need to follow is to never trust the client. If you need to update the client's inventory XML, send the new data and it's value to the client and have the client update the XML locally. That way you wouldn't have to send the entire XML file every time an update is requested. Edited February 13, 2016 by Guest Link to comment
Captain Cody Posted February 13, 2016 Author Share Posted February 13, 2016 Well what I was trying to do, is when player first registers, it will create an Xml file, assigned to that persons serial. Which will be used by multiple resources 'All server side' then when the inventory system is put into use, what I attempted to do is have it take the info from the xml then send it client side as to populate the gui gridlist. //Inventory would be limited to 50 items// This sound like something SQL should be used or XML? --- To addon to what you just added --- I was going to have everything stored server side as to be able to access everything and prevent cheating. + I'd prefer using the one that is best for the situation, that's why I ask if XML or SQL would be the best for this. Link to comment
Dealman Posted February 13, 2016 Share Posted February 13, 2016 Well what I was trying to do, is when player first registers, it will create an Xml file, assigned to that persons serial. Which will be used by multiple resources 'All server side' then when the inventory system is put into use, what I attempted to do is have it take the info from the xml then send it client side as to populate the gui gridlist. //Inventory would be limited to 50 items// This sound like something SQL should be used or XML? I haven't really been working with XML within MTA for a while now, but I don't think 50 items would be too hefty of an amount. The issue is that the server would need to load the XML file and read through the entire file to get the values in order to send them to the client. This could become a performance issue depending on the amount of players, but to my experience the MTA servers are surprisingly efficient. You could write a logger to monitor stuff like this, of course. On the plus side, you only need to send the values to the client to populate the gridlist instead of the entire XML file. MySQL of course would also work, and it has its pros and cons. Even if you do use MySQL, you still need the server to fetch the data and transfer it to the client either way. Though MySQL is pretty fast but requires the server where it's hosted to be stable and preferably run frequent backups of the entire database. Edit: If you want my honest opinion, I'd say use MySQL for this. It's a proven service and is used by the majority of online games with persistent data. If you're not experienced with MySQL there's plenty of people on these forums who'd gladly help you if you run into issues. And if you plan to work on developing games/mods outside of MTA - knowledge of using MySQL/SQL is usually a good merit to have. Then again, this is true for XML as well. But XML is far easier to learn than MySQL/SQL. Link to comment
Captain Cody Posted February 13, 2016 Author Share Posted February 13, 2016 Well stability and performance is not an issue at all. Test server running on my laptop 'Not even close to as powerful as the servers host' can handle anything I throw at it without any lag. And the actual host is extremely stable and well maintained. So I'm going to assume either or would work. But the issue I'm having is actually fetching the items and sending them to the grid-list. I have barley any idea exactly where to begin as said in the first post. I made one a while ago for a skin selector but long since forgotten how. And even using code from something such as that would not work since it has to load a file that's set on the players serial instead of a base file that only has to load once. Link to comment
Dealman Posted February 13, 2016 Share Posted February 13, 2016 Well stability and performance is not an issue at all. Test server running on my laptop 'Not even close to as powerful as the servers host' can handle anything I throw at it without any lag. And the actual host is extremely stable and well maintained. So I'm going to assume either or would work. But the issue I'm having is actually fetching the items and sending them to the grid-list. I have barley any idea exactly where to begin as said in the first post. I made one a while ago for a skin selector but long since forgotten how. And even using code from something such as that would not work since it has to load a file that's set on the players serial instead of a base file that only has to load once. But how many players are you testing it with? Something that runs well with 1 or 2 players might not run as well with 40+ players. And yes, you are indeed right - either XML or MySQL would work for this. I would strongly advice against using already existing code, it's very easy to get lost. If you build it from scratch, you'll know where to look if stuff goes wrong. This is especially true for complicated XML files such as XHTML files since you'll be having a fair bit of for loops Just how much do you know about the XML files? Do you know how to read it and retrieve the values? It depends on how your XML is structured as well. Link to comment
Captain Cody Posted February 13, 2016 Author Share Posted February 13, 2016 Well I tested it with 5 computers each sending 20 players to the server. "Dear lord those computers were about to implode" 1 running local host, and the other 4 all running at different locations. And I was not going to use existing code, I was using it as an example to get started. And really I know enough XML to create the file, populate it with children, edit/remove bits, read the file, pull info from it and a bit more. But the issue I am having is just sending the info that has been pulled to the client side code, then putting that into a a gridlist. I know how to do it for one XML file for every player, but not individual files where the tables that have been pulled have to be assigned to individual names or serials. Link to comment
Dealman Posted February 13, 2016 Share Posted February 13, 2016 But the issue I am having is just sending the info that has been pulled to the client side code, then putting that into a a gridlist. I know how to do it for one XML file for every player, but not individual files where the tables that have been pulled have to be assigned to individual names or serials. Get their serial, get their XML file, load it. Read through it and get the values you need and store them in a temporary table(table.insert) - you can then send this table to the client. Since you already have their serial, you know which player to send the data to. Then you loop through this table to add the items to the gridlist. guiGridListAddRow guiGridListSetItemText Link to comment
Captain Cody Posted February 13, 2016 Author Share Posted February 13, 2016 So use Table.insert for each object send it client side Then client side Use unpack correct? If so what do I use to create the initial table? Link to comment
Dealman Posted February 13, 2016 Share Posted February 13, 2016 So useTable.insert for each object send it client side Then client side Use unpack correct? If so what do I use to create the initial table? I'd use a for loop instead of unpack, kind of depends a bit on how it's all set up. You define the table like you define any variable. For example; local myTable = {} table.insert(myTable, "myValue") Link to comment
Captain Cody Posted February 13, 2016 Author Share Posted February 13, 2016 What do you mean by a loop? Link to comment
Captain Cody Posted February 13, 2016 Author Share Posted February 13, 2016 Ok well I got it to apear on table, though I'm having some issues. #1, how would I add in catagories 'Correctly' Currently they are apearing as the Numbers 3 and 4 #2 how do I format the gridlist correctly Everything from the chart is appearing, but in the wrong format. Link to comment
Captain Cody Posted February 13, 2016 Author Share Posted February 13, 2016 -- Server side -- function loadInventorym(account) local serial = getPlayerSerial ( client ) local InventoryTable = {} local InventoryTable2 = {} local player = client local xml = xmlLoadFile("@:Skins/Inventories/"..serial..".xml") for i, category in pairs(xmlNodeGetChildren(xml)) do local cName = xmlNodeGetAttribute(category, "Name") table.insert(InventoryTable, category) table.insert(InventoryTable, cName) for i, IN in pairs(xmlNodeGetChildren(category)) do local id, name = xmlNodeGetAttribute(IN, "Id"), xmlNodeGetAttribute(IN, "Name") table.insert(InventoryTable, name) table.insert(InventoryTable, id) end triggerClientEvent(player, "showInventorya", player, InventoryTable) end xmlUnloadFile(xml) end addEvent("ShowInventoryb", true) addEventHandler("ShowInventoryb", resourceRoot, loadInventorym) -- client side function showInventory(InventoryTable) guiGridListClear(Gridlist) for category, cName in pairs(InventoryTable) do local row = guiGridListAddRow(Gridlist) guiGridListSetItemText(Gridlist, row, 1, cName, true, false) for id, name in pairs(InventoryTable) do local row = guiGridListAddRow(Gridlist) guiGridListSetItemText(Gridlist, row, 1, "test2"..name, false, false) guiGridListSetItemText(Gridlist, row, 2, "test"..id, false, false) guiGridListSetItemText(Gridlist, row, 3, "test", false, false) showCursor(true) end end end How would I sort this? Correctly so that the correct items apear under the correct catagories? Link to comment
Captain Cody Posted February 13, 2016 Author Share Posted February 13, 2016 Or better question How would I link to table values together Example - table.insert(ObjectsTable, name) table.insert(ObjectsTable, id) How would I link these together so when I put them into the gridlist it matches them up. Link to comment
Dealman Posted February 13, 2016 Share Posted February 13, 2016 Instead of using two separate tables, use one. For example; local myTable = {} table.insert(myTable, {id, name}) Link to comment
Captain Cody Posted February 13, 2016 Author Share Posted February 13, 2016 Then what do I use to exact it into the client side? Never mind 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