Jump to content

Displaying every sound file in chat


kevenvz

Recommended Posts

Hello there MTA scripters,

I need a bit help, I got this code but it don't say what it needs to say.

I want a script that if you start the resource you see the text that are displayed in the xml file.

Server:

soundeffect = {} 
soundXML = xmlLoadFile( "commands.xml" ) 
addEventHandler ( "onResourceStart", resourceRoot, function ( ) 
        for index,node in pairs ( xmlNodeGetChildren ( soundXML ) ) do 
            if xmlNodeGetName ( node ) == "command" then 
                soundeffect[xmlNodeGetAttribute(node,"sound")] = node 
                outputChatBox(node) 
            end 
        end) 

Commands.xml:

<commands> 
    <command name="shit" sound="eat.mp3" /> 
    <command name="kaas" sound="kaas.mp3" /> 
</commands> 

Link to comment
soundeffect = { } 
  
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        local soundXML = xmlLoadFile( "commands.xml" ) 
        if ( soundXML ) then 
            for _, node in pairs ( xmlNodeGetChildren ( soundXML ) ) do 
                if ( xmlNodeGetName ( node ) == "command" ) then 
                    soundeffect [ xmlNodeGetAttribute ( node, "name" ) ] = xmlNodeGetAttribute ( node, "sound" ) 
                    outputChatBox ( xmlNodeGetAttribute ( node, "name" ) ..": ".. xmlNodeGetAttribute ( node, "sound" ) ) 
                end 
            end 
        end 
    end 
) 

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...