Sign in to follow this  
SoManyTears

playSound with getZoneName

Recommended Posts

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
)

 

Share this post


Link to post

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)

Share this post


Link to post

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!

Share this post


Link to post
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

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.