Jump to content

help [xml]


Ahmed Ly

Recommended Posts

function getfolderNameAndScripts (folder)
tables = {}
local xml = xmlLoadFile("meta.xml")   
local Nodes = xmlNodeGetChildren(xml) 
 for i,node in ipairs(Nodes) do 
if xmlNodeGetName(node) == "script" then 
local script_Name = xmlNodeGetAttribute(node, "src") 
table.insert(tables,script_Name)  
output =  "resources\\"..folder.."\\"..tables[#tables].. ""
end
end 
xmlUnloadFile(xml)    
return output
end  
outputServerLog(""..getfolderNameAndScripts("acl").."")
 --[[
 the code it's working good but its output last file .lua in meta.xml
 resources/acl/clinet.lua doesn't  output in server log 
 resources/acl/s.lua doesn't  output in server log 
 resources/acl/server.lua  this file output  in server log  
 --]]

 

Edited by Ahmed Ly
Link to comment

I didn't understand what are you trying to do but, that's an example :

function getFolderNameAndScripts ( folder )
    local script = ':' .. folder
        if ( fileExists ( script .. '/meta.xml' ) ) then
        scriptInfo = { };
        local resourceMeta = xmlLoadFile ( script .. '/meta.xml' )
            if ( resourceMeta ) then
                for k, info in pairs ( xmlNodeGetChildren ( resourceMeta ) ) do
                    if ( xmlNodeGetName ( info ) == 'script' or xmlNodeGetName ( info ) == 'file' or xmlNodeGetName ( info ) == 'map' ) then
                    table.insert ( scriptInfo, { script, xmlNodeGetAttribute ( info, 'src' ) or 'N/A', xmlNodeGetAttribute ( info, 'type' ) or 'N/A' } )
                end
            end
        end
    end
    return scriptInfo or { };
end

addEventHandler ( 'onResourceStart', root, function ( res )
    outputChatBox ( 'The Resource ' .. getResourceName ( res ) .. ' has been started', root, 0, 255, 0, true )
    outputChatBox ( 'Resource Scripts :', root, 255, 0, 0, true )
    local items = getFolderNameAndScripts ( getResourceName ( res ) )
        for i = 1, #items do
        local t = items [ i ]
        outputChatBox ( t [ 1 ]:gsub ( ':', 'resources/' ) .. '/' .. t [ 2 ] .. ', type = ' .. t [ 3 ], root, 0, 0, 255, true )
    end
end )

 

Edited by #,+( _xiRoc[K]; >
Link to comment

i fixed it 


function getFolderNameAndScripts (resourceName)

   if getResourceFromName(resourceName) then

     local scripts = {}

     local xml = xmlLoadFile(":" .. resourceName .. "/meta.xml")

       if xml then

         local nodes = xmlNodeGetChildren(xml)

         for i, node in ipairs(nodes) do

              if xmlNodeGetName(node) == "script" then

                 local scriptName = xmlNodeGetAttribute(node, "src")

                 scripts[#scripts + 1] = "deathmatch\\resources\\" ..resourceName.."\\"..scriptName

               end

            end

           xmlUnloadFile(xml)

      end

       return scripts

   end

   outputDebugString("No resource found to get the scripts from!", 2)

    return false

end

 local  items    =  getFolderNameAndScripts("acl")
for i, v in ipairs(items) do
iprint(""..v.."")
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...