veigac4tm Posted July 23, 2016 Share Posted July 23, 2016 Hello I need help to create a teamchat for me. I do not know how they could help me? Here the team is defined by getElementData(player,"NameGroup") could guide me? Link to comment
LabiVila Posted July 23, 2016 Share Posted July 23, 2016 So you want that all the players with 'NameGroup' see your messages when you write, not the rest? If not, be more specific please Link to comment
veigac4tm Posted July 23, 2016 Author Share Posted July 23, 2016 Sorry, my idea is as follows. I want to be a squad chat, all players who have the same squad can see the message is to be a kind of teamchat. Its clear? Link to comment
ALw7sH Posted July 23, 2016 Share Posted July 23, 2016 I might be bad at explaining but I hope you get it lol addCommandHandler("groupChat", -- Make a new command function(player,_,...) -- I've wrote ... because every word will be counted as a separated argument and ... will get all the arguments which is what the player wrote local playerGroup = getElementData(player,"NameGroup") if playerGroup then -- Make sure the player is within group local message = getPlayerName(player)":#FFFFFF "..table.concat({...}," ") -- Convert what the player wrote from arguments to one string for k,v in ipairs(getElementsByType("player")) do -- loop all players local group = getElementData(v,"NameGroup") if group and group == playerGroup then -- Check if this player are within the same group as the player who sent the message outputChatBox("[Group] "..message,v,255,255,255,true) -- output the message to this player end end end end ) Make a new bindKey for all the players whose within groups e.g bindKey(player,"key","down","chatbox","groupChat") Link to comment
veigac4tm Posted July 23, 2016 Author Share Posted July 23, 2016 I might be bad at explaining but I hope you get it lol addCommandHandler("groupChat", -- Make a new command function(player,_,...) -- I've wrote ... because every word will be counted as a separated argument and ... will get all the arguments which is what the player wrote local playerGroup = getElementData(player,"NameGroup") if playerGroup then -- Make sure the player is within group local message = getPlayerName(player)":#FFFFFF "..table.concat({...}," ") -- Convert what the player wrote from arguments to one string for k,v in ipairs(getElementsByType("player")) do -- loop all players local group = getElementData(v,"NameGroup") if group and group == playerGroup then -- Check if this player are within the same group as the player who sent the message outputChatBox("[Group] "..message,v,255,255,255,true) -- output the message to this player end end end end ) Make a new bindKey for all the players whose within groups e.g bindKey(player,"key","down","chatbox","groupChat") I tried but did not work. Below is the archive of my group system It helps? Server addEvent("onPlayerCreatedGroup",true) addEvent("onPlayerDeletedGroup",true) addEventHandler("onResourceStart",resourceRoot,function() executeSQLQuery("CREATE TABLE IF NOT EXISTS Groups_x22 (Account,NameGroup,RankPlayer,Owner,Event,Ruel)") executeSQLQuery("CREATE TABLE IF NOT EXISTS GrupsMembers_x22 (Account,NameGroup,RankPlayer,State,Name)") executeSQLQuery("CREATE TABLE IF NOT EXISTS GrupsInvite_x22 (Account,Name,NameGroup)") executeSQLQuery("CREATE TABLE IF NOT EXISTS GroupMoney_x22 (Account,Name,RankPlayer,NameGroup,Amount,Tick)") outputDebugString("Sql Group System , Loaded .",3) exports.scoreboard:addScoreboardColumn("NameGroup") exports.scoreboard:addScoreboardColumn("RankPlayer") for _,plrs in ipairs (getElementsByType("player")) do local acc = getPlayerAccount(plrs) if ( acc ) then if not( isGuestAccount(acc) ) then setElementData(plrs,"AccountName",tostring(getAccountName(acc))) local Row = executeSQLQuery("SELECT * FROM GrupsMembers_x22 WHERE Account=?",tostring(getAccountName(acc))) if ( type(Row) == "table" and #Row == 0 or not Row ) then setElementData(plrs,"NameGroup","N/A") setElementData(plrs,"RankPlayer","N/A") else setElementData(plrs,"NameGroup",tostring(Row[1]["NameGroup"])) setElementData(plrs,"RankPlayer",tostring(Row[1]["RankPlayer"])) local Row_ = executeSQLQuery("SELECT * FROM Groups_x22 WHERE NameGroup=?",tostring(Row[1]["NameGroup"])) if ( type(Row_) == "table" and #Row_ == 0 or not Row_ ) then return false else setElementData(resourceRoot,"Event"..tostring(Row_[1]["NameGroup"]).."",tostring(Row_[1]["Event"])) setElementData(resourceRoot,"Ruel"..tostring(Row_[1]["NameGroup"]).."",tostring(Row_[1]["Ruel"])) setElementData(resourceRoot,"General"..tostring(Row_[1]["NameGroup"]).."",tostring(Row_[1]["General"])) end end else setElementData(plrs,"AccountName","N/A") setElementData(plrs,"NameGroup","N/A") setElementData(plrs,"RankPlayer","N/A") end else setElementData(source,"AccountName","N/A") setElementData(plrs,"NameGroup","N/A") setElementData(plrs,"RankPlayer","N/A") end end end) addEventHandler("onPlayerJoin",root,function() setElementData(source,"AccountName","N/A") setElementData(source,"NameGroup","N/A") setElementData(source,"RankPlayer","N/A") end) addEventHandler("onPlayerLogin",root,function(_,account) setElementData(source,"AccountName",tostring(getAccountName(account))) local Row = executeSQLQuery("SELECT * FROM GrupsMembers_x22 WHERE Account=?",tostring(getAccountName(account))) if ( type(Row) == "table" and #Row == 0 or not Row ) then setElementData(source,"NameGroup","N/A") setElementData(source,"RankPlayer","N/A") else setElementData(source,"NameGroup",tostring(Row[1]["NameGroup"])) setElementData(source,"RankPlayer",tostring(Row[1]["RankPlayer"])) executeSQLQuery("UPDATE GrupsMembers_x22 SET State=? WHERE Account=?",tostring("Online"),tostring(getAccountName(account))) end end) addEventHandler("onPlayerLogout",root,function() local accountName = getElementData(source,"AccountName") local Row = executeSQLQuery("SELECT * FROM GrupsMembers_x22 WHERE Account=?",tostring(accountName)) if ( type(Row) == "table" and #Row == 0 or not Row ) then return false else executeSQLQuery("UPDATE GrupsMembers_x22 SET State=? WHERE Account=?",tostring("Offline"),tostring(accountName)) end setElementData(source,"AccountName","N/A") setElementData(source,"NameGroup","N/A") setElementData(source,"RankPlayer","N/A") triggerClientEvent(source,"DestroyGui",source) end) addEventHandler("onPlayerQuit",root,function() local accountName = getElementData(source,"AccountName") if ( accountName ~= "N/A" ) then local Row = executeSQLQuery("SELECT * FROM GrupsMembers_x22 WHERE Account=?",tostring(accountName)) if ( type(Row) == "table" and #Row == 0 or not Row ) then return false else executeSQLQuery("UPDATE GrupsMembers_x22 SET State=? WHERE Account=?",tostring("Offline"),tostring(accountName)) end end end) addEvent("CreateGroup",true) addEventHandler("CreateGroup",root,function(NameGroup) local accountName = getElementData(source,"AccountName") local CheckNameGroup = executeSQLQuery("SELECT * FROM Groups_x22 WHERE NameGroup=?",tostring(NameGroup)) if ( type(CheckNameGroup) == "table" and #CheckNameGroup == 0 or not CheckNameGroup ) then executeSQLQuery("INSERT INTO Groups_x22 (Account,NameGroup,RankPlayer,Owner,Event,Ruel) VALUES (?,?,?,?,?,?)",tostring(accountName),tostring(NameGroup),tostring("General"),tostring(string.gsub(getPlayerName(source),"#%x%x%x%x%x%x","")),tostring("Nada"),tostring("Nada")) executeSQLQuery("INSERT INTO GrupsMembers_x22 (Account,NameGroup,RankPlayer,State,Name) VALUES (?,?,?,?,?)",tostring(accountName),tostring(NameGroup),tostring("General"),tostring("Online"),tostring(string.gsub(getPlayerName(source),"#%x%x%x%x%x%x",""))) outputChatBox("#FF0000: #FFFFFFUm novo esquadrão foi criado [ Comandante : #00FF00"..getPlayerName(source).." #FFFFFF/ Esquadrão : #00FF00"..tostring(NameGroup).." ]#FFFFFF",everybody,0,255,255,true) triggerEvent("onPlayerCreatedGroup",source,source,NameGroup) setElementData(resourceRoot,"Event"..NameGroup.."","Nenhuma") setElementData(resourceRoot,"Ruel"..NameGroup.."","Nenhuma") setElementData(resourceRoot,"General"..NameGroup.."",tostring(string.gsub(getPlayerName(source),"#%x%x%x%x%x%x",""))) setElementData(source,"NameGroup",tostring(NameGroup)) setElementData(source,"RankPlayer",tostring("General")) for _,plrs in ipairs (getElementsByType("player")) do getAllGroups(plrs) end else outputChatBox("#FF0000:#FFFFFF Você não pode usar esse nome .",source,255,0,0,true) end end) addEvent("UpGroups",true) addEventHandler("UpGroups",root,function() for _,plrs in ipairs (getElementsByType("player")) do getAllGroups(plrs) end setElementData(resourceRoot,"CountGroups",getCountGroups()) setElementData(resourceRoot,"CountMembers",getCountMembers()) end) addEvent("UpMembers",true) addEventHandler("UpMembers",root,function() for _,plrs in ipairs (getElementsByType("player")) do getAllMembers(plrs,getElementData(source,"NameGroup")) end setElementData(source,"OnlineInMyGroup",""..#getPlayersCountOnlineInMyGroup(source,getElementData(source,"NameGroup")).."") setElementData(source,"OfflineInMyGroup",""..#getPlayersCountOfflineInMyGroup(source,getElementData(source,"NameGroup")).."") end) addEvent("UpEvent",true) addEventHandler("UpEvent",root,function(eventText) local NameGroup = getElementData(source,"NameGroup") executeSQLQuery("UPDATE Groups_x22 SET Event=? WHERE NameGroup=?",tostring(eventText),tostring(NameGroup)) setElementData(resourceRoot,"Event"..NameGroup.."",tostring(eventText)) end) addEvent("UpRuel",true) addEventHandler("UpRuel",root,function(ruelText) local NameGroup = getElementData(source,"NameGroup") executeSQLQuery("UPDATE Groups_x22 SET Ruel=? WHERE NameGroup=?",tostring(ruelText),tostring(NameGroup)) setElementData(resourceRoot,"Ruel"..NameGroup.."",tostring(ruelText)) end) addEvent("InvitePlayer",true) addEventHandler("InvitePlayer",root,function(Account) if ( Account and Account ~= false and Account ~= nil and string.len(Account) >= 1 ) then local MyAcc = getElementData(source,"AccountName") if ( Account == MyAcc ) then outputChatBox("#FF0000:#FFFFFF Você não pode convidar você mesmo .",source,255,0,0,true) return end local NameGroup_ = getElementData(source,"NameGroup") local Row = executeSQLQuery("SELECT * FROM GrupsMembers_x22 WHERE Account=?",tostring(Account)) local Row_ = executeSQLQuery("SELECT * FROM GrupsInvite_x22 WHERE Account=?",tostring(Account)) for i,v in ipairs (Row_) do if ( v.NameGroup == NameGroup_ ) then outputChatBox("#FF0000:#FFFFFF Convite enviado, aguarde o jogador aceitar o convite .",source,255,0,0,true) return end end executeSQLQuery("INSERT INTO GrupsInvite_x22 (Account,Name,NameGroup) VALUES (?,?,?)",tostring(Account),tostring(string.gsub(getPlayerName(source),"#%x%x%x%x%x%x","")),tostring(NameGroup_)) outputChatBox("#FFFFFFConvite de Esquadrão enviado .",source,0,255,255,true) else outputChatBox("#FF0000:#FFFFFF Selecione o jogador .",source,255,0,0,true) end end) addEvent("ViewMyInvite",true) addEventHandler("ViewMyInvite",root,function() getAllInvites(source,getElementData(source,"AccountName")) end) addEvent("InviteAgre",true) addEventHandler("InviteAgre",root,function(nameGroup,acc,name) if ( nameGroup and nameGroup ~= false and nameGroup ~= nil and string.len(nameGroup) >= 3 ) then local Row = executeSQLQuery("SELECT * FROM Groups_x22 WHERE NameGroup=?",tostring(nameGroup)) if ( type(Row) == "table" and #Row == 0 or not Row ) then outputChatBox("#FF0000:#FFFFFF Esse esquadrão foi deletado ,( Não Encontrado ) .",source,255,0,0,true) return end if ( Row[1]["NameGroup"] == getElementData(source,"NameGroup") ) then outputChatBox("#FF0000:#FFFFFF Você já está no esquadrão .",source,255,0,0,true) return end local accountName = getElementData(source,"AccountName") executeSQLQuery("INSERT INTO GrupsMembers_x22 (Account,NameGroup,RankPlayer,State,Name) VALUES (?,?,?,?,?)",tostring(accountName),tostring(nameGroup),tostring("Soldado"),tostring("Online"),tostring(string.gsub(getPlayerName(source),"#%x%x%x%x%x%x",""))) executeSQLQuery("DELETE FROM GrupsInvite_x22 WHERE NameGroup =? AND Account=? AND Name=?",tostring(nameGroup),tostring(acc),tostring(name)) setElementData(source,"NameGroup",tostring(nameGroup)) setElementData(source,"RankPlayer",tostring("Soldado")) getAllInvites(source,accountName) end end) addEvent("DeletedMyInvite",true) addEventHandler("DeletedMyInvite",root,function(nameGroup,acc,name) if ( nameGroup and nameGroup ~= false and nameGroup ~= nil and string.len(nameGroup) >= 3 ) then executeSQLQuery("DELETE FROM GrupsInvite_x22 WHERE NameGroup =? AND Account=? AND Name=?",tostring(nameGroup),tostring(acc),tostring(name)) getAllInvites(source,getElementData(source,"AccountName")) end end) addEvent("GiveRank",true) addEventHandler("GiveRank",root,function(acc,GiveRank) if ( acc and acc ~= false and acc ~= nil and type(acc) == "string" and string.len(acc) >= 1 and GiveRank ) then local Row = executeSQLQuery("SELECT * FROM GrupsMembers_x22 WHERE Account=?",tostring(acc)) local MyRank = getElementData(source,"RankPlayer") local MyAcc = getElementData(source,"AccountName") if ( type(Row) == "table" and #Row == 0 or not Row ) then outputChatBox("#FF0000:#FFFFFF Nenhum jogador encontrado no esquadrão .",source,255,0,0,true) else local PlayerToGiveRank = Row[1]["RankPlayer"] if ( acc == MyAcc ) then outputChatBox("#FF0000:#FFFFFF Você não pode promover você mesmo .",source,255,0,0,true) return end if ( MyRank == "Tenente" or MyRank == "Soldado" ) then outputChatBox("#FF0000:#FFFFFF Você não pode promover .",source,255,0,0,true) return end if ( MyRank == "Major" and GiveRank ~= "Tenente" and PlayerToGiveRank ~= "Soldado" ) then outputChatBox("#FF0000:#FFFFFF Você só pode dar membros .",source,255,0,0,true) return end if ( MyRank == "Coronel" and GiveRank == "General" ) then outputChatBox("#FF0000:#FFFFFF Você só pode dar owner .",source,255,0,0,true) return end if ( MyRank == "Coronel" and PlayerToGiveRank == "General" ) then outputChatBox("#FF0000:#FFFFFF Você não pode promover para owner .",source,255,0,0,true) return end executeSQLQuery("UPDATE GrupsMembers_x22 SET RankPlayer=? WHERE Account=?",tostring(GiveRank),tostring(acc)) outputChatBox("#FFFFFFCargo alterado .",source,0,255,255,true) getAllMembers(source,getElementData(source,"NameGroup")) local plr = getPlayerFromAccount(acc) if not( plr ) then return end setElementData(plr,"RankPlayer",tostring(rank)) end else outputChatBox("#FF0000:#FFFFFF bad argument acc&rank .",source,255,0,0,true) end end) addEvent("GetKick",true) addEventHandler("GetKick",root,function(acc) if ( acc and acc ~= false and acc ~= nil and type(acc) == "string" and string.len(acc) >= 1 ) then local Row = executeSQLQuery("SELECT * FROM GrupsMembers_x22 WHERE Account=?",tostring(acc)) Link to comment
ALw7sH Posted July 23, 2016 Share Posted July 23, 2016 What didn't worked exactly? debugscript 3 and see the errors Link to comment
veigac4tm Posted July 23, 2016 Author Share Posted July 23, 2016 What didn't worked exactly? debugscript 3 and see the errors So friend, I want to do the following: I want to create a chat for those who are in the same group understand? A teamchat only for the members of their respective groups. Most do not know why it does not work! 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