Author Topic: Private Messages for players [updated]  (Read 5239 times)

0 Members and 1 Guest are viewing this topic.

Offline freestyler

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 326
Private Messages for players [updated]
« on: August 14, 2007, 05:57:22 pm »
Script Name: Private Messages for players

Script Description: Soldat has private message thing implemented, but it's for admins only. This script allows every player to send private messages. It has also ignoring function, which mutes PMs from specified player.

Update:
Updated version of this script allows you to send PMs directly to TCP Admins (admins connected to server via client like ESA, ARSSE etc.)! Admins can use PMs aswell. You can also modify colors of messages - just modify constants (thanks to zyxstand for this idea).

Usage:
/pm X message - sends private message to player X
/pm admin message - sends private message to TCP Admin
/mutepm X - mutes PMs from player X
/unmutepm X - unmutes PMs from player X

Original Author(s): fri_ (inspired by DorkeyDear's Colored Admin Messages script)

Core Version: 2.6.2

Code: [Select]
const
  COLOR_PM_MSG    = $FF8888FF;  // color of private message
  COLOR_PM_OK     = $FF88FF88;  // color of "unmuted" and "msg sent"
  COLOR_PM_ERROR  = $FFFF8888;  // color of "muted", "not sent" and "player doesn't exist"
  COLOR_PM_SERVER = $FF8888FF;  // color of PM from TCP Admin

var
  i, idpm: integer;
  playerpm: string;
  mutepm: array[1..32] of array[1..32] of boolean;

procedure ActivateServer();
begin
  for i := 1 to 32 do mutepm[i][i] := false;
end;

function OnCommand(ID: Byte; Text: string): boolean;
begin
  if GetPiece(Text,' ',0) = '/pm' then begin
    Result := true;
    if ID = 255 then begin
      playerpm := 'SERVER';
      idpm := strtoint(GetPiece(Text, ' ', 1));
      if GetPlayerStat(idpm, 'Active') then begin
        WriteConsole(idpm, '[PM] [' + playerpm + ']' + Copy(Text, Length(GetPiece(Text, ' ', 1)) + 5, Length(Text)), COLOR_PM_SERVER);
        WriteLn('Private message sent to ' + IDToName(idpm));
      end else WriteLn('Error: player #' + (GetPiece(Text, ' ', 1)) + ' doesn`t exist.');
    end;
  end;     
end;

function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin
  if GetPiece(Text, ' ', 0) = '/mutepm' then begin
    idpm := strtoint(GetPiece(Text, ' ', 1));
    if GetPlayerStat(idpm, 'Active') = true then begin
      mutepm[ID][idpm] := true;
      WriteConsole(ID, 'Private Meggages from ' + IDToName(idpm) + ' muted.', COLOR_PM_ERROR);
    end else WriteConsole(ID, 'Error: player #' + (GetPiece(Text, ' ', 1)) + ' doesn`t exist.', COLOR_PM_ERROR);
  end else if GetPiece(Text, ' ', 0) = '/unmutepm' then begin
    idpm := strtoint(GetPiece(Text, ' ', 1));
    if GetPlayerStat(idpm, 'Active') = true then begin
      mutepm[ID][idpm] := false;
      WriteConsole(ID, 'Private Meggages from ' + IDToName(idpm) + ' unmuted.', COLOR_PM_OK);
    end else WriteConsole(ID, 'Error: player #' + (GetPiece(Text, ' ', 1)) + ' doesn`t exist.', COLOR_PM_ERROR);
  end;

  if GetPiece(Text, ' ', 0) = '/pm' then begin
    Result := true;
    playerpm := GetPlayerStat(ID, 'Name');
    if GetPiece(Text, ' ', 1) = 'admin' then begin
      WriteLn('[PM] [' + playerpm + '] ' + Copy(Text, StrPos(GetPiece(Text, ' ', 1), Text) + 5, Length(Text)));
      WriteConsole(ID, 'Private message sent to TCP Admin', COLOR_PM_OK);
    end else begin
      idpm := strtoint(GetPiece(Text, ' ', 1));
      if GetPlayerStat(idpm, 'Active') = true then begin
        if mutepm[idpm][ID] = true then begin
          WriteConsole(ID, 'Message NOT sent, ' + IDToName(idpm) + ' has muted your PMs.', COLOR_PM_ERROR);
        end else begin
          WriteConsole(idpm, '[PM] [' + playerpm + ']' + Copy(Text, Length(GetPiece(Text, ' ', 1)) + 5, Length(Text)), COLOR_PM_MSG);
          WriteConsole(ID, 'Private message sent to ' + IDToName(idpm), COLOR_PM_OK);
        end;
      end else WriteConsole(ID, 'Error: player #' + (GetPiece(Text, ' ', 1)) + ' doesn`t exist.', COLOR_PM_ERROR);
    end;
  end;
end;

procedure OnLeaveGame(ID, Team: byte; Kicked: boolean);
begin
  for i := 1 to 32 do begin
    mutepm[i][ID] := false;
    mutepm[ID][i] := false;
  end;
end;


« Last Edit: May 10, 2014, 12:38:27 pm by freestyler »

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Private Messages for players
« Reply #1 on: August 14, 2007, 06:41:43 pm »
cool,
looks well-made and tested.
Another one of those lovely mini-scripts all servers should have.
Might I suggest to define a constant:  MSG = $FFFF8888; and use MSG insead of $FFFF8888 everywhere*
Not necessary to change it now but just for future references...
I see the server itself can send messages lol.  But how can the server ever call the OnPlayerCommand???
Can't think of anything original to put here...

Offline mikembm

  • Soldier
  • **
  • Posts: 210
Re: Private Messages for players
« Reply #2 on: August 14, 2007, 06:43:39 pm »
The loop in ActivateServer isn't needed because they will all be false by default.

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Private Messages for players
« Reply #3 on: August 14, 2007, 06:52:05 pm »
It's good practice to do that mikembm.  It may not be necessary in pascal but it definitely is in vritually all other languages.  What if an admin wants to recompile the script?
Can't think of anything original to put here...

Offline mikembm

  • Soldier
  • **
  • Posts: 210
Re: Private Messages for players
« Reply #4 on: August 14, 2007, 09:09:10 pm »
It's good practice to do that mikembm.  It may not be necessary in pascal but it definitely is in vritually all other languages.  What if an admin wants to recompile the script?

I'm pretty sure recompiling will also set them back to false.
You may think it's good practice, but I think including code which does absolutely nothing isn't.
And as far as other languages go, I'm pretty sure they all have default values as well...
« Last Edit: August 14, 2007, 09:11:20 pm by mikembm »

Offline Ttil_Np.csWoW

  • Major
  • *
  • Posts: 55
  • The Berserkers Are Coming....
Re: Private Messages for players
« Reply #5 on: August 14, 2007, 10:34:21 pm »
I like it alot :) well done
I will be back to play soldat, just not now , but i will....... some day.

