jwalks Posted March 14, 2011 Share Posted March 14, 2011 --[[ Hello downloader:> When you want to set something to the "character data", you need to do the following things local accountName = getAccountName(getPlayerAccount(source)) local characterindex = getCharacterIndexByCharacterName (accountName,charactername) local root = xmlLoadFile ("players.xml") local playerRoot = xmlFindChild (root,"player",findPlayerIndexByName(accountName)) if (characterindex) then local characterRoot = xmlNodeGetChildren (playerRoot,tonumber(characterindex)-1) xmlNodeSetAttirbute (characterRoot,"tag",thingyouwanttosave) -- You can load with this local loadedpart = xmlNodeGetAttirbute (characterRoot,"tag") -- You can load with this end ]]-- addEvent ("lolmodLoginPlayer",true) addEventHandler ("lolmodLoginPlayer",getRootElement(), function(username,password) local account = getAccount (username,password) if (account) then logIn (source,account,password) local root = xmlLoadFile ("players.xml") if (xmlFindChild (root,"player",findPlayerIndexByName (tostring(username)))) then local playerNode = xmlFindChild (root,"player",findPlayerIndexByName (tostring(username))) triggerClientEvent ("lolmodOpenInfoWindow",source,"Welcome back! click your character to start!") local character = xmlNodeGetChildren (playerNode) if (character[3]) then triggerClientEvent (source,"lolmodOpenCharacterSelectWindow",source,username,xmlNodeGetAttribute(character[1],"name"),xmlNodeGetAttribute(character[2],"name"),xmlNodeGetAttribute(character[3],"name")) elseif (character[2]) then triggerClientEvent (source,"lolmodOpenCharacterSelectWindow",source,username,xmlNodeGetAttribute(character[1],"name"),xmlNodeGetAttribute(character[2],"name")) elseif (character[1]) then triggerClientEvent (source,"lolmodOpenCharacterSelectWindow",source,username,xmlNodeGetAttribute(character[1],"name")) else triggerClientEvent (source,"lolmodOpenCharacterSelectWindow",source,username) end else local playerNode = xmlCreateChild (root,"player") xmlNodeSetAttribute (playerNode,"name",tostring(username)) triggerClientEvent ("lolmodOpenInfoWindow",source,"Welcome!\nWe see it's your first time here, welcome to Lolmode!\nYou haven't got a character yet, but you can make one when you click New Character!\nGood luck in the game!") triggerClientEvent (source,"lolmodOpenCharacterSelectWindow",source,username) xmlSaveFile (root) end xmlUnloadFile (root) else triggerClientEvent (source,"lolmodOpenInfoWindow",source,"Sorry, your login values are invalid!\n\nMake sure the account is exist, and if the password is spelled well.\nThere also are some illegal strings, these you mayn't have in your name. Only A-Z a-z _ - and 0-9 (When you found a string which isn't in, we aren't responsible for when you lose all data!)\nsorry for the inconvenience.") end end) -- © JasperNL=D addEvent ("lolmodRegisterPlayer",true) addEventHandler ("lolmodRegisterPlayer",getRootElement(), function(username,password) local account = getAccount (username) if (account) then triggerClientEvent ("lolmodOpenInfoWindow",source,"We're sorry, but this account is already in use!\nPlease take another one \n\nNOTE: This is not your in-game name! so every name is good :D") else addAccount (username,password) triggerClientEvent ("lolmodOpenInfoWindow",source,"That's all! Your account is registered! You can log in now by clicking the Log In! button! then you can create a character which you play the game with!\nGood luck!") end end) -- © JasperNL=D addEvent ("lolmodSpawnCharacter",true) addEventHandler ("lolmodSpawnCharacter",getRootElement(), function(charactername) if (charactername) then local accountName = getAccountName(getPlayerAccount(source)) local characterindex = getCharacterIndexByCharacterName (accountName,charactername) local root = xmlLoadFile ("players.xml") local playerRoot = xmlFindChild (root,"player",findPlayerIndexByName(accountName)) if (characterindex) then local characterRoot = xmlNodeGetChildren (playerRoot,tonumber(characterindex)-1) spawnPlayer (source,tonumber(xmlNodeGetAttribute (characterRoot,"px")),tonumber(xmlNodeGetAttribute (characterRoot,"py")),tonumber(xmlNodeGetAttribute (characterRoot,"pz")),0,tonumber(xmlNodeGetAttribute (characterRoot,"skin")),tonumber(xmlNodeGetAttribute (characterRoot,"pi")),tonumber(xmlNodeGetAttribute (characterRoot,"pd")),nil) toggleControl (source,"chatbox",true) createBlipAttachedTo (source,0,2,tonumber(xmlNodeGetAttribute (characterRoot,"cr")),tonumber(xmlNodeGetAttribute (characterRoot,"cg")),tonumber(xmlNodeGetAttribute (characterRoot,"cb")),255) setPlayerMoney (source,tonumber(xmlNodeGetAttribute (characterRoot,"cash"))) setPlayerNametagText (source,tostring(xmlNodeGetAttribute (characterRoot,"name"))) setPlayerNametagColor (source,tonumber(xmlNodeGetAttribute (characterRoot,"cr")),tonumber(xmlNodeGetAttribute (characterRoot,"cg")),tonumber(xmlNodeGetAttribute (characterRoot,"cb"))) setPedArmor (source,tonumber(xmlNodeGetAttribute (characterRoot,"armor"))) setElementHealth (source,tonumber(xmlNodeGetAttribute (characterRoot,"health"))) local weapons = xmlFindChild (characterRoot,"weapons",0) if (weapons) then local weapon = xmlNodeGetAttributes (weapons) giveWeapon (source,weapon["w"],weapon["wammo"],true) end setCameraTarget (source,source) outputChatBox (getPlayerNametagText (source) .. "#FF0000 has joined the game [Logged In]",getRootElement(),255,0,0,true) local cash = xmlNodeGetAttribute (characterRoot,"cash") local bank = xmlNodeGetAttribute (characterRoot,"bank") local housenumber = xmlNodeGetAttribute (characterRoot,"house") if not (housenumber) then local housenumber = nil local housenumber = "No house Availible" end triggerClientEvent (source,"lolmodHideCharacterSelectWindow",source) triggerClientEvent (source,"lolmodRefreshBankInfoMenu",source,cash,bank,housenumber) xmlUnloadFile (root) end else triggerClientEvent ("lolmodOpenInfoWindow",source,"You need to select a character first!") end end) -- © JasperNL=D addEvent ("createNewCharacter",true) addEventHandler ("createNewCharacter",getRootElement(), function(skin,colred,colgreen,colblue,charactername) local accountName = getAccountName (getPlayerAccount(source)) if (getCharacterCount (accountName) < 3) then if not (checkCharacterNameIsFake(charactername) == "FAKE") then local root = xmlLoadFile ("players.xml") local playerRoot = xmlFindChild (root,"player",findPlayerIndexByName (tostring(accountName))) local newCharacter = xmlCreateChild (playerRoot,"character") xmlNodeSetAttribute (newCharacter,"name",charactername) xmlNodeSetAttribute (newCharacter,"skin",skin) xmlNodeSetAttribute (newCharacter,"cr",colred) xmlNodeSetAttribute (newCharacter,"cg",colgreen) xmlNodeSetAttribute (newCharacter,"cb",colblue) xmlNodeSetAttribute (newCharacter,"px",2000.51) xmlNodeSetAttribute (newCharacter,"py",1567.37) xmlNodeSetAttribute (newCharacter,"pz",15.367185) xmlNodeSetAttribute (newCharacter,"pi",0) xmlNodeSetAttribute (newCharacter,"pd",0) xmlNodeSetAttribute (newCharacter,"cash",1000) xmlNodeSetAttribute (newCharacter,"bank",1500) setTimer (logOut,1000,1,source) xmlSaveFile (root) xmlUnloadFile (root) else triggerClientEvent ("lolmodOpenInfoWindow",source,"Sorry, this character name is already in use.") end else triggerClientEvent ("lolmodOpenInfoWindow",source,"Sorry, the character max is 3 characters!\nYou have: 3 characters!\nYou can't add new ones any more!") end end) -- © JasperNL=D function getCharacterIndexByCharacterName (playeraccountname,charactername) local root = xmlLoadFile ("players.xml") local playerRoot = xmlFindChild (root,"player",findPlayerIndexByName (playeraccountname)) local allCharacters = xmlNodeGetChildren (playerRoot) j = 0 for i,v in ipairs (allCharacters) do j = j+1 if (xmlNodeGetAttribute (v,"name") == charactername) then return j end end xmlUnloadFile (root) end -- © JasperNL=D function getCharacterCount (playeraccountname) local root = xmlLoadFile ("players.xml") local playerRoot = xmlFindChild (root,"player",findPlayerIndexByName (playeraccountname)) local allCharacters = xmlNodeGetChildren (playerRoot) if (allCharacters) then k = 0 for i,v in ipairs (allCharacters) do i keep getting this error mesage and i have attempted it [2011-01-08 05:07:27] WARNING: lolmode\gui_s.lua:152: Bad argument @ 'xmlNodeFindChild' [2011-01-08 05:07:27] WARNING: lolmode\gui_s.lua:153: Bad argument @ 'xmlNodeGetChildren' [2011-01-08 05:07:27] ERROR: lolmode\gui_s.lua:155: bad argument #1 to 'ipairs' (table expected, got boolean) [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:168: Bad argument @ 'xmlNodeFindChild' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:169: Bad argument @ 'xmlNodeGetChildren' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:123: Bad argument @ 'xmlNodeFindChild' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:124: Bad argument @ 'xmlCreateChild' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:125: Bad argument @ 'xmlNodeSetAttribute' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:126: Bad argument @ 'xmlNodeSetAttribute' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:127: Bad argument @ 'xmlNodeSetAttribute' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:128: Bad argument @ 'xmlNodeSetAttribute' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:129: Bad argument @ 'xmlNodeSetAttribute' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:130: Bad argument @ 'xmlNodeSetAttribute' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:131: Bad argument @ 'xmlNodeSetAttribute' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:132: Bad argument @ 'xmlNodeSetAttribute' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:133: Bad argument @ 'xmlNodeSetAttribute' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:134: Bad argument @ 'xmlNodeSetAttribute' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:135: Bad argument @ 'xmlNodeSetAttribute' [2011-01-08 05:07:42] WARNING: lolmode\gui_s.lua:136: Bad argument @ 'xmlNodeSetAttribute' Link to comment
Moderators Citizen Posted March 14, 2011 Moderators Share Posted March 14, 2011 Hi, Maybe it's "players" instead of "player" in the xmlFindChild but I don't know, could you put here your player.xml ? EDIT: Or see this recent topic of Jasper: https://forum.multitheftauto.com/viewtopic.php?f=91&t=32309#p341306 Link to comment
jwalks Posted March 14, 2011 Author Share Posted March 14, 2011 <players> <player name="JasperNL=D"> <character name="JasperNL=D" skin="106" cr="255" cg="127" cb="0" px="-1959.99609375" py="284.21875" pz="36.46875" pi="0" pd="0" cash="99999549" bank="6255" health="54.117649078369" armor="0" house="0"> <weapons w="0" wammo="1" /> </character> <character name="JasperNL=O" skin="106" cr="127" cg="255" cb="0" px="-1973.9951171875" py="294.1162109375" pz="36.171875" pi="0" pd="0" cash="703" bank="92501496" health="65.098037719727" armor="0" house="1"> <weapons w="0" wammo="1" /> </character> </player> </players> Link to comment
Moderators Citizen Posted March 14, 2011 Moderators Share Posted March 14, 2011 Can you give us the findPlayerIndexByName function ? Link to comment
jwalks Posted March 14, 2011 Author Share Posted March 14, 2011 function findPlayerIndexByName (playeraccountname) local root = xmlLoadFile ("players.xml") local allPlayers = xmlNodeGetChildren (root) local k = -1 for i,v in ipairs (allPlayers) do k = k+1 if (xmlNodeGetAttribute (v,"name") == playeraccountname) then return k end end xmlUnloadFile (root) end Link to comment
Moderators Citizen Posted March 15, 2011 Moderators Share Posted March 15, 2011 Try with this XML: <players> <player name="JasperNL=D"> <character name="JasperNL=D" skin="106" cr="255" cg="127" cb="0" px="-1959.99609375" py="284.21875" pz="36.46875" pi="0" pd="0" cash="99999549" bank="6255" health="54.117649078369" armor="0" house="0" /> <character name="JasperNL=O" skin="106" cr="127" cg="255" cb="0" px="-1973.9951171875" py="294.1162109375" pz="36.171875" pi="0" pd="0" cash="703" bank="92501496" health="65.098037719727" armor="0" house="1" /> </player> </players> If it works, it means that you can't modify the XML structure like you want Link to comment
jwalks Posted March 15, 2011 Author Share Posted March 15, 2011 [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:168: Bad argument @ 'xmlNodeFindChild' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:169: Bad argument @ 'xmlNodeGetChildren' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:123: Bad argument @ 'xmlNodeFindChild' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:124: Bad argument @ 'xmlCreateChild' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:125: Bad argument @ 'xmlNodeSetAttribute' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:126: Bad argument @ 'xmlNodeSetAttribute' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:127: Bad argument @ 'xmlNodeSetAttribute' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:128: Bad argument @ 'xmlNodeSetAttribute' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:129: Bad argument @ 'xmlNodeSetAttribute' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:130: Bad argument @ 'xmlNodeSetAttribute' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:131: Bad argument @ 'xmlNodeSetAttribute' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:132: Bad argument @ 'xmlNodeSetAttribute' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:133: Bad argument @ 'xmlNodeSetAttribute' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:134: Bad argument @ 'xmlNodeSetAttribute' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:135: Bad argument @ 'xmlNodeSetAttribute' [2011-01-09 16:31:27] WARNING: lolmode\gui_s.lua:136: Bad argument @ 'xmlNodeSetAttribute' when i try to create a new player this pops up i can see the players i already have but trying to make a new one fails i can see the character's that i placed in the players.xml Link to comment
Castillo Posted March 15, 2011 Share Posted March 15, 2011 That should mean, you need a different code to create them. Link to comment
Moderators Citizen Posted March 15, 2011 Moderators Share Posted March 15, 2011 Try this and tell me if there are errors: local playerRoot = xmlFindChild (root,"player",1) 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