Author Topic: Auto-Chat  (Read 3236 times)

0 Members and 1 Guest are viewing this topic.

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Auto-Chat
« on: May 26, 2007, 05:16:05 am »
Script Name: Auto-Chat
Script Description: Show an automatic message when what a player says matches a list of keywords.
Original Author(s): PerroAZUL
Core Version: 2.6.1
Requieres: xsplit.pas
Code:
Code: [Select]
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;

This script gives you the following commands:

/autochatadd name/R|G|B/keywords/Message
Adds a new message to show when all the keywords are inside the text that somones writes in the chat.
name: identifies the message so it can be deleted
R|G|B: color of the message.
keywords: list of keywords separated by space.
Message: message to show.

Note that the character "/" is used as a separator, so it can't be included in name, keywords or message. And also everything should be lowercase, except Message.

Example: /autochatadd example/255|0|0/server lag/Go to other server!
if someone says "this server lags" or "big lags on this server" or anything that includes "lag" and "server" the message will be shown, in red.

/autochatdel name
Deletes an entry from the automatic messages to show.

/autochatload
Reloads the file where messages are stored, autochat.txt

/autochathelp
Reminds you the parameters of /autochatadd

/autochatlist
Lists all the entries in the server console.


This script is in some way similar to cResponse script, but the difference is that in this one you can set multiple keywords. I use it to joke with my friends in my server :)
« Last Edit: June 07, 2007, 11:45:20 am by PerroAZUL »
urraka

Offline KeYDoN

  • Major
  • *
  • Posts: 60
Re: Auto-Chat
« Reply #1 on: May 26, 2007, 05:53:53 pm »
nice example, if someone says "juhu first server with no lag" it would say "Go to other server!"
but well done nice ;D

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: Auto-Chat
« Reply #2 on: May 26, 2007, 07:28:02 pm »
haha u are right :P
but i think it's mainly to joke with people that i did the script. my friends make taunts joking about me so i give them an auto response heh
urraka

Offline xReaperx

  • Major(1)
  • Posts: 45
Re: Auto-Chat
« Reply #3 on: May 27, 2007, 05:55:32 am »
doesn't like me :(