SpecT Posted April 2, 2015 Share Posted April 2, 2015 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
ALw7sH Posted April 2, 2015 Share Posted April 2, 2015 without a custom script loader, idont think this is possible Link to comment
Walid Posted April 2, 2015 Share Posted April 2, 2015 Maybe you can put somthing like that in your meta file "song" download="false" /> Link to comment
WhoAmI Posted April 2, 2015 Share Posted April 2, 2015 You have to change meta of all maps I guess. Don't know if there is another way to do that. I can be wrong if course. Link to comment
ALw7sH Posted April 2, 2015 Share Posted April 2, 2015 (edited) 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 April 2, 2015 by Guest Link to comment
WhoAmI Posted April 2, 2015 Share Posted April 2, 2015 (edited) 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 April 2, 2015 by Guest Link to comment
ALw7sH Posted April 2, 2015 Share Posted April 2, 2015 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
WhoAmI Posted April 2, 2015 Share Posted April 2, 2015 Yea. But, it will check only first "file" child. Not all. If you know what I mean. If first "file" child won't be a song, script won't search for another one. Link to comment
Sasu Posted April 2, 2015 Share Posted April 2, 2015 (edited) 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 April 2, 2015 by Guest Link to comment
ALw7sH Posted April 2, 2015 Share Posted April 2, 2015 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
WhoAmI Posted April 3, 2015 Share Posted April 3, 2015 What the... Al7wsH, why wouldn't you use 'for' statement, which in this case is better imo? Link to comment
SpecT Posted April 3, 2015 Author Share Posted April 3, 2015 (edited) 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 April 3, 2015 by Guest Link to comment
WhoAmI Posted April 3, 2015 Share Posted April 3, 2015 toni, try to use Sasu code. It should work. Link to comment
SpecT Posted April 3, 2015 Author Share Posted April 3, 2015 toni, try to use Sasu code. It should work. It does, but the problem is that the maps are in .zip. And the maps count is ~1600. And meta editing works only for maps that are in folder. Link to comment
WhoAmI Posted April 3, 2015 Share Posted April 3, 2015 Damn, I don't know if there is possibility to unpack .zip in MTA. Link to comment
SpecT Posted April 3, 2015 Author Share Posted April 3, 2015 Nevermind, I will try to figure it out. Maybe I will download them from the FTP and then extract all of them and re-upload ... that may take really long time but .. there is no other way to do it. Link to comment
WhoAmI Posted April 3, 2015 Share Posted April 3, 2015 Maybe wait for tip from other pro scripter. Maybe there is a way... Don't know. Link to comment
John Smith Posted April 3, 2015 Share Posted April 3, 2015 As far as i know zip files are automatically extracted to the folder with same name when running the resource Link to comment
WhoAmI Posted April 3, 2015 Share Posted April 3, 2015 But it doesn't matter, you can't start 1600 maps in the same time. Link to comment
Gallardo9944 Posted April 3, 2015 Share Posted April 3, 2015 Technically, making a custom scriptloader is easier than the method you want. It doesn't take a lot of effort Link to comment
WhoAmI Posted April 3, 2015 Share Posted April 3, 2015 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
SpecT Posted April 3, 2015 Author Share Posted April 3, 2015 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 ...... 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
WhoAmI Posted April 3, 2015 Share Posted April 3, 2015 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 Link to comment
SpecT Posted April 3, 2015 Author Share Posted April 3, 2015 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 Dude thanks for all of that 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
WhoAmI Posted April 3, 2015 Share Posted April 3, 2015 Well, you can also open script using fileOpen and find something about playSound. Nevermind, I combine too much. Link to comment
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