Help How can I show the profession of the player in the chat?

Started by Kelvinvenema, Sep 26, 2020, 05:57 PM

Previous topic - Next topic

Kelvinvenema

Hello guys I have run into some problems. I recently made a command EmergencyChat for my roleplay server. But the thing is I would like it to show what profession everybody has For example to visualize it:

EmergencyChat: Firefighter: TheKiller01:  "Message"
EmergencyChat: Police: Theweirdguy1:  "Message"
EmergencyChat: Paramedic: Niceman: "Message"

The code down here has something called + "Profession" +
The line with Profession should give the player the string with the Profession that depends on their Job if they are FireFighter the command should output firefighter.

I can't seem to work out how I should do it,
I really appreciate if you could help,

Code:

for( local i = 0; i <= GetMaxPlayers(); i++ )
{
plr = FindPlayer( i );
if ( ( plr ) && ( plr.Skin ==1 || 5 || 6) )
{
MessagePlayer("[#A42F2B][Emergency-Chat] " +Profession+" "+player.Name+  ":[#0CF4D4]  " + text + "", plr);

Kelvin Garcia Mendoza

you could do something like this:

playerProfession <- array( GetMaxPlayers(), 0 ); // 0 for no profession.

function getPlayerProfessionName( player )
{
 switch( playerProfession[ player.ID ] )
 {
  case 1:
   return "Police Officer";

  case 2:
   return "Firefighter";

  case 3:
   return "Paramedic";
 }

 return "Citizen";
}

function onPlayerChat( player, message )
{
 Message( format( "[%s] %s: %s", getPlayerProfessionName( player ), player.Name, message ) );

 return 0;
}

function onPlayerPart( player, reason )
{
 playerProfession[ player.ID ] = 0;
}


all you have to do is to assign players a profession anytime using:
playerProfession[ player ID ] = profession ID;
for example:
function onPlayerCommand( player, command, arguments )
{
 if ( command == "cop" )
 {
  playerProfession[ player.ID ] = 1;

  PrivMessage( player, "You are now a Police Officer!" );
 }
}

Kelvinvenema

Quote from: [ss]keLvin_ on Sep 26, 2020, 10:15 PMyou could do something like this:

playerProfession <- array( GetMaxPlayers(), 0 ); // 0 for no profession.

function getPlayerProfessionName( player )
{
 switch( playerProfession[ player.ID ] )
 {
  case 1:
   return "Police Officer";

  case 2:
   return "Firefighter";

  case 3:
   return "Paramedic";
 }

 return "Citizen";
}

function onPlayerChat( player, message )
{
 Message( format( "[%s] %s: %s", getPlayerProfessionName( player ), player.Name, message ) );

 return 0;
}

function onPlayerPart( player, reason )
{
 playerProfession[ player.ID ] = 0;
}


all you have to do is to assign players a profession anytime using:
playerProfession[ player ID ] = profession ID;
for example:
function onPlayerCommand( player, command, arguments )
{
 if ( command == "cop" )
 {
  playerProfession[ player.ID ] = 1;

  PrivMessage( player, "You are now a Police Officer!" );
 }
}


Your code doesn't seem to work if
error:

AN ERROR HAS OCCURED [the index 'message' does not exist]

CALLSTACK
*FUNCTION [onPlayerChat()] scripts/main.nut line [337]

LOCALS
[text] "32"
[player] INSTANCE
[this] TABLE


and my privatechat for Emergency services doesn't seem to work it doesn't give an error that is pretty weird when I remove the getplayerprofession it works fine but it doesn't show the profession.

MessagePlayer("[#A42F2B][Emergency-Chat] " +getplayerProfession+ " "+player.Name+  ":[#0CF4D4]  " + text + "", plr);

Xhefri

Quote from: Kelvinvenema on Sep 27, 2020, 06:42 AM
Quote from: [ss]keLvin_ on Sep 26, 2020, 10:15 PMyou could do something like this:

playerProfession <- array( GetMaxPlayers(), 0 ); // 0 for no profession.

function getPlayerProfessionName( player )
{
 switch( playerProfession[ player.ID ] )
 {
  case 1:
   return "Police Officer";

  case 2:
   return "Firefighter";

  case 3:
   return "Paramedic";
 }

 return "Citizen";
}

function onPlayerChat( player, message )
{
 Message( format( "[%s] %s: %s", getPlayerProfessionName( player ), player.Name, message ) );

 return 0;
}

function onPlayerPart( player, reason )
{
 playerProfession[ player.ID ] = 0;
}


all you have to do is to assign players a profession anytime using:
playerProfession[ player ID ] = profession ID;
for example:
function onPlayerCommand( player, command, arguments )
{
 if ( command == "cop" )
 {
  playerProfession[ player.ID ] = 1;

  PrivMessage( player, "You are now a Police Officer!" );
 }
}


Your code doesn't seem to work if
error:

AN ERROR HAS OCCURED [the index 'message' does not exist]

CALLSTACK
*FUNCTION [onPlayerChat()] scripts/main.nut line [337]

LOCALS
[text] "32"
[player] INSTANCE
[this] TABLE


and my privatechat for Emergency services doesn't seem to work it doesn't give an error that is pretty weird when I remove the getplayerprofession it works fine but it doesn't show the profession.

MessagePlayer("[#A42F2B][Emergency-Chat] " +getplayerProfession+ " "+player.Name+  ":[#0CF4D4]  " + text + "", plr);
Hey Kelvin, nice to see you back ;). Maybe you are using TEXT instead of MESSAGE on your playerchat function so try switching that. You can either switch it from text to message on the function or change it from message to text in the line he provided, if thats the case why you are getting the error.