I'm trying to make my Buffbot buff people when receiving a PM, like several buffbots out there do, using a chatbot script.
I'm was trying to use switch so that the script chooses the correct buff to use, but I simply couldn't figure out how to use it with strings. So I decided to go the messy way, by making loads of ifs and elses everywhere. It's working, but the code looks horrible. I know there's an easier way to do this, but I can't figure it out.
Basically, the way it's working now is by having a message look like this: "buff [buffname] [number of casts]". The word buff is needed since the script also handles dice rolls and a few other things my clan requested.
And while I'm on the subject, how would I go about making sure people can get only 1 buff per day? Adding sender to a map and calling it to check the names? I don't fully understand how maps work, even after reading veracity's tutorial, so I would be happy if someone explained how to use one in this particular case.
Here's the part of the code containing the buffing things:
I'm was trying to use switch so that the script chooses the correct buff to use, but I simply couldn't figure out how to use it with strings. So I decided to go the messy way, by making loads of ifs and elses everywhere. It's working, but the code looks horrible. I know there's an easier way to do this, but I can't figure it out.
Basically, the way it's working now is by having a message look like this: "buff [buffname] [number of casts]". The word buff is needed since the script also handles dice rolls and a few other things my clan requested.
And while I'm on the subject, how would I go about making sure people can get only 1 buff per day? Adding sender to a map and calling it to check the names? I don't fully understand how maps work, even after reading veracity's tutorial, so I would be happy if someone explained how to use one in this particular case.
Here's the part of the code containing the buffing things:
Code:
void main(string sender, string message)
{
if(contains_text(message, "buff"))
{
int numcasts = to_int(message);
if(contains_text(message, "madrigal"))
{
if(have_skill($skill[The Moxious Madrigal]))
{
if(my_mp() >= mp_cost($skill[The Moxious Madrigal]))
{
chat_private(sender, "Casting The Moxious Madrigal"+ numcasts +" times.");
use_skill(numcasts, $skill[The Moxious Madrigal], sender);
}
else
{
cli_execute("recover mp");
chat_private(sender, "Casting The Moxious Madrigal"+ numcasts +" times.");
use_skill(numcasts, $skill[The Moxious Madrigal], sender);
}
}
else
{
chat_private(sender, "I don't have that buff available, human.");
}
}
if(contains_text(message, "mojomuscular"))
{
if(have_skill($skill[The Magical Mojomuscular Melody]))
{
if(my_mp() >= mp_cost($skill[The Magical Mojomuscular Melody]))
{
chat_private(sender, "Casting The Moxious Madrigal"+ numcasts +" times.");
use_skill(numcasts, $skill[The Magical Mojomuscular Melody], sender);
}
else
{
cli_execute("recover mp");
chat_private(sender, "Casting The Magical Mojomuscular Melody"+ numcasts +" times.");
use_skill(numcasts, $skill[The Magical Mojomuscular Melody], sender);
}
}
else
{
chat_private(sender, "I don't have that buff available, human.");
}
}
else
{
chat_private(sender, "Excuse me, human, but I was not able to understand your request: "+ message +" is not an available buff or you made a mistake.");
}
}
}