Davidchecker Posted June 22, 2020 Posted June 22, 2020 Hello, i want to create a player chat for different teams. What is the best way? My Currnt style does not work mp.events.add("policeoutfit2", (player) =>{//Police player.model = "s_m_y_swat_01"; player.call("CloseSkinAuswahl") player.setVariable('fraktion', 5) //VARIABLE FOR CHAT spawn(player); }); mp.events.add("playerChat" , (player, message) => { if(player.getVariable('fraktion') == 5)//police //TypeError: Cannot read property 'getVariable' of undefined { player.data.ChatColor = [255, 255, 255]; } let PlayerColor = player.data.ChatColor; mp.players.broadcast("!{"+PlayerColor+"}"+player.name+"["+player.id+"]!{#FFFFFF}: "+message); // send player message });
Division Posted June 22, 2020 Posted June 22, 2020 (edited) you need to loop all players and send everyone a message if he also is fraktion==5 Edited June 22, 2020 by Division
mZentorno Posted June 23, 2020 Posted June 23, 2020 (edited) const teamData = { Team1 : "#ff0000", Team2 : "#0000ff" } const white = "#FFFFFF" mp.events.add('changeTeam', (player, newTeam) => { player.data.currentTeam = newTeam player.data.colorTeam = teamData[player.data.currentTeam] }) mp.events.add("playerChat" , (player, message) => { mp.players.broadcast(`!{${player.data.colorTeam}} ${player.name} [${player.id}]: !{${white}}${message}`) }) this is a model of an implementation that I use, use the way you want do you want or chat to appear for everyone, or just for your team? Edited June 23, 2020 by mZentorno
Davidchecker Posted June 25, 2020 Author Posted June 25, 2020 First i try to create a global chat with the different team colors. Then i want to create an internal chat for each team. How can i call it? mp.events.call("changeTeam", "Team1"); ? I have an Error TypeError: Cannot set property 'currentTeam' of undefined player.data.currentTeam = newTeam;
mZentorno Posted June 25, 2020 Posted June 25, 2020 (edited) playerJoin event: player.data = {} for chat team: make use of any symbol at the beginning of the message, example !: playerChat event: if (message[0] == '!'){ message = message.slice(1) mp.players.forEach(p => { if(p.data.currentTeam == player.data.currentTeam){ p.outputChatBox(message) } }) } and call the event changeTeam with any command and use mp.events.call('changeTeam', (player, 'Team1')) I wrote this with my cellphone, this is just a way, it shouldn't be 100% right. Visit the wiki Edited June 25, 2020 by mZentorno
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