-.Paradox.- Posted March 1, 2014 Share Posted March 1, 2014 Hello guys, does anybody know how to create a new chat? or edit the old chats? Like example Gang chat, thanks for help. Link to comment
Castillo Posted March 1, 2014 Share Posted March 1, 2014 Are you talking about a new chat system or editing a current chat command? You can bind keys to the player to act like "T" and "Y" keys. bindKey ( thePlayer, "U", "down", "chatbox", "Local Chat" ) Link to comment
-.Paradox.- Posted March 1, 2014 Author Share Posted March 1, 2014 creating a new chat system Link to comment
WhoAmI Posted March 1, 2014 Share Posted March 1, 2014 Then you dxDrawText and tables. Link to comment
Castillo Posted March 1, 2014 Share Posted March 1, 2014 You can try this one: https://community.multitheftauto.com/in ... ls&id=6380 Link to comment
-.Paradox.- Posted March 1, 2014 Author Share Posted March 1, 2014 No, you don't understand, I want to create a new chat like team chat. I will name it gang chat. I need just functions to create it, or an example... Link to comment
Castillo Posted March 1, 2014 Share Posted March 1, 2014 addEventHandler ( "onResourceStart", resourceRoot, function ( ) for _, player in ipairs ( getElementsByType ( "player" ) ) do -- Loop all the players. bindKey ( player, "U", "down", "chatbox", "GangChat" ) -- Bind the key "U" to the "GangChat" command. end end ) addEventHandler ( "onPlayerJoin", root, function ( ) bindKey ( source, "U", "down", "chatbox", "GangChat" ) -- Bind the key "U" to the "GangChat" command. end ) function gangChat ( thePlayer, _, ... ) local text = table.concat ( { ... }, " " ) if ( #text > 0 ) then outputChatBox ( text, thePlayer ) end end addCommandHandler ( "GangChat", gangChat ) Link to comment
-.Paradox.- Posted March 1, 2014 Author Share Posted March 1, 2014 Thanks working, but is there a way to lt only people who get invited can talk in gang chat? like example /invite randomplayer then we are the only players who can talk in gang chat and other people can't see I edited the code to keep showing player name addEventHandler ( "onResourceStart", resourceRoot, function ( ) for _, player in ipairs ( getElementsByType ( "player" ) ) do -- Loop all the players. bindKey ( player, "U", "down", "chatbox", "gangChat" ) -- Bind the key "U" to the "GangChat" command. end end ) addEventHandler ( "onPlayerJoin", root, function ( ) bindKey ( source, "U", "down", "chatbox", "gangChat" ) -- Bind the key "U" to the "GangChat" command. end ) function gangChat ( thePlayer, _, ... ) local text = table.concat ( { ... }, " " ) if ( #text > 0 ) then outputChatBox ("#FF32AA (GANG) "..getPlayerName(thePlayer)..": #FFFFFF" ..text, thePlayer, 255, 255, 255, true ) end end addCommandHandler ( "gangChat", gangChat ) Link to comment
Thorxx Posted March 1, 2014 Share Posted March 1, 2014 You can have it done by using MySQL or tables. Link to comment
WhoAmI Posted March 1, 2014 Share Posted March 1, 2014 Lol no! Setelementdata, thats all. For example. addCommandHandler("invite", function (player, cmd, name) if not name then return end setElementData(getPlayerFromName(name), "invited", true) end ) And then you are just checking if (getElementData(player, "invited") then Link to comment
Thorxx Posted March 1, 2014 Share Posted March 1, 2014 Lol no! Setelementdata, thats all. I didn't write all the ways to make it done, I just wrote two ways that he can use. Link to comment
-.Paradox.- Posted March 1, 2014 Author Share Posted March 1, 2014 But how to check if the player is invited or not? If the player is invited he can use the chat, if not he cant use the chat or see the chat. Link to comment
Moderators Citizen Posted March 1, 2014 Moderators Share Posted March 1, 2014 Lol no! Setelementdata, thats all.For example. addCommandHandler("invite", function (player, cmd, name) if not name then return end setElementData(getPlayerFromName(name), "invited", true) end ) And then you are just checking if (getElementData(player, "invited") then Will only work for one group chat and you will have to invite the guys each time they reconnect. I would use element datas to know in which group the guy is and persist the data in database (Mysql or account datas). The invite command will check in which group the player who wrote the cmd is and then add the target player to that group. Then the chat will display group messages between guys that are in the same group. Link to comment
Thorxx Posted March 1, 2014 Share Posted March 1, 2014 But how to check if the player is invited or not? If the player is invited he can use the chat, if not he cant use the chat or see the chat. And then you are just checking if (getElementData(player, "invited") then Link to comment
WhoAmI Posted March 1, 2014 Share Posted March 1, 2014 Well I wrote you how, but... addEventHandler ( "onResourceStart", resourceRoot, function ( ) for _, player in ipairs ( getElementsByType ( "player" ) ) do -- Loop all the players. bindKey ( player, "U", "down", "chatbox", "gangChat" ) -- Bind the key "U" to the "GangChat" command. end end ) addEventHandler ( "onPlayerJoin", root, function ( ) bindKey ( source, "U", "down", "chatbox", "gangChat" ) -- Bind the key "U" to the "GangChat" command. end ) function gangChat ( thePlayer, _, ... ) local isInvited = getElementData ( thePlayer, "invited" ) or false if ( isInvited ) then local text = table.concat ( { ... }, " " ) if ( #text > 0 ) then outputChatBox ("#FF32AA (GANG) "..getPlayerName(thePlayer)..": #FFFFFF" ..text, thePlayer, 255, 255, 255, true ) end end end addCommandHandler ( "gangChat", gangChat ) function invitePlayer ( thePlayer, _, playerName ) if not playerName then return end local playerToInvite = getPlayerFromName(playerName) if ( isElement ( playerToInvite ) ) then setElementData ( playerToInvite, "invited", true ) outputChatBox ( "You have been invited to the chat.", playerToInvite) else outputChatBox ( "There is no such a player!", thePlayer ) end end addCommandHandler ( "invite", invitePlayer ) Link to comment
-.Paradox.- Posted March 1, 2014 Author Share Posted March 1, 2014 Does this depend many gang chats? I mean if i have a gang chat with player 1 then player2 and player3 can have their own gang chat too like example Link to comment
Moderators Citizen Posted March 1, 2014 Moderators Share Posted March 1, 2014 Yes of course, excepted if you are using the element data "invited" like who am I did. Link to comment
-.Paradox.- Posted March 1, 2014 Author Share Posted March 1, 2014 Okay thanks gonna try Link to comment
-.Paradox.- Posted March 1, 2014 Author Share Posted March 1, 2014 I have a problem, when i invite a player, i can't use gangChat but he can use them, i want to both can talk in the gang chat, like a pm chat box Link to comment
Moderators Citizen Posted March 1, 2014 Moderators Share Posted March 1, 2014 I have a problem, when i invite a player, i can't use gangChat but he can use them, i want to both can talk in the gang chat, like a pm chat box A gang chat is not the same as PM because PM is between two players only (at least for me). You have to do another command first to create the gang/group and then you will invite other players in it. If you don't want to let anyone be able to create a gang/group (then definied by the script), you will have to create the group 1st and then you need to put AT LEAST one guy into it (usually the leader). In your case, the player1 who is not in a gang/group is inviting player2 in a gang he doesn't own. Link to comment
-.Paradox.- Posted March 1, 2014 Author Share Posted March 1, 2014 I want make it like a group pm if you know what i mean Link to comment
Moderators Citizen Posted March 1, 2014 Moderators Share Posted March 1, 2014 You don't want to use other resources but you can't do it yourself either even after we told you the main idea and the functions you would have to use. Learn to script simple stuff first. Check the Introduction to Scripting available on the wiki main page. function createGang( thePlayer, cmd, gngName ) if not thePlayer or not cmd then return end if not gngName then return outputChatBox("SYNTAX: /createGang ") end if getElementData(thePlayer, "gang") then return outputChatBox("You are already in a gang. Do /leaveGang to leave it.", thePlayer) end if isGangAlreadyExist(gngName) then return outputChatBox("The gang "..gngName.." already exist !", thePlayer) end local newGang = createElement("gang") setElementData(newGang, "name", gngName) setElementData(newGang, "leader", gngName) setElementData(newGang, "members", {}) outputChatBox("You successfully created the "..gngName.." gang and you are the leader !", thePlayer) end addCommandHandler("createGang", createGang, false, false) function inviteInGang( thePlayer, cmd, playerName ) if not thePlayer or not cmd then return end if not playerName then return outputChatBox("SYNTAX: /invite ", thePlayer) end local gang = getElementData(thePlayer, "gang") if not gang then return outputChatBox("You must be part of a gang first. Do /createGang to create your own.", thePlayer) end local newMember = getPlayerFromName(playerName) if not newMember then return outputChatBox("Player "..playerName.." not found !", thePlayer) end if newMember == thePlayer then return outputChatBox("You can't invite your self into a gang !", thePlayer) if getElementData(newMember, "gang") then return outputChatBox("The player "..playerName.." is already in a gang. Ask him to leave first.", thePlayer) end if addNewMemberToGang(gang, newMember) then local gangName = getElementData(gang, "name") or "" outputChatBox("Congrats ! You are now part of the "..tostring(gangName).." gang !", newMember) outputChatBox(playerName.." is now a member of your gang !", thePlayer) else outputChatBox("An error has occured. Please contact an administrator.", thePlayer) end end addCommandHandler("invite", inviteInGang, false, false) function leaveGang( thePlayer ) if not thePlayer then return end local gang = getElementData(thePlayer, "gang") if not gang then return outputChatBox("You already aren't in a gang !", thePlayer) end if removeMemberFromGang( gang, thePlayer ) then local gangName = getElementData(gang, "name") or "" local leader = getElementData(gang, "leader") outputChatBox("You successfully left the "..tostring(gangName).." gang !", thePlayer) if leader and isElement(leader) then outputChatBox(playerName.." left your gang !", leader) end else outputChatBox("An error has occured. Please contact an administrator.", thePlayer) end end addCommandHandler("leaveGang", leaveGang, false, false) function addNewMemberToGang( theGang, thePlayer ) if not theGang or not thePlayer then return end local members = getElementData(theGang, "members") table.insert(members, thePlayer) return (setElementData(newMember, "gang", theGang) and setElementData(theGang "members", members)) end function removeMemberFromGang( theGang, thePlayer ) if not theGang or nor thePlayer then return end local tmp = getElementData(theGang, "members") or {} local members = {} for k, member in ipairs(members) do if member ~= thePlayer then table.insert(members, member) end end return (removeElementData(thePlayer, "gang") and setElementData(theGang, "members", members)) end function isGangAlreadyExist( gngName ) for k, theGang in ipairs (getElementsByType("gang")) do local name = getElementData(theGang, "name") or "" if name == gngName then return true end end return false end function gangChat ( thePlayer, _, ... ) local text = table.concat ( { ... }, " " ) local theGang = getElementData(thePlayer, "gang") if #text == 0 or not theGang then return end local members = getElementData(theGang, "members") or {} local playerName = getPlayerName(thePlayer) for k, member in ipairs (members) do outputChatBox ("#FF32AA (GANG) "..playerName..": #FFFFFF"..text, member, 255, 255, 255, true ) end end addCommandHandler ( "gangChat", gangChat ) addCommandHandler ( "gc", gangChat ) This script may have bugs since I didn't test it. Link to comment
-.Paradox.- Posted March 4, 2014 Author Share Posted March 4, 2014 (edited) Gonna try Edited March 7, 2014 by Guest Link to comment
-.Paradox.- Posted March 7, 2014 Author Share Posted March 7, 2014 Thanks man its working 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