GanJaRuleZ Posted January 29, 2012 Posted January 29, 2012 Hi all , so , now to finish the infopanel , i need to learn the xml functions .. But here is the problem .. I simply don't can understand them , so can anybody give me examples of : Getting text from a XML file , and Saving text in a XML file .. Thanks in advance
HunT Posted January 29, 2012 Posted January 29, 2012 Look this for example XML https://community.multitheftauto.com/index.php?p= ... ls&id=2585 u need the XML for what? why no use the Gui element?
FatalTerror Posted January 29, 2012 Posted January 29, 2012 2s in the wiki... you find that: addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() local xml = xmlLoadFile("welcome.xml") -- open the XML file local messageNodes = xmlNodeGetChildren(xml) -- get all child nodes of the root node () g_WelcomeMessages = {} -- create a new global variable to store the welcome messages for i,node in ipairs(messageNodes) do -- loop over all the message nodes g_WelcomeMessages[i] = xmlNodeGetValue(node) -- retrieve the text in each node end xmlUnloadFile(xml) -- close the XML file end ) addEventHandler("onPlayerJoin", getRootElement(), function() local numMessages = #g_WelcomeMessages -- get the number of messages local message = g_WelcomeMessages[math.random(numMessages)] -- pick a random message outputChatBox(message, source, 0, 255, 0) -- display it to the joining player end Result: <messages> <message>Welcome to the deathmatch server, enjoy your stay.</message> <message>Welcome. Be sure to get your free pizza at Matt's!</message> <message>Party going on at the LS beach, be there</message> </messages>
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