Jump to content

[Help] Use chat as a Player


JuAnY

Recommended Posts

Im looking for a resource, or create my own script, where I can use a command to talk in the player chatbox...

For example:

/playersay PLAYERNAME TEXT --->(this show in the chat) PLAYERNAME: TEXT

/playersay PLAYERNAME COMMAND(/quit) ---> "PLAYERNAME has left the server"

Any ideas? :)

Link to comment
  • Moderators

@venadHD: Please verify if it's possible before dropping methods that will let the OP think it's actually possible.

Plus, even if it was possible, the only two functions you dropped here is not helping him at all.

For the message part, it's possible by using outputChatBox but you need to replicate the colors for the player's name.

You can get the color by using getPlayerNametagColor and it will return the RGB color model of the player's name.

To use it in outputChatBox as you want only the player's name to be in that color and not the whole text, you have to set the r, g and a parameters to 255 and the colorCoded parameter to true so you can use multiple colors in the same text message. You will end up with something like this:

local playerName = getPlayerName(player) 
local r, g ,b = getPlayerNametagColor(player) 
local hexColor = "#"..toHex(r, g, b) -- Convert to hexadecimal string (i.e: "#FFAA55") 
outputChatBox(hexColor..playerName.."#FFFFFF: "..text, 255, 255, 255, true) 

Note that toHex is a usefull function so you have to paste the function in your code, you can get it here.

Results:

If the text is "Hello !" and getPlayerNametagColor(player) returns 255, 255, 0 and the player's name is "John #FF0000Cena" then it will be equivalent to:

outputChatBox("#FFFF00John #FF0000Cena: #FFFFFFHello !", 255, 255, 255, true) 

or:

JohnCena: Hello !

For the commands part, the only way to make another player use commands you want is by using the executeCommandHandler function.

However, as the wiki says:

NOTE: You can only execute commands created by Lua. You cannot execute MTA harcoded commands due to security reasons.

This means that you can not use the following functions:

https://wiki.multitheftauto.com/wiki/Cl ... e_Commands

bind defaults - Binds control defaults in the settings menu.

maps - This displays a list of all maps available on the server.

nick [nickname] - This changes your nickname whilst in-game to whatever you specify in the parameters.

msg [nickname] [message] or pm [nickname] [message] - This sends a private message to the person you specify in the [nickname] parameter. Only the person you specify can see the message. Both msg and pm perform the same function.

quit or exit - This disconnects you from the server and returns you to the Windows desktop. Performs the same function as the Quit button on the main menu.

ver - This displays the version number and copyright information for the software.

sver - This displays the version number of the server you are connected to.

time - This displays the current time.

disconnect - This disconnects you from the server and returns you to the main menu.

say [text] - This enables you to continue talking to people in the chat box whilst the console is open.

ignore [nickname] - This will not display any text typed by the player you wish to ignore. To stop ignoring a player, type ignore [nickname] again.

Also, note that there is a getKeyState but no setKeyState for the same security reasons.

To summarize the answer:

- You can fake a player message by reproducing yourself the entire message (so including the player's name) and the colors so it's impossible to know the player didn't actually wrote this message himself.

- But you can't fake player commands if the commands are MTA commands.

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...