Jump to content
RAGE Multiplayer Community

Recommended Posts

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


});

Link to post
Share on other sites
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 by mZentorno
Link to post
Share on other sites

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;

Link to post
Share on other sites

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 by mZentorno
Link to post
Share on other sites

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