Resource:Gang Manager/createGang: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Server client function}} {{Note_box|Avoid outputting text to the chatbox that isn't actually chat, as this can be annoying for players. Output information and status message...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Server client function}}
{{Server client function}}
{{Note_box|Avoid outputting text to the chatbox that isn't actually chat, as this can be annoying for players. Output information and status messages to the HUD.}}
Creates gang with chosen name in the database.
__NOTOC__
This outputs the specified text string to the chatbox. It can be specified as a message to certain player(s) or all players.
 
It can optionally allow you to embed color changes into the string by setting the colorCoded boolean to true. This allows:
<syntaxhighlight lang="lua">
outputChatBox ( "#FF0000Hello #00FF00World", getRootElement(), 255, 255, 255, true )
</syntaxhighlight>
This will display as: '''<span style='color:red;'>Hello</span> <span style='color:green'>World</span> '''


==Syntax==
==Syntax==
<section name="Server" class="server" show="true">
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">bool outputChatBox ( string text [, element visibleTo=getRootElement(), int r=231, int g=217, int b=176, bool colorCoded=false ] )</syntaxhighlight>
<syntaxhighlight lang="lua">string createGang ( string GangName )</syntaxhighlight>


==Required Arguments==
==Required Arguments==
*'''text:''' The text string that you wish to send to the chat window. If more than 128 characters it will not be showed in chat.
*'''GangName:''' Name of the gang you wish to create
 
==Optional Arguments==
{{OptionalArg}}
*'''visibleTo:''' This specifies who the chat is visible to. Any players in this element will see the chat message. See [[visibility]].
*'''r:''' The amount of red in the color of the text. Default value is 231.
*'''g:''' The amount of green in the color of the text. Default value is 217.
*'''b:''' The amount of blue in the color of the text. Default value is 176.
*'''colorCoded:''' A boolean value determining whether or not '#RRGGBB' tags should be used.
Note: The #RRGGBB format must contain capital letters a-f is not acceptable but A-F is.
</section>
</section>
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">bool outputChatBox ( string text [, int r=231, int g=217, int b=176, bool colorCoded=false ] )</syntaxhighlight>
<syntaxhighlight lang="lua">string createGang ( string GangName )</syntaxhighlight>


==Required Arguments==
==Required Arguments==
*'''text:''' The text string that you wish to send to the chat window. If more than 128 characters it will not be showed in chat.
*'''GangName:''' Name of the gang you wish to create
 
==Optional Arguments==
{{OptionalArg}}
*'''r:''' The amount of red in the color of the text. Default value is 231.
*'''g:''' The amount of green in the color of the text. Default value is 217.
*'''b:''' The amount of blue in the color of the text. Default value is 176.
*'''colorCoded:''' A boolean value determining whether or not '#RRGGBB' tags should be used.
</section>
</section>


==Returns==
==Returns==
Returns ''true'' if the message was displayed successfully. Returns ''false'' if invalid arguments are specified.
*'''Gang:''' ID of the gang that was created
 
==Example==
<section name="Server" class="server" show="true">
'''Example 1:''' This example displays a chat message to all users.
<syntaxhighlight lang="lua">
x = 5
y = 10 
-- Displays the message
outputChatBox ( "I have " .. x .. " apples and " .. y .. " oranges." )
</syntaxhighlight>
 
'''Example 2:''' This example outputs a simple colour coded message, "Red White", where the 'White' is in white colour, and 'Red' is in a red colour.
<syntaxhighlight lang="lua">
outputChatBox ( "Red #FFFFFFWhite", getRootElement(), 255, 0, 0, true )
</syntaxhighlight>
 
'''Example 3:''' This example allows for coloured chat, according to a player's nametag.  This makes use of colour coded outputs.
<syntaxhighlight lang="lua">
function colouredChat ( message, theType )
if theType == 0 then --if its normal chat (not /me or teamchat) then
cancelEvent() --prevent MTA from outputting chat
message = string.gsub(message, "#%x%x%x%x%x%x", "") --remove any hex tags in a player's chat to prevent custom colours by using lua's string.gsub
local r,g,b = getPlayerNametagColor ( source ) --get the player's nametag colour
local chatterName = getPlayerName ( source ) --get his name
--output a message with the name as his nametag colour, and the rest in white.
outputChatBox ( chatterName..":#FFFFFF "..message, getRootElement(), r, g, b, true )
end
end
addEventHandler("onPlayerChat", getRootElement(), colouredChat)
</syntaxhighlight>
 
'''Example 4:''' This example displays a chat message to a single user called ''someguy''.
<syntaxhighlight lang="lua">
-- Find the player element for the player called 'someguy'
myPlayer = getPlayerFromName ( "someguy" )
-- If a player was found called 'someguy' then...
if ( myPlayer ~= false ) then
    x = 5
    y = 10
    -- Display the message
    outputChatBox ( "I have " .. x .. " apples and " .. y .. " oranges.", myPlayer )
end
</syntaxhighlight>
 
'''Example 5:''' These two functions can speed up typing, and display a message when a player Joins.
<syntaxhighlight lang="lua">
local msg_red,msg_green,msg_blue = 255,255,0
 
function servertalkprivate(message, sendto)
        --Talk to one client only
outputChatBox(tostring(message), sendto, msg_red, msg_green, msg_blue, true)
end
 
function servertalk(message)
        --Talk to everyone
servertalkprivate(message, getRootElement())
end
 
function onJoin()
servertalkprivate("Welcome to My Server", source)
end
 
addEventHandler("onPlayerJoin",getRootElement(),onJoin)
</syntaxhighlight>
</section>
 
==See Also==
{{Server functions}}
[[cs:outputChatBox]]
[[ru:outputChatBox]]

Latest revision as of 23:11, 23 June 2014

Creates gang with chosen name in the database.

Syntax

Click to collapse [-]
Server
string createGang ( string GangName )

Required Arguments

  • GangName: Name of the gang you wish to create
Click to collapse [-]
Client
string createGang ( string GangName )

Required Arguments

  • GangName: Name of the gang you wish to create

Returns

  • Gang: ID of the gang that was created