SetPlayerVoiceBroadcastTo: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(→‎No, thanks: Undo revision 33161 by Sora (talk))
Line 20: Line 20:
<section name="Server" class="server" show="true">
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function getPlayerFromNamePart(name)
    if name then
        for i, player in ipairs(getElementsByType("player")) do
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then
                return player
            end
        end
    end
    return false
end
function voice(player,cmd,target1,target2)
local tp1 = getPlayerFromNamePart(target1)
local tp2 = getPlayerFromNamePart(target2)
if tp1 and tp2 then
setPlayerVoiceBroadcastTo ( tp1, tp2 )
else
outputChatBox("* Usage : /bt [playername][playername] ",player,255,255,255,true) -- for example /bt sora sheepy
end
end
addCommandHandler("bt",voice)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 12:09, 8 September 2012

Note: This function should only be used as a low-level function for advanced users. For typical Voice scripting, please see the Voice Resource

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

Syntax

bool setPlayerVoiceBroadcastTo ( element thePlayer, mixed broadcastTo )

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 getPlayerFromNamePart(name)
    if name then 
        for i, player in ipairs(getElementsByType("player")) do
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then
                return player 
            end
        end
    end
    return false
end

function voice(player,cmd,target1,target2)
local tp1 = getPlayerFromNamePart(target1)
local tp2 = getPlayerFromNamePart(target2)
if tp1 and tp2 then
setPlayerVoiceBroadcastTo ( tp1, tp2 )
else
outputChatBox("* Usage : /bt [playername][playername] ",player,255,255,255,true) -- for example /bt sora sheepy
end
end
addCommandHandler("bt",voice)

See Also