Jump to content

XML Functions


GanJaRuleZ

Recommended Posts

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> 
  

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...