Jump to content

On playSound


SpecT

Recommended Posts

Hello guys!

I want to make the download less for the players in a server (Race-DM). So I got the idea to get the songs from web storage and stop the download of songs when a map is being downloaded.

So my question is: Is there a way to cancel the event of downloading song - when the map starts it won't download the song.

@PS: Tell me if you didn't understand. I don't know how to explain it better so I would try to exaplain better when you ask.

Link to comment
for _,resource in ipairs(getResources()) do 
    if getResourceInfo(resource,"type") == "map" then 
    local resourceName = getResourceName(resource)  
    local metaPath = ":"..resourceName.."/meta.xml" 
    local meta = xmlLoadFile(metaPath) 
        if meta then 
        local childIndex = 0 
        local child = xmlFindChild(meta,"file",childIndex) 
            if child then 
            repeat 
                local song = xmlNodeGetAttribute(child,"src") 
                if string.find(song,".mp3") or string.find(song,".wav") then 
                xmlNodeSetAttribute(child,"download","false") 
                end 
                childIndex = childIndex+1 
                child = xmlFindChild(meta,"file",childIndex) 
            until child == false 
            end 
        xmlSaveFile(meta) 
        xmlUnloadFile(meta) 
        end 
    end 
end 

idont know but this should works fine

Edited by Guest
Link to comment

Shouldn't it looks like this?

xmlNodeSetAttribute(child,"download","false") 

I changed song to child.

And what if there is another file which is mentioned in meta? I prefer to loop through all "file" childrens. Not only one.

You have to save file and unload it after editing.

Edited by Guest
Link to comment
Shouldn't it looks like this?
xmlNodeSetAttribute(child,"download","false") 

I changed song to child.

yea, sorry i'm just too tired

i'll edit it, and thanks

--

And what if there is another file which is mentioned in meta? I prefer to loop through all "file" childrens. Not only one.
if string.find(song,".mp3") or string.find(song,".wav") then 

Link to comment

I don't have experience with XML.

for _, resource in ipairs ( getResources() ) do 
    if getResourceInfo ( resource,"type" ) == "map" then 
    local resourceName = getResourceName ( resource ) 
    local metaPath = ":"..resourceName.."/meta.xml" 
    local meta = xmlLoadFile ( metaPath ) 
        if meta then 
        local children = xmlNodeGetChildren ( meta ) 
            if children then 
                for _, node in ipairs ( children ) do 
                    local nodeName = xmlNodeGetName ( node ) 
                    if nodeName == "file" then 
                        local song = xmlNodeGetAttribute ( node,"src" ) 
                        if string.find( song, ".mp3" ) or string.find ( song, ".wav" ) then 
                            xmlNodeSetAttribute ( node, "download", "false" ) 
                        end 
                    end 
                end 
            end 
            xmlSaveFile ( meta ) 
            xmlUnloadFile ( meta ) 
        end 
    end 
end 

Is it correct?

Edited by Guest
Link to comment
I don't have experience with XML.
for _, resource in ipairs ( getResources() ) do 
    if getResourceInfo ( resource,"type" ) == "map" then 
    local resourceName = getResourceName ( resource ) 
    local metaPath = ":"..resourceName.."/meta.xml" 
    local meta = xmlLoadFile ( metaPath ) 
        if meta then 
        local children = xmlNodeGetChildren ( meta ) 
            if children then 
                for _, node in ipairs ( children ) do 
                    local nodeName = xmlNodeGetName ( node ) 
                    if nodeName == "file" then 
                        local song = xmlNodeGetAttribute ( node,"src" ) 
                        if string.find( song, ".mp3" ) or string.find ( song, ".wav" ) then 
                        xmlNodeSetAttribute ( node, "download", "false" ) 
                    end 
                end 
            end 
            xmlSaveFile ( meta ) 
            xmlUnloadFile ( meta ) 
        end 
    end 
end 

Is it correct?

you have missed ends, but i have already fix the code you can check my reply

Link to comment

Oh I didn't got the idea of changing the meta with script. Thank you guys! You saved me so much work ... I appreciate it !

The other problem is that that the most maps are in .zip ... Is it possible to edit the meta when they are archived in .zip ?

Edited by Guest
Link to comment

I did something like that. When map is started - it stops it, edits meta and starts again.

