OnClientSoundBeat: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
Fernando187 (talk | contribs) (Remove obsolete Requirements section) |
||
(11 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
{{Client event}} | {{Client event}} | ||
__NOTOC__ | __NOTOC__ | ||
{{New feature| | {{New feature|3.0131|1.3.1| | ||
This event is triggered when a '''sound''' beats. | This event is triggered when a '''sound''' beats. | ||
}} | }} | ||
{{Note|This event | {{Note|This event does not work correctly pre 1.3.1-9-04627 | ||
}} | |||
{{Note|This event is triggered ahead of a sound beat the number passed is the play time at which the beat occurs | |||
}} | |||
==Parameters== | ==Parameters== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
double theTime | |||
</syntaxhighlight> | </syntaxhighlight> | ||
*''' | *'''theTime''': the position in the song of the beat | ||
==Source== | ==Source== | ||
Line 16: | Line 19: | ||
==Example== | ==Example== | ||
<section name="Client" class="client" show="true"> | |||
This code will change the vehicle color to a random value if the sound beats and the localPlayer is inside a vehicle | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | function playMySound() | ||
playSound("sound.mp3") -- play the sound used for onClientSoundBeat | |||
addEventHandler("onClientSoundBeat", getRootElement(), changeVehicleColorOnSoundBeat) | |||
end | |||
addEventHandler("onClientResourceStart", getRootElement(), playMySound) | |||
function changeVehicleColorOnSoundBeat() | |||
if getPedOccupiedVehicle(localPlayer) then -- if the player is inside a vehicle | |||
setVehicleColor( getPedOccupiedVehicle(localPlayer), math.random(0,255), math.random(0,255), math.random(0,255) ) -- apply the color to the vehicle | |||
outputChatBox("The color of your vehicle was changed.") | |||
else | |||
outputChatBox("Could not change the vehicle color, the localPlayer is not inside a vehicle.") | |||
return end; | |||
end | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
==See Also== | ==See Also== |
Latest revision as of 17:07, 7 November 2024
This event is triggered when a sound beats.
Parameters
double theTime
- theTime: the position in the song of the beat
Source
The source of this event is the sound's element.
Example
Click to collapse [-]
ClientThis code will change the vehicle color to a random value if the sound beats and the localPlayer is inside a vehicle
function playMySound() playSound("sound.mp3") -- play the sound used for onClientSoundBeat addEventHandler("onClientSoundBeat", getRootElement(), changeVehicleColorOnSoundBeat) end addEventHandler("onClientResourceStart", getRootElement(), playMySound) function changeVehicleColorOnSoundBeat() if getPedOccupiedVehicle(localPlayer) then -- if the player is inside a vehicle setVehicleColor( getPedOccupiedVehicle(localPlayer), math.random(0,255), math.random(0,255), math.random(0,255) ) -- apply the color to the vehicle outputChatBox("The color of your vehicle was changed.") else outputChatBox("Could not change the vehicle color, the localPlayer is not inside a vehicle.") return end; end
See Also
Client sound events
- onClientSoundBeat
- onClientSoundChangedMeta
- onClientSoundFinishedDownload
- onClientSoundStarted
- onClientSoundStopped
- onClientSoundStream
Client event functions
- triggerLatentServerEvent
- triggerServerEvent
- Shared
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled