Jump to content

playSound with getZoneName


SoManyTears

Recommended Posts

Posted

The sound still does not play when I enter the cities.what's wrong ? can someone help?

cities = {

["Bone County"] = true,
["Tierra Robada"] = true,

}

addEventHandler('onClientResourceStart', localPlayer,
function  ()
	local x,y,z = getElementPosition(localPlayer)
	local city = getZoneName(x,y,z, true)
	if cities[city] then
      playSound("sound.mp3",true)
		end
end
)

 

  • Moderators
Posted

onClientResourceStart call the function once, when resource started. If in this time, `localPlayer` is not inside the zone, the music don't start.

You have two options:

- Place down looped 3D sound.

- Check player's position in every second, and start sound if inside the zone (and music isn't playing) or stop sound if outside the zone (and music plays)

  • Helpers
Posted

How about looking into the game's info.zon file? You find the entries...

zone
(...)
BONE, 0, -480.539, 596.349, -242.99, 869.461, 2993.87, 900.0, 1, BONE
ROBAD, 0, -2997.47, 1659.68, -242.99, -480.539, 2993.87, 900.0, 1, ROBAD
(...)
end

zonename, interior, start_x, start_y, start_z, end_x, end_y, end_z, levelNumber, gxtName

You can use

colshape createColRectangle ( float fX, float fY, float fWidth, float fHeight )

and then use addEventHandler with "onClientElementColShapeHit" and "onClientElementColShapeLeave" to detect player position, playSound if inside colshape, then stopSound if leaving colshape.

Hopefully this helps!

8MF74XW.pngZr2Ufps.png

Developer of Magic.TXD • Developer of MTA:Eir, Eir Lua • Company owner of EirDev

  • Moderators
Posted (edited)
4 minutes ago, The_GTA said:

How about looking into the game's info.zon file? You find the entries...

 


zone
(...)
BONE, 0, -480.539, 596.349, -242.99, 869.461, 2993.87, 900.0, 1, BONE
ROBAD, 0, -2997.47, 1659.68, -242.99, -480.539, 2993.87, 900.0, 1, ROBAD
(...)
end

 

zonename, interior, start_x, start_y, start_z, end_x, end_y, end_z, levelNumber, gxtName

You can use

 


colshape createColRectangle ( float fX, float fY, float fWidth, float fHeight )

 

and then use addEventHandler with "onClientElementColShapeHit" and "onClientElementColShapeLeave" to detect player position, playSound if inside colshape, then stopSound if leaving colshape.

Hopefully this helps!

This is a solution too, if you make a colshape around the center of the music's place.

Edited by Patrick

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