Creating a bot system based on .txt file -
JaKe Elite - 23.04.2013
Hi i am creating a bot system.
All messages that the bot are sending are from a .txt not from script.
It works. However.
It always stuck at the 1st line from the .txt and also it only takes the 1st whole word.
Not the whole word of the line.
Demonstration:
Код:
Hello i am bot of JakAdmin.
Steve will send these.
But instead the result is
Then it keeps sending.
How to fix it?
pawn Код:
#if BOT_FEATURE == true
ChatTimer = SetTimer("BotChat", 1000*60*1, true);
#endif
#if BOT_FEATURE == true
if(fexist("JakAdmin/Config/botdialogue.txt"))
{
new File:dialogue;
new str[256];
dialogue = fopen("JakAdmin/Config/botdialogue.txt", io_read);
while(fread(dialogue, str, sizeof(str), false))
{
new idx;
format(Chats[ChatCount], 256, "%s", strtok(str, idx));
ChatCount++;
}
print("Bot Dialogue has been loaded!");
}
else
{
print("Bot Dialogue has not been loaded!");
}
#endif
#if BOT_FEATURE == true
forward BotChat();
public BotChat()
{
if(ccount == sizeof(Chats)) ccount = 0;
new str[256];
format(str, sizeof(str), "%s: "white"%s", BOT_NAME, Chats[ccount]);
SendClientMessageToAll(COLOR_GREEN, str); //Change the colour!
format(str, sizeof(str), "%s: %s", BOT_NAME, Chats[ccount]);
printf(str);
return 1;
}
#endif
BOT_NAME is "Steve".
Re: Creating a bot system based on .txt file - Emmet_ - 23.04.2013
Not sure if you still need help with this lol, anyways try this:
pawn Код:
#if BOT_FEATURE == true
ChatTimer = SetTimer("BotChat", 1000*60*1, true);
#endif
#if BOT_FEATURE == true
if(fexist("JakAdmin/Config/botdialogue.txt"))
{
new File:dialogue;
new str[256];
dialogue = fopen("JakAdmin/Config/botdialogue.txt", io_read);
while(fread(dialogue, str, sizeof(str), false))
{
new idx;
strmid(Chats[ChatCount], str, 0, strlen(str)-1, 200);
ChatCount++;
}
print("Bot Dialogue has been loaded!");
}
else
{
print("Bot Dialogue has not been loaded!");
}
#endif
#if BOT_FEATURE == true
forward BotChat();
public BotChat()
{
if(ccount == sizeof(Chats)) ccount = 0;
new str[256];
format(str, sizeof(str), "%s: "white"%s", BOT_NAME, Chats[ccount]);
SendClientMessageToAll(COLOR_GREEN, str); //Change the colour!
format(str, sizeof(str), "%s: %s", BOT_NAME, Chats[ccount]);
printf(str);
return 1;
}
#endif
Re: Creating a bot system based on .txt file -
JaKe Elite - 23.04.2013
It works fine.
However,
The result is
Код:
Steve: Hello
Steve: My
Steve: Whahahahaha!
botdialogue.txt
Код:
Hello all users i'm JakBot!
My Master is _Jake_.
Whahahahahaha!
EDIT:
When there is no more message to send.
The bot keeps sending empty text.
Re: Creating a bot system based on .txt file -
Sithis - 23.04.2013
Why not make an array that contains multiple strings, then echo a string randomly or in order.