Someone help me with modifying this

Hey guys. I want to make this voice addon only work if you are team_cop and such in DarkRP. Can someone help me or show me a way to do this? Thanks :slight_smile:


local function PlayerStartVoice( ply )
local client = LocalPlayer()
        if ( ply:IsPlayer() ) then
                client:EmitSound("jessev92/bf2/hud/activate_voip.wav")
        end
end
hook.Add( "PlayerStartVoice", "PlayerStartedTheirVoice", PlayerStartVoice)

local function PlayerEndVoice( ply )
local client = LocalPlayer()
        if ( ply:IsPlayer() ) then
                client:EmitSound("jessev92/bf2/hud/deactivate_voip.wav")    
        end    
end       
hook.Add( "PlayerEndVoice", "PlayerEndedTheirVoice", PlayerEndVoice)
        


Change

[lua]if ( ply:IsPlayer() ) then[/lua]

to

[lua]if ( ply:IsPlayer() and ply:IsCP() ) then[/lua]

in both functions.

[editline]12th September 2013[/editline]

If you’re on DarkRP 2.5+ then it’ll be ply:isCP(), not ply:IsCP()

Thanks again bud :slight_smile:

Okay, this works, but how can I make it where only CP can hear it, not the citizens and such?

[lua]if ( ply:IsPlayer() and ply:IsCP() and client:IsCP() ) then[/lua]

That’ll do it for you.

[editline]13th September 2013[/editline]

Thought I’m not sure why you check IsPlayer in the first place, you could get rid of that. The ply argument in that function would never not be a player entity.