Offline chrisgbk

  • Moderator
  • Veteran
  • *****
  • Posts: 1739
Re: Private Messages for players
« Reply #6 on: August 14, 2007, 11:31:59 pm »
It's good practice to do that mikembm.  It may not be necessary in pascal but it definitely is in vritually all other languages.  What if an admin wants to recompile the script?

I'm pretty sure recompiling will also set them back to false.
You may think it's good practice, but I think including code which does absolutely nothing isn't.
And as far as other languages go, I'm pretty sure they all have default values as well...

Pascal and Delphi are actually exceptions to this, they do not have default values. When you name a variable, whatever is in the memory it gets assigned to is what value it starts with.

You have to explicitly declare any default values yourself.

Offline ghg

  • Camper
  • ***
  • Posts: 411
  • Village Idiot
Re: Private Messages for players
« Reply #7 on: August 15, 2007, 05:09:14 am »
Argh. I tried this once, failed horribly. I was using RegExp to try and break off bits of the string.
-=Gradius wuz you=-

Offline freestyler

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 326
Re: Private Messages for players [updated]
« Reply #8 on: August 16, 2007, 03:02:09 pm »
Script updated again... I fixed sending PMs to TCP admins, it was buggy, but it works perfectly now.
« Last Edit: August 16, 2007, 03:03:42 pm by freestyler »

Offline Mr Bunny

  • Major(1)
  • Posts: 8
  • You've Been Bunnified
Re: Private Messages for players [updated]
« Reply #9 on: August 16, 2007, 03:22:13 pm »
Sounds really handy =D
I am the Bunny
xfire: funkylemon
ADD ME =DD

Offline JotEmI

  • Soldier
  • **
  • Posts: 188
Re: Private Messages for players [updated]
« Reply #10 on: November 19, 2008, 02:59:25 pm »
Yeah great but this one's only sending first word of the message. You'd have to write whole text without spaces between words. I tried to solve it but all my attempts have failed.

Offline Polifen

  • Soldier
  • **
  • Posts: 127
Re: Private Messages for players [updated]
« Reply #11 on: November 20, 2008, 03:07:50 am »
Maybe you should use GetPiece(Text, ',', 1) function? Then players could use /PM,ID,Message and it ll send all message. And others suggestion: use lowercase(GetPiece(Text, ',', 0) = '/pm', then command will work even when player ll write '/PM'.

Sorry for my bad English.

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Private Messages for players [updated]
« Reply #12 on: November 20, 2008, 06:51:56 am »
Maybe you should use GetPiece(Text, ',', 1) function? Then players could use /PM,ID,Message and it ll send all message. And others suggestion: use lowercase(GetPiece(Text, ',', 0) = '/pm', then command will work even when player ll write '/PM'.
Using ',' instead of space will only confuse players, Copy is good.

Offline Polifen

  • Soldier
  • **
  • Posts: 127
Re: Private Messages for players [updated]
« Reply #13 on: November 23, 2008, 05:20:34 am »
It's not good if it's not working properly... it don't have to be "," it can be "|" or anything other, "," was only example.

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: Private Messages for players [updated]
« Reply #14 on: November 23, 2008, 10:11:04 am »
i have no idea how you guys are using this so that it doesnt work, it works for me perfectly well