Advertisement
Bendarr

PrivateMessages110

Feb 29th, 2012
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.87 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.    StoreText: string;
  52. begin
  53.    for i := 1 to HighestID do begin
  54.    
  55.         if LowerCase(GetPlayerStat(i, 'Name')) = LowerCase(NamePiecePM) then begin
  56.      NameCountPM := 1
  57.      SlotIDPM := i
  58.      exit;
  59.      end;
  60.      
  61.      if ContainsString(LowerCase(NamePiecePM) + ' ' + LowerCase(PhrasePM), LowerCase(GetPlayerStat(i, 'Name'))) then begin
  62.           NameCountPM := 1
  63.      SlotIDPM := i
  64.      StoreText := NamePiecePM + ' ' + PhrasePM
  65.      NamePiecePM := Copy(StoreText, 1, Length(GetPlayerStat(i, 'Name')))
  66.      PhrasePM := Copy(StoreText, Length(GetPlayerStat(i, 'Name')) + 2, Length(StoreText))
  67.      exit;
  68.      end;
  69.      
  70.      if (ContainsString(LowerCase(GetPlayerStat(i, 'Name')), LowerCase(NamePiecePM))) then begin
  71.      NameCountPM := NameCountPM + 1
  72.      SlotIDPM := i
  73.      end;
  74. end;
  75. end;
  76.  
  77. function OnCommand(Id: byte; Text: string): boolean;
  78. begin
  79. if (LowerCase(GetPiece(Text, ' ', 0)) = '/pm') then begin
  80. Result := true;
  81. if Id = 255 then begin
  82. if (ContainsString(Text, ' ')) then begin
  83. NamePiecePM := GetPiece(Text, ' ', 1)
  84. PhrasePM := Copy(Text, StrPos(NamePiecePM, Text) + Length(NamePiecePM) + 1, Length(Text))
  85. NameCountPM := 0
  86. SlotIDPM := 0
  87. Trigger := false
  88.  
  89. try
  90. NamePieceInt := StrToInt(NamePiecePM);
  91. if GetPlayerStat(NamePieceInt, 'Active') = true then begin
  92. Trigger := true;
  93. NameCountPM := 1;  
  94. SlotIDPM := NamePieceInt;
  95. end;
  96. except
  97. Trigger := false
  98. end;
  99.  
  100. if Trigger = false then begin
  101. CountPM();
  102. end;
  103.  
  104. if NameCountPM = 1 then begin
  105. Say(SlotIDPM, '[SERVER PM]' + ' ' + PhrasePM, PMColor)
  106. WriteLn('PM To: [' + GetPlayerStat(SlotIDPM, 'Name') + ']' + ' ' + PhrasePM);
  107. end;
  108. if NameCountPM = 0 then begin
  109. WriteLn('Phrase' + ' "' + NamePiecePM + '" ' + 'was not found, please be more specific or use the players slot number (1-32)');
  110. end;
  111. if NameCountPM > 1 then begin
  112. WriteLn('Phrase' + ' "' + NamePiecePM + '" ' + 'returned too many different players, please be more specific or use the players slot number (1-32)');
  113. end
  114. end
  115. end
  116. end
  117. end;
  118.  
  119. function OnPlayerCommand(Id: byte; Text: string): boolean;
  120. var
  121.    i: byte;
  122. begin
  123.  
  124. if (LowerCase(GetPiece(Text, ' ', 0)) = '/pm') or (LowerCase(GetPiece(Text, ' ', 0)) = '/ignore') or (LowerCase(GetPiece(Text, ' ', 0)) = '/unignore') then begin
  125. if (ContainsString(Text, ' ')) then begin
  126. NamePiecePM := GetPiece(Text, ' ', 1)
  127. PhrasePM := Copy(Text, StrPos(NamePiecePM, Text) + Length(NamePiecePM) + 1, Length(Text))
  128.  
  129. NameCountPM := 0
  130. SlotIDPM := 0
  131. Trigger := false
  132.  
  133. try
  134. NamePieceInt := StrToInt(NamePiecePM);
  135. if GetPlayerStat(NamePieceInt, 'Active') = true then begin
  136. Trigger := true;
  137. NameCountPM := 1;  
  138. SlotIDPM := NamePieceInt;
  139. end;
  140. except
  141. Trigger := false
  142. end;
  143.  
  144. if (LowerCase(NamePiecePM) = 'server') or (LowerCase(NamePiecePM) = 'admin') then begin
  145. Trigger := true
  146. NameCountPM := 69;
  147. end;
  148.  
  149. if (Trigger = false) then begin
  150. CountPM();
  151. end;
  152.  
  153. if (LowerCase(GetPiece(Text, ' ', 0)) = '/pm') then begin
  154.  
  155. if NameCountPM = 0 then begin
  156. Say(Id, 'Phrase' + ' "' + NamePiecePM + '" ' + 'was not found, please be more specific or use the players slot number (1-32)', ErrorColor)
  157. exit;
  158. end;
  159. if (NameCountPM > 1) and (NameCountPM < 69) then begin
  160. Say(Id, 'Phrase' + ' "' + NamePiecePM + '" ' + 'returned too many different players, please be more specific or use the players slot number (1-32)', ErrorColor)
  161. exit;
  162. end;
  163. if NameCountPM = 69 then begin
  164. Say(Id, 'PM Sent To Admin:' + ' ' + PhrasePM, PMColor2)
  165. WriteLn('!admin')
  166. WriteLn('PM' + ' ' + 'From:' + ' [' +  GetPlayerStat(Id, 'Name') + '] ' + 'To: [SERVER ADMIN]' + ' ' + PhrasePM);
  167. exit;
  168. end;
  169.  
  170. if (NameCountPM = 1) and (IgnorePM[SlotIDPM][Id] = true) then begin
  171. NameCountPM := 70;
  172. end;
  173.  
  174. if NameCountPM = 1 then begin
  175. Say(SlotIDPM, '[PM] [' + GetPlayerStat(Id, 'Name') + ']' + ' ' + PhrasePM, PMColor)
  176. Say(Id, 'PM To: [' + GetPlayerStat(SlotIDPM, 'Name') + ']' + ' ' + PhrasePM, PMColor2)
  177. WriteLn('PM' + ' ' + 'From' + ' [' +  GetPlayerStat(Id, 'Name') + '] ' + 'To: [' + GetPlayerStat(SlotIDPM, 'Name') + ']' + ' ' + PhrasePM);
  178. exit;
  179. end;
  180.  
  181. if NameCountPM = 70 then begin
  182. WriteConsole(Id, GetPlayerStat(SlotIDPM, 'Name') + ' ' + 'has muted your Private Messages', ErrorColor)
  183. exit;
  184. end
  185. end;
  186. end;
  187.  
  188. if (LowerCase(GetPiece(Text, ' ', 0)) = '/ignore') then begin
  189.  
  190. if NameCountPM = 1 then begin
  191. IgnorePM[Id][SlotIDPM] := true;
  192. WriteConsole(SlotIDPM, GetPlayerStat(Id, 'Name') + ' ' + 'has muted your Private Messages', ErrorColor);
  193. Say(Id, 'You have muted Private Messages from' + ' ' + GetPlayerStat(SlotIDPM, 'Name') + ' ' + '(to get private messages again from this player use /unignore)', ErrorColor)
  194. WriteLn(GetPlayerStat(Id, 'Name') + ' ' + 'has muted Private Messages from' + ' ' + GetPlayerStat(SlotIDPM, 'Name'));
  195. exit;
  196. end;
  197.  
  198. if NameCountPM = 0 then begin
  199. Say(Id, 'Phrase' + ' "' + NamePiecePM + '" ' + 'was not found, please be more specific or use the players slot number (1-32)', ErrorColor)
  200. exit;
  201. end;
  202. if NameCountPM > 1 then begin
  203. Say(Id, 'Phrase' + ' "' + NamePiecePM + '" ' + 'returned too many different players, please be more specific or use the players slot number (1-32)', ErrorColor)
  204. exit;
  205. end;
  206. end;
  207.  
  208. if (LowerCase(GetPiece(Text, ' ', 0)) = '/unignore') then begin
  209.  
  210. if NameCountPM = 1 then begin
  211. IgnorePM[Id][SlotIDPM] := false;
  212. WriteConsole(SlotIDPM, GetPlayerStat(Id, 'Name') + ' ' + 'has unmuted your Private Messages', ErrorColor)
  213. Say(Id, 'You have unmuted Private Messages from' + ' ' + GetPlayerStat(SlotIDPM, 'Name'), ErrorColor)
  214. WriteLn(GetPlayerStat(Id, 'Name') + ' ' + 'has unmuted Private Messages from' + ' ' + GetPlayerStat(SlotIDPM, 'Name'));
  215. exit;
  216. end;
  217.  
  218. if NameCountPM = 0 then begin
  219. Say(Id, 'Phrase' + ' "' + NamePiecePM + '" ' + 'was not found, please be more specific or use the players slot number (1-32)', ErrorColor)
  220. exit;
  221. end;
  222. if NameCountPM > 1 then begin
  223. Say(Id, 'Phrase' + ' "' + NamePiecePM + '" ' + 'returned too many different players, please be more specific or use the players slot number (1-32)', ErrorColor)
  224. exit;
  225. end
  226. end
  227. end;
  228. //
  229.  
  230. if (LowerCase(Text) = '/ignoreall') then begin
  231. for i := 1 to 32 do IgnorePM[Id][i] := true;
  232. WriteConsole(Id, 'You have muted all Private Messages, to undo this type /unignoreall', ErrorColor);
  233. end;
  234. if (LowerCase(Text) = '/unignoreall') then begin
  235. for i := 1 to 32 do IgnorePM[Id][i] := false;
  236. WriteConsole(Id, 'You have unmuted all Private Messages', ErrorColor);
  237. end;
  238.  
  239. //
  240.  
  241. end;
  242.  
  243. procedure OnJoinGame(Id, Team: byte);
  244. begin
  245. HighestID := 1
  246. SetHighestID();
  247. end;
  248.  
  249. procedure OnLeaveGame(Id, Team: byte; Kicked: boolean);
  250. var i: byte;
  251. begin
  252.  
  253. for i := 1 to 32 do begin
  254. IgnorePM[i][Id] := false;
  255. IgnorePM[Id][i] := false;
  256. end;
  257.  
  258. if Id = HighestID then begin
  259. HighestID := 1
  260. SetHighestID();
  261. end;
  262. end;
  263.  
  264. procedure ActivateServer();
  265. var i, j: byte;
  266. begin
  267. SetHighestID();
  268.   for i := 1 to 32 do for j := 1 to 32 do IgnorePM[i][j] := false;
  269. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement