[Tutorial] How to make a "BOT" replies almost everything player says..
#1

Hi everybody there...
Today, I'm gonna show you, How to make a "BOT" that replies almost all words a player says.
Fine... Let's start...
-----------------------------------------------------------------------------------------
1.-Before do anything, We must add the following include at the top of your script...

pawn Code:
#include <a_samp>//Obviously, we have to add a_samp include which contains all the information to work...

2.-You have to go to the following function:


pawn Code:
public OnPlayerText(playerid, text[]) //At this function, We're gonna write, a text and the response from the "BOT" if we call it like this...
{
    return 1;
}

3.-Onto it, We have to add the following things:

pawn Code:
if(!strcmp(text, "Hello Bot", true)) // Here we have to insert the text, This function will check if the player has said this word
4.-
pawn Code:
{
      new string[128]; GetPlayerName(playerid,string,sizeof(string));
      format(string,sizeof(string),"%s[%d]: %s",string,playerid, text);//Here we are going to give the format, when the player says that word...
5.-
pawn Code:
SendClientMessageToAll(GetPlayerColor(playerid), string);//Here we are going to add the function, to send the text...
      SendClientMessageToAll(green, "[BOT]: Hey Wassup!");//Here is the reply...In other words, What the bot will reply to the player... °Don't forget to add the "#define green 0x33FF33AA" Or you'll get an error
6.-
pawn Code:
return 0;//We have to add return 0;//To stop the BOT says it.
    }//Close the bracket.
The whole function will be like this:

pawn Code:
public OnPlayerText(playerid, text[])
{
if(!strcmp(text, "Hi Bot", true))
    {
      new string[128]; GetPlayerName(playerid,string,sizeof(string));
      format(string,sizeof(string),"%s[%d]: %s",string,playerid, text);
      SendClientMessageToAll(GetPlayerColor(playerid), string);
      SendClientMessageToAll(green, "[BOT]iThe_Bot: Hey Wassup!");
      return 0;
    }
    return 1;
}
So Now You can add your own Words And Replies...

Thank you for see my Tutorial.
Reply
#2

well, nice tutorial.

but i prefer strfind than strcmp.

because the player may write Hello Bot so the bot won't reply

so replace if(!strcmp(text. "Hello Bot")) to if(strfind(text, "Hello Bot")) (that's what i prefer)
Reply
#3

Well, We can use both..
Anyways thanks for reply.
Reply
#4

pawn Code:
new string[128]; GetPlayerName(playerid,string,sizeof(string));
      format(string,sizeof(string),"%s[%d]: %s",string,playerid, text);
      SendClientMessageToAll(GetPlayerColor(playerid), string);
Those above lines won't even work...
Reply
#5

Nope, They will work...

They will check the color from the player...

So The bot response will be the same color as the Player!
Reply
#6

Cool but i wanna know where to add more words and where to add reply of my bot.
I am a beginner so please help me.
Reply
#7

yes looking good
Reply
#8

Wouldn't it be easier to use strfind,and make an array that would store for about 30 replies of the bot?And select the bot's reply through an index,as you know the elements of the array,like:
pawn Code:
new BotMessage[][]=
{
   "Hi!",//element 0
   "I am fine thanks,and you?"//element 1
};
Then use strinfd,and if you find the words:"how are you",then do:
pawn Code:
SendClientMessage(playerid,COLOR_GREEN,BotReply[1]);
Much shorter :P
Reply
#9

Quote:
Originally Posted by Cjgogo
View Post
Wouldn't it be easier to use strfind,and make an array that would store for about 30 replies of the bot?And select the bot's reply through an index,as you know the elements of the array,like:
pawn Code:
new BotMessage[][]=
{
   "Hi!",//element 0
   "I am fine thanks,and you?"//element 1
};
Then use strinfd,and if you find the words:"how are you",then do:
pawn Code:
SendClientMessage(playerid,COLOR_GREEN,BotReply[1]);
Much shorter :P
Yea, but for newbies it would be easier to use the one in the tutorial
Reply
#10

Quote:
Originally Posted by _Khaled_
View Post
Yea, but for newbies it would be easier to use the one in the tutorial
This is 1.000.000x more efficient. Your method would require 10x more lines then what he said, people should learn about the right way to do it not the way you think is easier.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)