# CreateSound

- **Ortam:** İstemci, Sunucu
- **İngilizce aslı:** https://wiki.facepunch.com/gmod/Global.CreateSound
- **Çeviri tarihi:** 2025-09-08

```lua
CSoundPatch CreateSound( Entity targetEnt, string soundName, CRecipientFilter filter = nil )
```

## Açıklama

Belirtilen entity'ye bağlı bir ses döndürür.

> **NOT:** Aynı anda entity başına, ses dosyası başına yalnızca bir CSoundPatch oluşturabilirsiniz.

> **NOT:** Geçerli örnekleme hızları: **11025 Hz, 22050 Hz ve 44100 Hz**, aksi takdirde şu tür bir mesaj görebilirsiniz:
>
> `Unsupported 32-bit wave file your_sound.wav` ve `Invalid sample rate (48000) for sound 'your_sound.wav'`

## Argümanlar

1. [Entity](https://gmod.tr/wiki/Entity) **targetEnt**: Hedef entity.
2. [string](https://gmod.tr/wiki/string) **soundName**: Çalınacak ses. (Ses dosyası yolu veya bir [soundscript](https://gmod.tr/wiki/sound.Add)) [Soundscript Karakterleri](https://developer.valvesoftware.com/wiki/Soundscripts/en#Sound_Characters) desteklenmektedir.
3. [CRecipientFilter](https://gmod.tr/wiki/CRecipientFilter) **filter** = nil: Bu sesin ağ üzerinden gönderileceği oyuncuların bir [CRecipientFilter](https://gmod.tr/wiki/CRecipientFilter)'ı. Ayarlanmazsa, varsayılan bir [CPASAttenuationFilter](https://developer.valvesoftware.com/wiki/CRecipientFilter#Derived_classes)'dır. > **NOT:** Bu argüman yalnızca sunucu tarafında çalışır.

## Döndürülen Değer

1. [CSoundPatch](https://gmod.tr/wiki/CSoundPatch): Ses nesnesi. Sesin çalmasını istediğiniz sürece bu nesneye bir referans tutmalısınız!

### Örnek

[surface.PlaySound](https://gmod.tr/wiki/surface.PlaySound)'a benzer şekilde, ancak istemci ve sunucu tarafında kullanılabilir olan, her yerde bir ses çalar.

```lua
local LoadedSounds
if CLIENT then
	LoadedSounds = {} -- bu tablo mevcut CSoundPatch'leri önbelleğe alır
end

local function ReadSound( FileName )
	local sound
	local filter
	if SERVER then
		filter = RecipientFilter()
		filter:AddAllPlayers()
	end
	if SERVER or !LoadedSounds[FileName] then
		-- RecipientFilter nedeniyle ses her zaman sunucu tarafında yeniden oluşturulur.
		sound = CreateSound( game.GetWorld(), FileName, filter ) -- her zaman var olan worldspawn'a bağlı yeni sesi oluştur
		if sound then
			sound:SetSoundLevel( 0 ) -- her yerde çal
			if CLIENT then
				LoadedSounds[FileName] = { sound, filter } -- CSoundPatch'i önbelleğe al
			end
		end
	else
		sound = LoadedSounds[FileName][1]
		filter = LoadedSounds[FileName][2]
	end
	if sound then
		if CLIENT then
			sound:Stop() -- aksi takdirde tekrar çalmaz
		end
		sound:Play()
	end
	return sound -- sesi kendiniz durdurmak isterseniz kullanışlıdır
end

-- Hazır olduğumuzda, sesi çalıyoruz:
ReadSound( "phx/hmetal1.wav" )
```

- [GMod Wiki ana sayfası](https://gmod.tr/wiki)

---

[Tüm sunucular](https://gmod.tr/) · [GmodTR Launcher](https://gmod.tr/launcher) · [Rehber](https://gmod.tr/rehber) · [GMod Wiki](https://gmod.tr/wiki) · [GmodTR nedir?](https://gmod.tr/hakkinda) · [Sunucu ekle](https://gmod.tr/sunucu-ekle) · [Discord](https://discord.gg/gmodtr)

Kaynak: https://gmod.tr/wiki/Global.CreateSound
