Jump to content

ChatboxOuput


Recommended Posts

Example 1: This example displays a chat message to all users.

x = 5

y = 10

-- Displays the message

outputChatBox ( "I have " .. x .. " apples and " .. y .. " oranges." )

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.

outputChatBox ( "Red #ffffffWhite", 255,0,0,true )

Example 3: This example allows for coloured chat, according to a player's nametag. This makes use of colour coded outputs.

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 = getClientName ( 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

Example 4: This example displays a chat message to a single user called someguy.

-- Find the player element for the player called 'someguy'

myPlayer = getPlayerFromNick ( "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

that stands in the touterial of mta but now i wanne know how to make the /command and then that triggers the script that sends the message into the chat may sound an bit noob but im learning lua so...

Greatings DJFrankie

Link to comment

Use addCommandHandler. See wiki for documentation.

  
function myCommandFunction ( playerSource, command, parameter1, parameter2 ) 
  outputChatBox ( "you typed /mycommand", playerSource ) 
end 
  
addCommandHandler ( "mycommand", myCommandFunction ) 
  

Link to comment

Okay ive got an question the script works great but it doesnt show to everyone does it? it only g'o's to your self right? how can i make it that it sends it to everyone like: -XIII-DJFrankie Is Laughing Out Loud!!

The script that i use now only sends it to your self:

  
function lolFunction ( playerSource, command, parameter1, parameter2 ) 
  outputChatBox ( "Im Laughing Out Loud!", playerSource ) 
end 
  
addCommandHandler ( "lolcommand", lolCommandFunction ) 
  

Can someone explain this because i dont understand anything off the wiki :P

EDIT: Know server says: WARNING: lol.lua: Bad Argument @ 'AddCommandHandler' - Line:5

Is this an problem? because it doesnt work anymore...

Greatings Frank

Link to comment

Try this:

function lolCommandFunction ( playerSource, command ) 
  outputChatBox ( "Im Laughing Out Loud!", playerSource ) 
end 
addCommandHandler ( "lolcommand", getRootElement(), lolCommandFunction ) 

and for your script with included name:

function lolCommandFunction ( playerSource, command ) 
  outputChatBox ( "* " .. getClientName(playerSource) .. " is Laughing Out Loud!") 
end 
addCommandHandler ( "lolcommand", getRootElement(), lolCommandFunction ) 

Link to comment

Ehm...

WARNING: lol.lua: Bad argument@ 'addCommandHandler' - Line: 4

With this script:

  
function lolCommandFunction ( playerSource, command ) 
  outputChatBox ( "* " .. getClientName(getRootElement()) .. " is Laughing Out Loud!") 
end 
addCommandHandler ( "lolcommand", getRootElement(), lolCommandFunction ) 
  

Link to comment

What terenex meants was the following I think:

# function lolCommandFunction ( playerSource, command )

# outputChatBox ( "* " .. getClientName(playerSource) .. " is Laughing Out Loud!", getRootElement() )

# end

# addCommandHandler ( "lolcommand", getRootElement(), lolCommandFunction )

this will mainly send the message to getRootElement(), which basically is your universe, it contains everything: players, vehicles, objects, elements, etc.

You can see it as a tree of which the result of getRootElement() is the tree-root. players, vehicles, objects, etc are all sub-trees of this.

So if you would use the root element to send the message to it will also reach ALL players :) (correct me if this is wrong)

note: the argument of getClientName MUST be a player-object. a vehicle or blip for instance are of different types and conflict in their data structures, for this reason the root element cannot be used as argument of that function.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...