addEventHandler ( "onResourceStart", root, 
    function ( resource ) 
        if ( resource:getInfo ( "type" ) ~= "map" ) then 
            return; 
        end 
        local resourceName = resource:getName ( ); 
        local meta = XML.load ( ":" .. resourceName .. "/meta.xml" ); 
        if ( meta ) then 
            resource:stop ( ); 
            local child = meta:getChildren ( ); 
            if ( child ) then 
                for _, node in pairs ( child ) do 
                    if ( node:getName ( ) == "file" ) then 
                        local song = node:getAttribute ( "src" ); 
                        if ( song:find ( ".mp3" ) or song:find ( ".wav" ) ) then 
                            node:setAttribute ( "download", "false" ); 
                            meta:saveFile ( ); 
                            meta:unload ( ); 
                            break; 
                        end 
                    end 
                end 
            end 
            resource:start ( ); 
        end 
    end 
); 

I didn't test it. Script needs admin privileges.

Link to comment
I did something like that. When map is started - it stops it, edits meta and starts again.
addEventHandler ( "onResourceStart", root, 
    function ( resource ) 
        if ( resource:getInfo ( "type" ) ~= "map" ) then 
            return; 
        end 
        local resourceName = resource:getName ( ); 
        local meta = XML.load ( ":" .. resourceName .. "/meta.xml" ); 
        if ( meta ) then 
            resource:stop ( ); 
            local child = meta:getChildren ( ); 
            if ( child ) then 
                for _, node in pairs ( child ) do 
                    if ( node:getName ( ) == "file" ) then 
                        local song = node:getAttribute ( "src" ); 
                        if ( song:find ( ".mp3" ) or song:find ( ".wav" ) ) then 
                            node:setAttribute ( "download", "false" ); 
                            meta:saveFile ( ); 
                            meta:unload ( ); 
                            break; 
                        end 
                    end 
                end 
            end 
            resource:start ( ); 
        end 
    end 
); 

I didn't test it. Script needs admin privileges.

I will try it later cuz right now I can't. Btw there is a script of loading the song :D ......

Most times it's song.lua or music.lua ... It will send errors in the debugscript cuz the .mp3 isnt added in meta.

Link to comment

Oh, you are right. If so:

addEventHandler ( "onResourceStart", root, 
    function ( resource ) 
        if ( resource:getInfo ( "type" ) ~= "map" ) then 
            return; 
        end 
        local resourceName = resource:getName ( ); 
        local meta = XML.load ( ":" .. resourceName .. "/meta.xml" ); 
        if ( meta ) then 
            resource:stop ( ); 
            local child = meta:getChildren ( ); 
            if ( child ) then 
                for _, node in pairs ( child ) do 
                    if ( node:getName ( ) == "file" ) then 
                        local song = node:getAttribute ( "src" ); 
                        if ( song:find ( ".mp3" ) or song:find ( ".wav" ) ) then 
                            node:setAttribute ( "download", "false" ); 
                        end 
                    elseif ( node:getName ( ) == "script" ) then 
                        local s = node:getAttribute ( "src" ); 
                        if ( s:find ( ".lua" ) ) then 
                            node:setAttribute ( "download", "false" ); 
                        end 
                    end 
                end 
                meta:saveFile ( ); 
                meta:unload ( ); 
            end 
            resource:start ( ); 
        end 
    end 
); 

Not sure if this will work, but you can try :P

Link to comment
Oh, you are right. If so:
addEventHandler ( "onResourceStart", root, 
    function ( resource ) 
        if ( resource:getInfo ( "type" ) ~= "map" ) then 
            return; 
        end 
        local resourceName = resource:getName ( ); 
        local meta = XML.load ( ":" .. resourceName .. "/meta.xml" ); 
        if ( meta ) then 
            resource:stop ( ); 
            local child = meta:getChildren ( ); 
            if ( child ) then 
                for _, node in pairs ( child ) do 
                    if ( node:getName ( ) == "file" ) then 
                        local song = node:getAttribute ( "src" ); 
                        if ( song:find ( ".mp3" ) or song:find ( ".wav" ) ) then 
                            node:setAttribute ( "download", "false" ); 
                        end 
                    elseif ( node:getName ( ) == "script" ) then 
                        local s = node:getAttribute ( "src" ); 
                        if ( s:find ( ".lua" ) ) then 
                            node:setAttribute ( "download", "false" ); 
                        end 
                    end 
                end 
                meta:saveFile ( ); 
                meta:unload ( ); 
            end 
            resource:start ( ); 
        end 
    end 
); 

Not sure if this will work, but you can try :P

Dude thanks for all of that :D Really ... but maybe you don't know that the DM maps have custom scripts. I mean .lua files for markers ... onClientHitMarker , playSound etc ... So if it will remove all the .lua files from the meta .. probably the map will be buggy as fu**. Nevermind, as gallardo said I will try to make a scriptloader, I have ideas and examples so yea.

Thanks again for all of that, WhoAmI !

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