Personal tools

Lua/Client/ClientSound/Static Functions/Create

From JC2-MP Documentation

< Lua‎ | Client‎ | ClientSound
Jump to: navigation, search

Returns    ClientSound
Prototype    ClientSound.Create(AssetLocation, table)
Description    No description


Required values

Type Name Notes
Vector3 position
number bank_id
number sound_id

Optional values

These values can be found in the sound libraries listed below, under the "Parameters" list for each sound.

Type Name Notes
number variable_id_distance Tell the game the index of the (distance) parameter.
number variable_id_focus Tell the game the index of the focus parameter.
number variable_id_rain Tell the game the index of the precipitation parameter.
number variable_id_time_of_day Tell the game the index of the timeofday parameter.
number variable_id_timeline Tell the game the index of the timeline parameter.

Example

Create the Mile High Club music where you click

  1. sound = nil
  2.  
  3. Events:Subscribe("MouseDown", function(args)
  4. 	if args.button ~= 1 then
  5. 		return
  6. 	end
  7.  
  8. 	Chat:Print("Creating sound", Color.White)
  9.  
  10. 	-- If a sound is already playing, remove it. This makes sure only one sound plays at once.
  11. 	CleanUp()
  12.  
  13. 	local result = Physics:Raycast(
  14. 		Camera:GetPosition(),
  15. 		Camera:GetAngle() * Vector3.Forward,
  16. 		0,
  17. 		100
  18. 	)
  19.  
  20. 	local spawnArgs = {
  21. 		position = result.position + result.normal * 0.5,
  22. 		bank_id = 25,
  23. 		sound_id = 148,
  24. 		variable_id_focus = 0
  25. 	}
  26. 	sound = ClientSound.Create(AssetLocation.Game, spawnArgs)
  27. end)
  28.  
  29. function CleanUp()
  30. 	if sound then
  31. 		sound:Remove()
  32. 		sound = nil
  33. 	end
  34. end
  35.  
  36. -- Make sure to clean up the sound on module unload.
  37. Events:Subscribe("ModuleUnload", CleanUp)

External links