SetPlayerVoiceBroadcastTo: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Server function}}
{{Server function}}
__NOTOC__  
__NOTOC__  
<div style="border: 1px dotted blue; background: #00CC66;padding:4px;margin-bottom:2px;">'''Note''':  This function should only be used as a low-level function for advanced users.  For typical Voice scripting, please see the [[Resource:Voice|Voice Resource]]</div>
 
This function allows you to change who can hear the voice of a player.
This function allows you to change who can hear the voice of a player.
{{Important Note|This function should only be used as a low-level function for advanced users.  For typical Voice scripting, please see the [[Resource:Voice|Voice Resource]]}}


==Syntax==  
==Syntax==  
Line 9: Line 10:
bool setPlayerVoiceBroadcastTo ( element thePlayer, mixed broadcastTo )
bool setPlayerVoiceBroadcastTo ( element thePlayer, mixed broadcastTo )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[player]]:setVoiceBroadcastTo|voiceBroadcastTo|}}
===Required Arguments===  
===Required Arguments===  
*'''thePlayer:''' The [[player]] you wish to change
*'''thePlayer:''' The [[player]] you wish to change
Line 20: Line 21:
<section name="Server" class="server" show="true">
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function getPlayerFromName(...)
function getPlayer( ... )
if( ... ) then
if ( ... ) then
local foundList = {}
for i,v in ipairs( ... ) do
local elements = {};
for i,p in ipairs( getElementsByType 'player' ) do
for _, string in ipairs( { ... } ) do
if( string.find( getPlayerName(p):lower(), tostring(v):lower(), 1, true ) then
for _, element in ipairs( getElementsByType( 'player' ) ) do
table.insert( foundList, p )
if ( string.find( string:lower(), getPlayerName(element):lower(), 1, true ) ) then
table.insert( elements, element );
end
end
end
end
end
end
return unpack( foundList )
return elements;
end
end
return false
return false
end
end


function setBroadcastTo( p, cmd, p1, p2 )
addCommandHandler( 'broadcast',
if( p1 and p2 ) then
function( player, command, target, target_ )
p1, p2 = getPlayerFromName( p1, p2 )
if ( target and target_ ) then
if( p1 and p2 ) then
target, target_ = getPlayer( target, target_ );
setPlayerVoiceBroadcastTo( p1, p2 )
if ( target and target_ ) then
else
setPlayerVoiceBroadcastTo( target, target_ );
outputChatBox( p1 == false and 'Player to change broadcast could not be found!' or p2 == false and 'Players to hear player 1 could not be found!', p, 255, 0, 0, false )
else
outputChatBox( not target and "Target 1 not found!" or not target_ and "Target 2 not found!", root, 255, 0, 0, false );
end
end
end
end
end
end
)
addCommandHandler( 'bt', setBroadcastTo )
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>


==See Also==
==See Also==
{{Player_functions}}
{{Player functions|server}}

Latest revision as of 22:44, 6 September 2024


This function allows you to change who can hear the voice of a player.

[[{{{image}}}|link=|]] Important Note: This function should only be used as a low-level function for advanced users. For typical Voice scripting, please see the Voice Resource

Syntax

bool setPlayerVoiceBroadcastTo ( element thePlayer, mixed broadcastTo )

OOP Syntax Help! I don't understand this!

Method: player:setVoiceBroadcastTo(...)
Variable: .voiceBroadcastTo


Required Arguments

  • thePlayer: The player you wish to change
  • broadcastTo : Element or table of elements who should hear the voice from this player

Returns

Returns true if the value was set successfully, false otherwise.

Example

Click to collapse [-]
Server
function getPlayer( ... )
	if ( ... ) then
		
		local elements = {};
		for _, string in ipairs( { ... } ) do
			for _, element in ipairs( getElementsByType( 'player' ) ) do
				if ( string.find( string:lower(), getPlayerName(element):lower(), 1, true ) ) then
					table.insert( elements, element );
				end
			end
		end
		
		return elements;
	end
	
	return false
end

addCommandHandler( 'broadcast', 
	function( player, command, target, target_ )
		if ( target and target_ ) then
			target, target_ = getPlayer( target, target_ );
			if ( target and target_ ) then
				setPlayerVoiceBroadcastTo( target, target_ );
			else
				outputChatBox( not target and "Target 1 not found!" or not target_ and "Target 2 not found!", root, 255, 0, 0, false );
			end
		end
	end
)

See Also