Dealman Posted December 27, 2014 Share Posted December 27, 2014 Just curious if anyone has found any reliable way of differentiating a map from a resource? I recall trying to do this before when I was working on a script to alter the volume of music played via maps. For the most part the issue lies with how onClientSoundStarted is designed. It would be a very welcome addition if it also returned the name of the resource that started it. But it doesn't. None of the sort. Before that event was introduced, I relied on a script that checked for sound elements with a length of 30 seconds or above when it was started. Then it used events available by the Race resource(onRaceStateChanging) to start a new timer every time a map changed(and then kill the timer if a sound was found). It worked pretty well, only issue was that it would sometime interfere with streamed music as well. Now I thought this would be easy to solve using getElementParent and getResourceName. However, that wasn't quite the case - and I'm not sure what the logic behind those functions are. For example, if I found a sound that was longer than 30 seconds - it was either a song started via a map or the music streamer. If I got the parent of that, it would return "map" for both sounds. And if I got the parent of that parent, it returned "resource" for both. After this I thought, well, I'll just get the resource name of the two and compare them. But this wasn't possible either, since getResourceName requires "resource-data" and not a resource element. Am I missing something here? Or is the logic behind getResourceName a bit odd? Link to comment
MTA Team botder Posted December 27, 2014 MTA Team Share Posted December 27, 2014 You need a serverside solution: Everytime a map resources starts you take it's resource root element (parent of 'map' element) and set the element data with the key type to resource-type -- resourceRoot is the root element of the resource -- resource is the pointer to the resource, which started setElementData(resourceRoot, "type", getResourceInfo(resource, "type")) Then you can use that information clientside to differentiate between maps/gamemodes/etc by getting the element data from the resource root element -- resourceRoot is the parent of the parent (= map) of the sound local resourceType = getElementData(resourceRoot, "type") Maybe that will help. 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