GetSoundPosition

Definition

double,double,double GetSoundPosition(string 3DSoundObjectName)

Description

This function receives the name of the 3D sound 3DSoundObjectName and returns its position as three values x, y and z.

Parameters

3DSoundObjectName
Specifies the name of the 3D sound object. You can also use the name “this” for this parameter. In this case, “this” refers to the 3D sound name that this script is attached to.

Return Value

This function returns the 3D sound position as three values x, y and z.

Example 1

posX = 0.0
posY = 0.0
posZ = 0.0

function Init()
    posX, posY, posZ = GetSoundPosition("sound1")

    message = string.format("\nSound position is > (%.2f, %.2f, %.2f)" , posX, posY, posZ)
    PrintConsole(message)
end

function Update()

end
First, GetSoundPosition function returns the position of “sound1” 3D sound. Then we display the position values in the console using the PrintConsole function.

Example 2

--Name of script is GetSoundPosition2.lua

posX = 0.0
posY = 0.0
posZ = 0.0

function Init()
    posX, posY, posZ = GetSoundPosition("this")

    message = string.format("\nSound position is > (%.2f, %.2f, %.2f)" , posX, posY, posZ)
    PrintConsole(message)
end

function Update()

end
Assume that the above script named GetSoundPosition2.lua is attached to a 3D sound object named “sound1”. In this case, string “this”  in the GetSoundPosition function will be equal to “sound1”. In our example, the function GetSoundPosition returns the position of current 3D sound, which is “sound1”. Then we display the position values in the console using the PrintConsole function.
adminGetSoundPosition