BriGhtx3 Posted January 6, 2012 Share Posted January 6, 2012 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
Kenix Posted January 6, 2012 Share Posted January 6, 2012 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
BriGhtx3 Posted January 6, 2012 Author Share Posted January 6, 2012 You didn't read the question -.- I want to detect if the player uses the teamchat and output his message and not change the type to string. The problem is that he doesn't detect whether it is the teamchat or not. Link to comment
Kenix Posted January 6, 2012 Share Posted January 6, 2012 (edited) 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 January 6, 2012 by Guest Link to comment
BriGhtx3 Posted January 6, 2012 Author Share Posted January 6, 2012 I tested it. It already outputs the messageType without the tostring when the type is 0, but it doesn't output it WHEN THE TYPE IS TEAMMESSAGE Link to comment
Castillo Posted January 6, 2012 Share Posted January 6, 2012 It works perfectly, BUT you must be in a TEAM. Link to comment
BriGhtx3 Posted January 6, 2012 Author Share Posted January 6, 2012 Ehm then how can I use the y-chat for a faction chat? So that I bind the y-key to my chat function. Link to comment
BriGhtx3 Posted January 6, 2012 Author Share Posted January 6, 2012 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
Kenix Posted January 6, 2012 Share Posted January 6, 2012 Try function cheata (text,msType) if msType == 2 then executeCommandHandler("t",source,_,text) end end addEventHandler( "onPlayerChat", getRootElement(), cheata ) Test it and see in debug. Link to comment
Castillo Posted January 6, 2012 Share Posted January 6, 2012 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
BriGhtx3 Posted January 6, 2012 Author Share Posted January 6, 2012 Oh okay Thank you Link to comment
Castillo Posted January 6, 2012 Share Posted January 6, 2012 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
BriGhtx3 Posted January 6, 2012 Author Share Posted January 6, 2012 It already works with my Faction System 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