Jump to content

onPlayerChat MessageType 2


BriGhtx3

Recommended Posts

I'm trying to put out the message of the teamchat, but I can't switch to messageType 2.

function cheata (text,msType) 
if msType == 2 then 
    outputChatBox(msType) 
    outputChatBox(text) 
end 
end 
addEventHandler( "onPlayerChat", getRootElement(), cheata ) 

So when I press "y" and type in the message then the message isn't outputed. When I change the msType to 0 it puts the message out. The question is, how do I detect the message of the teamchat?

Link to comment
function cheata ( text,msType ) 
    if msType == 2 then 
        outputChatBox( tostring( msType ) ) 
        outputChatBox( text ) 
    end 
end 
addEventHandler( "onPlayerChat", root, cheata ) 

Because variable msType is number and you can't output in function outputChatBox.You need convert number to string see arguments in function https://wiki.multitheftauto.com/wiki/OutputChatBox

Link to comment

If it not use convert number to string in function outputChatBox then it created a error in script.

Just test my code and see.

Idk what you mean "detect" you can see him message in log file or create onPlayerChat event create a outputDebugString or outputServerLog.

Edited by Guest
Link to comment

So here I've got a function :

function teamsay_all(player,cmd, ...) 
local FRank = tonumber(destinyGetData (player,"rang")) 
local parametersTable = {...} 
local text = table.concat( parametersTable, " " ) 
local ranktitle = "" 
  
    if destinyGetData(player,"fraktion") == 1 then 
        if FRank == 0 then ranktitle = "Constable" end 
        if FRank == 1 then ranktitle = "Captian" end 
        if FRank == 2 then ranktitle = "Marshall" end 
        if FRank == 3 then ranktitle = "Commander" end 
        if FRank == 4 then ranktitle = "Bureau Chief" end 
        if FRank == 5 then ranktitle = "Chief of Department" end 
        red = 0 
        green = 0 
        blue = 205 
    else 
        triggerClientEvent ( player, "infobox", getRootElement(), "Du bist in keiner Fraktion!", 5000, 155, 0, 0 ) 
    end 
    for playeritem, index in pairs(fraktionsMemb[destinyGetData(player,"fraktion")]) do 
        outputChatBox ( "[[ "..ranktitle.." | "..getPlayerName(player)..": "..text.." ]]", playeritem, red, green, blue ) 
    end 
end 
addCommandHandler("t",teamsay_all) 

Now I want to use that function for the y-chat. So I used this code :

function cheata (text,msType) 
    if msType == 2 then 
executeCommandHandler("t",source,text) 
end 
end 
addEventHandler( "onPlayerChat", getRootElement(), cheata ) 

But it doesn't work :/

When I use /t it works.

Link to comment
addEventHandler("onPlayerJoin",root, 
function () 
    bindKey(source, "y", "down", "chatbox", "Faction Chat") 
end) 
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, player in ipairs(getElementsByType("player")) do 
        bindKey(player, "y", "down", "chatbox", "FactionChat") 
    end 
end) 
  
function factionChat(player,cmd,...) 
    local message = table.concat ( {...}, " " ) 
    if(message ~= nil or message ~= "") then 
        local name = getPlayerName(player) 
        outputChatBox(tostring(name) ..": ".. tostring(message)) 
    end 
end 
addCommandHandler("FactionChat",factionChat) 

This will overwrite the "Team say" with "FactionChat".

Link to comment

You can also try this:

addEventHandler("onPlayerJoin",root, 
function () 
    bindKey(source, "y", "down", "chatbox", "Faction Chat") 
end) 
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, player in ipairs(getElementsByType("player")) do 
        bindKey(player, "y", "down", "chatbox", "FactionChat") 
    end 
end) 
  
function factionChat(player,cmd,...) 
    local message = table.concat ( {...}, " " ) 
    if(message ~= nil or message ~= "") then 
        local FRank = tonumber(destinyGetData (player,"rang")) 
        local ranktitle = "" 
        if destinyGetData(player,"fraktion") == 1 then 
            if FRank == 0 then ranktitle = "Constable" end 
            if FRank == 1 then ranktitle = "Captian" end 
            if FRank == 2 then ranktitle = "Marshall" end 
            if FRank == 3 then ranktitle = "Commander" end 
            if FRank == 4 then ranktitle = "Bureau Chief" end 
            if FRank == 5 then ranktitle = "Chief of Department" end 
            red = 0 
            green = 0 
            blue = 205 
        else 
            triggerClientEvent ( player, "infobox", getRootElement(), "Du bist in keiner Fraktion!", 5000, 155, 0, 0 ) 
        end 
        local name = getPlayerName(player) 
        for playeritem, index in pairs(fraktionsMemb[destinyGetData(player,"fraktion")]) do 
            outputChatBox ( "[[ "..ranktitle.." | "..tostring(name)..": "..tostring(message).." ]]", playeritem, red, green, blue ) 
        end      
    end 
end 
addCommandHandler("FactionChat",factionChat) 

To see if it works with your faction system.

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