Frank-De-Ruiter Posted January 4, 2008 Share Posted January 4, 2008 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
ChrML Posted January 5, 2008 Share Posted January 5, 2008 Use addCommandHandler. See wiki for documentation. function myCommandFunction ( playerSource, command, parameter1, parameter2 ) outputChatBox ( "you typed /mycommand", playerSource ) end addCommandHandler ( "mycommand", myCommandFunction ) Link to comment
Frank-De-Ruiter Posted January 6, 2008 Author Share Posted January 6, 2008 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 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
Mount Posted January 6, 2008 Share Posted January 6, 2008 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
therenex Posted January 6, 2008 Share Posted January 6, 2008 ummm if you put playerSource in the first outputChatBox only he will see the message... just change "playerSource" by "getRootElement()". That should work. Link to comment
Frank-De-Ruiter Posted January 6, 2008 Author Share Posted January 6, 2008 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
[email protected] Posted January 6, 2008 Share Posted January 6, 2008 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
therenex Posted January 6, 2008 Share Posted January 6, 2008 maybe you should define something as your root element. gamemode_root = getRootElement() so instead of using getRootElement() on your codes, put gamemode_root. Link to comment
[email protected] Posted January 9, 2008 Share Posted January 9, 2008 maybe you should define something as your root element. gamemode_root = getRootElement() so instead of using getRootElement() on your codes, put gamemode_root. Shouldn't really make a difference I think..., unless the root element changes to a different one, but that should not be the case I think. Link to comment
Jumba' Posted January 9, 2008 Share Posted January 9, 2008 Does it matter if you put getRootElement? it'll show it to all players as long as you remove playerSource right? Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now