Advertisement
Bendarr

PrivateMessages

Jan 2nd, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.27 KB | None | 0 0
  1. const
  2. PMColor = $FF0FA0C6;
  3. PMColor2 = $FF9C9F9F;
  4. ErrorColor = $FFBF7F7F;
  5.  
  6. var
  7. HighestID: byte;
  8. SlotIDPM, NameCountPM, NamePieceInt: integer;
  9. IgnorePM: array[1..32] of array[1..32] of boolean;
  10. NamePiecePM, PhrasePM: string;
  11. Trigger: boolean;
  12.  
  13. function StrrPos(const Substr, S: string): integer;
  14. begin
  15.    for Result := Length(S) - Length(Substr) + 1 downto 1 do
  16.    if (Copy(S, Result, Length(Substr)) = Substr) then
  17.      exit;
  18.    Result := 0;
  19. end;
  20.  
  21. procedure Say(const Id: byte; const Text: string; const Color: longint);
  22. var
  23.    Pos: integer;
  24. begin
  25.    if (Length(Text) <= 72) then
  26.      WriteConsole(Id, Text, Color)
  27.    else begin
  28.    Pos := StrrPos(' ', Copy(Text, 1, 72));
  29.    if (Pos = 0) then begin
  30.      Pos := 72;
  31.    WriteConsole(Id, Copy(Text, 1, 72), Color);
  32. end else
  33. WriteConsole(Id, Copy(Text, 1, Pos - 1), Color);
  34. Say(Id, Copy(Text, Pos + 1, Length(Text)), Color);
  35. end;
  36. end;
  37.  
  38. Procedure SetHighestID();
  39. var
  40.    i: byte;
  41. begin
  42.    for i := 1 to 32 do
  43.    if (HighestID < i) then
  44.    if (GetPlayerStat(i, 'Active') = true) then
  45.    HighestID := i
  46. end;
  47.  
  48. procedure CountPM();
  49. var
  50.    i: byte;
  51. begin
  52.    for i := 1 to HighestID do
  53.      if (ContainsString(LowerCase(GetPlayerStat(i, 'Name')), LowerCase(NamePiecePM))) then begin
  54.      NameCountPM := NameCountPM + 1
  55.      SlotIDPM := i
  56. end;
  57. end;
  58.  
  59. function OnCommand(Id: byte; Text: string): boolean;
  60. begin
  61. if (LowerCase(GetPiece(Text, ' ', 0)) = '/pm') then begin
  62. Result := true;
  63. if Id = 255 then begin
  64. if (ContainsString(Text, ' ')) then begin
  65. NamePiecePM := GetPiece(Text, ' ', 1)
  66. PhrasePM := Copy(Text, StrPos(NamePiecePM, Text) + Length(NamePiecePM) + 1, Length(Text))
  67. NameCountPM := 0
  68. SlotIDPM := 0
  69. Trigger := false
  70.  
  71. try
  72. NamePieceInt := StrToInt(NamePiecePM);
  73. if GetPlayerStat(NamePieceInt, 'Active') = true then begin
  74. Trigger := true;
  75. NameCountPM := 1;  
  76. SlotIDPM := NamePieceInt;
  77. end;
  78. except
  79. Trigger := false
  80. end;
  81.  
  82. if Trigger = false then begin
  83. CountPM();
  84. end;
  85.  
  86. if NameCountPM = 1 then begin
  87. Say(SlotIDPM, '[SERVER PM]' + ' ' + PhrasePM, PMColor)
  88. WriteLn('PM To: [' + GetPlayerStat(SlotIDPM, 'Name') + ']' + ' ' + PhrasePM);
  89. end;
  90. if NameCountPM = 0 then begin
  91. WriteLn('Phrase' + ' "' + NamePiecePM + '" ' + 'was not found, please be more specific or use the players slot number (1-32)');
  92. end;
  93. if NameCountPM > 1 then begin
  94. WriteLn('Phrase' + ' "' + NamePiecePM + '" ' + 'returned too many different players, please be more specific or use the players slot number (1-32)');
  95. end
  96. end
  97. end
  98. end
  99. end;
  100.  
  101. function OnPlayerCommand(Id: byte; Text: string): boolean;
  102. var
  103.    i: byte;
  104. begin
  105.  
  106. if (LowerCase(GetPiece(Text, ' ', 0)) = '/pm') or (LowerCase(GetPiece(Text, ' ', 0)) = '/ignore') or (LowerCase(GetPiece(Text, ' ', 0)) = '/unignore') then begin
  107. if (ContainsString(Text, ' ')) then begin
  108. NamePiecePM := GetPiece(Text, ' ', 1)
  109. PhrasePM := Copy(Text, StrPos(NamePiecePM, Text) + Length(NamePiecePM) + 1, Length(Text))
  110. NameCountPM := 0
  111. SlotIDPM := 0
  112. Trigger := false
  113.  
  114. try
  115. NamePieceInt := StrToInt(NamePiecePM);
  116. if GetPlayerStat(NamePieceInt, 'Active') = true then begin
  117. Trigger := true;
  118. NameCountPM := 1;  
  119. SlotIDPM := NamePieceInt;
  120. end;
  121. except
  122. Trigger := false
  123. end;
  124.  
  125. if (LowerCase(NamePiecePM) = 'server') or (LowerCase(NamePiecePM) = 'admin') then begin
  126. Trigger := true
  127. NameCountPM := 69;
  128. end;
  129.  
  130. if (Trigger = false) then begin
  131. CountPM();
  132. end;
  133.  
  134. if (LowerCase(GetPiece(Text, ' ', 0)) = '/pm') then begin
  135.  
  136. if NameCountPM = 0 then begin
  137. Say(Id, 'Phrase' + ' "' + NamePiecePM + '" ' + 'was not found, please be more specific or use the players slot number (1-32)', ErrorColor)
  138. exit;
  139. end;
  140. if (NameCountPM > 1) and (NameCountPM < 69) then begin
  141. Say(Id, 'Phrase' + ' "' + NamePiecePM + '" ' + 'returned too many different players, please be more specific or use the players slot number (1-32)', ErrorColor)
  142. exit;
  143. end;
  144. if NameCountPM = 69 then begin
  145. Say(Id, 'PM Sent To Admin:' + ' ' + PhrasePM, PMColor2)
  146. WriteLn('!admin')
  147. WriteLn('PM' + ' ' + 'From:' + ' [' +  GetPlayerStat(Id, 'Name') + '] ' + 'To: [SERVER ADMIN]' + ' ' + PhrasePM);
  148. exit;
  149. end;
  150.  
  151. if (NameCountPM = 1) and (IgnorePM[SlotIDPM][Id] = true) then begin
  152. NameCountPM := 70;
  153. end;
  154.  
  155. if NameCountPM = 1 then begin
  156. Say(SlotIDPM, '[PM] [' + GetPlayerStat(Id, 'Name') + ']' + ' ' + PhrasePM, PMColor)
  157. Say(Id, 'PM To: [' + GetPlayerStat(SlotIDPM, 'Name') + ']' + ' ' + PhrasePM, PMColor2)
  158. WriteLn('PM' + ' ' + 'From' + ' [' +  GetPlayerStat(Id, 'Name') + '] ' + 'To: [' + GetPlayerStat(SlotIDPM, 'Name') + ']' + ' ' + PhrasePM);
  159. exit;
  160. end;
  161.  
  162. if NameCountPM = 70 then begin
  163. WriteConsole(Id, GetPlayerStat(SlotIDPM, 'Name') + ' ' + 'has muted your Private Messages', ErrorColor)
  164. exit;
  165. end
  166. end;
  167. end;
  168.  
  169. if (LowerCase(GetPiece(Text, ' ', 0)) = '/ignore') then begin
  170.  
  171. if NameCountPM = 1 then begin
  172. IgnorePM[Id][SlotIDPM] := true;
  173. WriteConsole(SlotIDPM, GetPlayerStat(Id, 'Name') + ' ' + 'has muted your Private Messages', ErrorColor);
  174. Say(Id, 'You have muted Private Messages from' + ' ' + GetPlayerStat(SlotIDPM, 'Name') + ' ' + '(to get private messages again from this player use /unignore)', ErrorColor)
  175. WriteLn(GetPlayerStat(Id, 'Name') + ' ' + 'has muted Private Messages from' + ' ' + GetPlayerStat(SlotIDPM, 'Name'));
  176. exit;
  177. end;
  178.  
  179. if NameCountPM = 0 then begin
  180. Say(Id, 'Phrase' + ' "' + NamePiecePM + '" ' + 'was not found, please be more specific or use the players slot number (1-32)', ErrorColor)
  181. exit;
  182. end;
  183. if NameCountPM > 1 then begin
  184. Say(Id, 'Phrase' + ' "' + NamePiecePM + '" ' + 'returned too many different players, please be more specific or use the players slot number (1-32)', ErrorColor)
  185. exit;
  186. end;
  187. end;
  188.  
  189. if (LowerCase(GetPiece(Text, ' ', 0)) = '/unignore') then begin
  190.  
  191. if NameCountPM = 1 then begin
  192. IgnorePM[Id][SlotIDPM] := false;
  193. WriteConsole(SlotIDPM, GetPlayerStat(Id, 'Name') + ' ' + 'has unmuted your Private Messages', ErrorColor)
  194. Say(Id, 'You have unmuted Private Messages from' + ' ' + GetPlayerStat(SlotIDPM, 'Name'), ErrorColor)
  195. WriteLn(GetPlayerStat(Id, 'Name') + ' ' + 'has unmuted Private Messages from' + ' ' + GetPlayerStat(SlotIDPM, 'Name'));
  196. exit;
  197. end;
  198.  
  199. if NameCountPM = 0 then begin
  200. Say(Id, 'Phrase' + ' "' + NamePiecePM + '" ' + 'was not found, please be more specific or use the players slot number (1-32)', ErrorColor)
  201. exit;
  202. end;
  203. if NameCountPM > 1 then begin
  204. Say(Id, 'Phrase' + ' "' + NamePiecePM + '" ' + 'returned too many different players, please be more specific or use the players slot number (1-32)', ErrorColor)
  205. exit;
  206. end
  207. end
  208. end;
  209. //
  210.  
  211. if (LowerCase(Text) = '/ignoreall') then begin
  212. for i := 1 to 32 do IgnorePM[Id][i] := true;
  213. WriteConsole(Id, 'You have muted all Private Messages, to undo this type /unignoreall', ErrorColor);
  214. end;
  215. if (LowerCase(Text) = '/unignoreall') then begin
  216. for i := 1 to 32 do IgnorePM[Id][i] := false;
  217. WriteConsole(Id, 'You have unmuted all Private Messages', ErrorColor);
  218. end;
  219.  
  220. //
  221.  
  222. end;
  223.  
  224. procedure OnJoinGame(Id, Team: byte);
  225. begin
  226. HighestID := 1
  227. SetHighestID();
  228. end;
  229.  
  230. procedure OnLeaveGame(Id, Team: byte; Kicked: boolean);
  231. var i: byte;
  232. begin
  233.  
  234. for i := 1 to 32 do begin
  235. IgnorePM[i][Id] := false;
  236. IgnorePM[Id][i] := false;
  237. end;
  238.  
  239. if Id = HighestID then begin
  240. HighestID := 1
  241. SetHighestID();
  242. end;
  243. end;
  244.  
  245. procedure ActivateServer();
  246. var i, j: byte;
  247. begin
  248. SetHighestID();
  249.   for i := 1 to 32 do for j := 1 to 32 do IgnorePM[i][j] := false;
  250. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement