0 Members and 1 Guest are viewing this topic.
var autochat_data: array of string; autochat_sep: string;procedure autochat_Delete(idx: integer);var i, L: integer;begin L := GetArrayLength(autochat_data) - 1; for i := idx to L - 1 do begin autochat_data[i] := autochat_data[i + 1]; end; SetArrayLength(autochat_data, L);end;procedure autochat_SaveFile();var text: string; i, L: integer;begin L := GetArrayLength(autochat_data) - 1; for i := 0 to L do begin text := text + autochat_data[i] + chr(13) + chr(10); end; WriteFile('autochat.txt', text);end;procedure autochat_LoadFile();var s: TStringArray; i, L, size: integer;begin SetArrayLength(autochat_data, 0); if FileExists('autochat.txt') then begin s := xsplit(ReadFile('autochat.txt'), chr(13) + chr(10)); L := GetArrayLength(s) - 1; for i := 0 to L do begin if s[i] <> '' then begin size := GetArrayLength(autochat_data) + 1; SetArrayLength(autochat_data, size); autochat_data[size - 1] := s[i]; end; end; end;end;procedure autochat_ActivateServer();var s: TStringArray; i, L, size: integer;begin autochat_sep := '/'; autochat_LoadFile();end;procedure autochat_OnPlayerSpeak(ID: byte; Text: string);var i, L, j: integer; s, keys, color: TStringArray; r, g, b, AllKeysMatch: byte;begin Text := LowerCase(Text); L := GetArrayLength(autochat_data) - 1; for i := 0 to L do begin SetArrayLength(s, 0); s := xsplit(autochat_data[i], autochat_sep); if GetArrayLength(s) = 4 then begin r := 255; g := 255; b := 255; SetArrayLength(color, 0); color := xsplit(s[1], '|'); if GetArrayLength(color) = 3 then begin r := StrToInt(color[0]); g := StrToInt(color[1]); b := StrToInt(color[2]); end; SetArrayLength(keys, 0); keys := xsplit(s[2], ' '); AllKeysMatch := 1; for j := 0 to GetArrayLength(keys) - 1 do begin if ContainsString(Text, keys[j]) = false then begin AllKeysMatch := 0; j := GetArrayLength(keys); end; end; if AllKeysMatch = 1 then WriteConsole(0, s[3], RGB(r, g, b)); end; end;end;procedure autochat_OnCommand(ID: Byte; Text: string);var lText, name: string; s: TStringArray; size: integer; i: integer;begin //Commands: // /autochatadd name,color,keys,msg // /autochatdel name // /autochatlist // /autochathelp lText := LowerCase(Text); if StrPos('/autochatadd ', lText) = 1 then begin Text := Copy(Text, 14, Length(Text)); s := xsplit(Text, autochat_sep); if GetArrayLength(s) = 4 then begin size := GetArrayLength(autochat_data) + 1; SetArrayLength(autochat_data, size); autochat_data[size - 1] := Text; autochat_SaveFile(); end else begin WriteLn('Parameters error.'); end; end else if StrPos('/autochatdel ', lText) = 1 then begin size := GetArrayLength(autochat_data); name := Copy(lText, 14, Length(lText)); for i := 0 to size - 1 do begin SetArrayLength(s, 0); s := xsplit(autochat_data[i], autochat_sep); if name = s[0] then begin autochat_Delete(i); i := i - 1; size := size - 1; end; end; autochat_SaveFile(); end else if lText = '/autochatlist' then begin size := GetArrayLength(autochat_data); for i := 0 to size - 1 do begin WriteLn(autochat_data[i]); end; end else if lText = '/autochathelp' then begin WriteLn('/autochatadd name/R|G|B/keywords/message'); end else if lText = '/autochatload' then begin autochat_LoadFile(); end;end;