AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Autoresponder modification (https://forums.alliedmods.net/showthread.php?t=117492)

OM NOM NOM NOM 02-01-2010 17:36

Autoresponder modification
 
1 Attachment(s)
MaximusBrood Autoresponder/Advertiser




PHP Code:

#include <amxmodx>
#include <amxmisc>
#pragma semicolon 1
new const PLUGIN[] = "Autoresponder/Advertiser";
new const 
VERSION[] = "0.5";
new const 
AUTHOR[] = "MaximusBrood";
#define NORM_AD 0
#define SAY_AD 1
#define COND 0
#define STORE 1
#define COND_TKN '%'
#define SAY_TKN '@'
#define COND_STKN "%"
#define DEVIDE_STKN "~"
#define SAY_STKN "@"
//-.-.-.-.-.-.-.-.DEFINES.-.-.-.-.-.-.-.-.-.-.
//Maximum amount of ads
#define MAXADS 64
//Minimum difference between two different ads (float)
new const Float:RAND_MIN 60.0;
//Maximum difference between two different ads (float)
new const Float:RAND_MAX 80.0;
//-.-.-.-.-.-.-.-.END DEFINES..-.-.-.-.-.-.-.
//Stores
new sayConditions[MAXADS][3][32];
new 
normConditions[MAXADS][3][32];
new 
normStore[MAXADS][128];
new 
sayStore[MAXADS][2][128];
new 
gmsgSayText;
//Counters
new adCount[2] = {00};
public 
plugin_init() {
register_plugin(PLUGINVERSIONAUTHOR);
 
register_cvar("ad_react_all""1");
 
gmsgSayText get_user_msgid("SayText");
 
register_clcmd("say","eventSay");
register_clcmd("say_team","eventSay");
 
//Delay the load proces by 10 sec because we don't want to get more load
//on the already high-load mapchange.
//Too soon to affect players while playing, too late to create time-out @ mapchange
set_task(10.0"load");
}
public 
load()
{
//Load the data
new filepath[64];
get_configsdir(filepath63);
format(filepath63"%s/advertisements.ini"filepath);
 
if(
file_exists(filepath))
{
new 
output[512], conditions[128], temp[64], type;
 
//Open file
new fHandle fopen(filepath"rt");
 
//Checks for failure
if(!fHandle)
return;
 
//Loop through all lines
for(new 0MAXADS && !feof(fHandle); a++)
{
//Get line
fgets(fHandleoutput511);
 
 
//Work away comments
if(output[0] == ';' || !output[0] || output[0] == ' ' || output[0] == 10
{
//Line is not counted
a--;
continue;
}
 
//Reset type
type 0;
 
//Check if it contains conditions
if(output[0] == COND_TKN)
{
//Cut the conditions off the string
split(outputconditions127output511DEVIDE_STKN);
 
//Determine if its say check or normal ad
type output[0] == SAY_TKN 0;
 
//Put the conditions in own space
for(new 03b++)
{
new 
sort[16], cond[32], numb;
 
//Remove the % from line 
conditions[0] = ' ';
trim(conditions);
 
//Get one condition from the line
split(conditionstemp64conditions127COND_STKN);
 
split(tempsort15cond31" ");
 
if(
equali(sort"map"))
{
numb 0;
} else if(
equali(sort"min_players"))
{
numb 1;
} else if(
equali(sort"max_players"))
{
numb 2;
} else
{
continue;
}
 
//Copy it to its final resting place ^^
setString(CONDtypecondadCount[type], numb);
 
//Exit if it hasn't got more conditions
if(!conditions[0])
break;
}
}
 
if(
type == 0)
type output[0] == SAY_TKN 0;
 
if(
type == SAY_AD)
{
new 
said[32], answer[128];
 
//Remove the @ from line
output[0] = ' ';
trim(output);
 
split(outputsaid31answer127DEVIDE_STKN);
 
//Apply color
setColor(answer127);
 
//Save it
setString(STORESAY_ADsaidadCount[SAY_AD], 0);
setString(STORESAY_ADansweradCount[SAY_AD], 1);
} else
//if(type == NORM_AD)
{
//Apply color
setColor(output511);
 
//Save it
setString(STORENORM_ADoutputadCount[NORM_AD]);
}
 
//Increment the right counter
adCount[NORM_AD] += type == NORM_AD 0;
adCount[SAY_AD] += type == SAY_AD 0;
}
 
//Set a first task, if there are any normal ads
if(adCount[NORM_AD] != 0)
set_task(random_float(RAND_MINRAND_MAX), "eventTask");
 
//Close file to prevent lockup
fclose(fHandle); 
}
}
new 
currAd = -1;
public 
eventTask()
{
//Go past all ads and check conditions
for(new 0adCount[NORM_AD]; a++)
{
//Put current ad to the next one
currAd currAd == adCount[NORM_AD] - currAd 1;
 
if(
checkConditions(currAdNORM_AD))
{
//Display the ad
new data[3];
data[0] = currAd;
data[1] = NORM_AD;
data[2] = 0;
displayAd(data);
 
break;
}
}
 
//Set a new task
set_task(random_float(RAND_MINRAND_MAX), "eventTask");
 
return 
PLUGIN_CONTINUE;
}
public 
eventSay(id)
{
//If nothing is said, don't check
if(adCount[SAY_AD] == 0)
return 
PLUGIN_CONTINUE;
 
new 
talk[64], keyword[16];
read_args(talk63) ;
 
//En nu rennen voor jullie zakgeld klootzjakken!
for(new 0adCount[SAY_AD]; a++)
{
//Get the string
getString(STORESAY_ADkeyword15a0);
 
if(
containi(talkkeyword) != -1)
{
//Check the rest if it fails to conditions
if(!checkConditions(aSAY_AD))
continue;
 
new 
data[3];
data[0] = a;
data[1] = SAY_AD;
data[2] = id;
 
//Set the task
set_task(0.3"displayAd"0data3);
 
//Don't execute more of them
break;
}
}
 
return 
PLUGIN_CONTINUE;
}
public 
displayAd(params[])
{
//Get the string that is going to be displayed
new message[128];
getString(STOREparams[1], message127params[0], params[1]);
 
//If its enabled by cvar and id is set, display to person who triggered message only
if(get_cvar_num("ad_react_all") == && params[2] != 0)
{
message_begin(MSG_ONEgmsgSayText, {0,0,0}, params[2]);
write_byte(params[2]);
write_string(message);
message_end();
 
} else
{
//Display the message to everyone
new plist[32], playernumplayer;
 
get_players(plistplayernum"c");
 
for(new 
0playernumi++)
{
player plist[i];[/i]
[
i][/i]
[
i]message_begin(MSG_ONEgmsgSayText, {0,0,0}, player);[/i]
[
i]write_byte(player);[/i]
[
i]write_string(message);[/i]
[
i]message_end();[/i]
[
i]}[/i]
[
i]}[/i]
[
i][/i]
[
i]return PLUGIN_HANDLED;[/i]
[
i]}[/i]
[
i]//---------------------------------------------------------------------------[/i]
[i]// STOCKS[/i]
[i]//---------------------------------------------------------------------------[/i]
[i]stock checkConditions(atype)[/i]
[
i]{[/i]
[
i]//Mapname[/i]
[i]if((type == NORM_AD && normConditions[a][0][0]) || (type == SAY_AD && sayConditions[a][0][0]))[/i]
[
i]{[/i]
[
i]new mapname[32];[/i]
[
i]get_mapname(mapname31);[/i]
[
i][/i]
[
i]if(! (type == NORM_AD && equali(mapnamenormConditions[a][0]) ) || (type == SAY_AD && equali(mapnamesayConditions[a][0]) ) )[/i]
[
i]return false;[/i]
[
i]}[/i]
[
i][/i]
[
i]//Min Players[/i]
[i]if((type == NORM_AD && normConditions[a][1][0]) || (type == SAY_AD && sayConditions[a][1][0]))[/i]
[
i]{[/i]
[
i]new playersnum get_playersnum();[/i]
[
i][/i]
[
i]if( (type == NORM_AD && playersnum str_to_num(normConditions[a][1]) ) || (type == SAY_AD && playersnum str_to_num(sayConditions[a][1]) ) )[/i]
[
i]return false;[/i]
[
i]}[/i]
[
i][/i]
[
i]//Max Players[/i]
[i]if((type == NORM_AD && normConditions[a][2][0]) || (type == SAY_AD && sayConditions[a][2][0]))[/i]
[
i]{[/i]
[
i]new playersnum get_playersnum();[/i]
[
i][/i]
[
i]if( (type == NORM_AD && playersnum str_to_num(normConditions[a][2]) ) || (type == SAY_AD && playersnum str_to_num(sayConditions[a][2]) ) )[/i]
[
i]return false;[/i]
[
i]}[/i]
[
i][/i]
[
i]//If everything went fine, return true[/i]
[i]return true;[/i]
[
i]} [/i]
[
i]stock setColor(string[], len)[/i]
[
i]{[/i]
[
i]if (contain(string"!t") != -|| contain(string"!g") != -|| contain(string,"!n") != -1)[/i]
[
i]{[/i]
[
i]//Some nice shiny colors ^^[/i]
[i]replace_all(stringlen"!t""^x03");[/i]
[
i]replace_all(stringlen"!n""^x01");[/i]
[
i]replace_all(stringlen"!g""^x04");[/i]
[
i][/i]
[
i]//Work away a stupid bug[/i]
[i]format(stringlen"^x01%s"string);[/i]
[
i]}[/i]
[
i]}[/i]
[
i]stock getString(modetypestring[], lenonetwo 0)[/i]
[
i]{[/i]
[
i]//server_print("mode: %d type: %d len: %d one: %d two %d", mode, type, len, one, two);[/i]
[i][/i]
[
i]//Uses the fact that a string is passed by reference[/i]
[i]if(mode == COND)[/i]
[
i]{[/i]
[
i]if(type == NORM_AD)[/i]
[
i]{[/i]
[
i]copy(stringlennormConditions[one][two]);[/i]
[
i]} else//if(type = SAY_AD)[/i]
[i]{[/i]
[
i]copy(stringlensayConditions[one][two]);[/i]
[
i]}[/i]
[
i]} else//if(mode == STORE)[/i]
[i]{[/i]
[
i]if(type == NORM_AD)[/i]
[
i]{[/i]
[
i]copy(stringlennormStore[one]);[/i]
[
i]} else//if(type == SAY_AD)[/i]
[i]{[/i]
[
i]copy(stringlensayStore[one][two]);[/i]
[
i]}[/i]
[
i]}[/i]
[
i]}[/i]
[
i]stock setString(modetypestring[], onetwo 0)[/i]
[
i]{[/i]
[
i]if(mode == COND)[/i]
[
i]{[/i]
[
i]if(type == NORM_AD)[/i]
[
i]{[/i]
[
i]copy(normConditions[one][two], 31string);[/i]
[
i]} else//if(type = SAY_AD)[/i]
[i]{[/i]
[
i]copy(sayConditions[one][two], 31string);[/i]
[
i]}[/i]
[
i]} else//if(mode == STORE)[/i]
[i]{[/i]
[
i]if(type == NORM_AD)[/i]
[
i]{[/i]
[
i]copy(normStore[one], 127string);[/i]
[
i]} else//if(type == SAY_AD)[/i]
[i]{[/i]
[
i]copy(sayStore[one][two], 127string);[/i]
[
i]}[/i]
[
i]}[/i]
[
i]}[/i]
[
i][/i

Hello my ninjas.

I've been using this plugin for some time now and I find it very useful.
If you reading this I hope that you have some time on your hands.
I’m in need of customized auto-reply code, adding several different possibilities, random check would be lovely.

Basically "when someone says 'cheat', the server reacts with 'To report a cheater, use blah blah blah...'"

advertisements.ini
Line #1 @cheat~!gTo report a cheater use blah #1
Line #2 @cheat~!gTo report a cheater use blah #2 </STRIKE>
Line #3 @cheat~!gTo report a cheater use blah #3 </STRIKE>

Right now the plugin has only one value/string auto-reply, if that's what you call it.
As for now both lines #2 and #3 are completely ignored. If you get a chance, please do make it go in random cycles.




advertisements.ini (Let's assume you've done it that way, another example)
Line #1 @cheat~!gTo report a cheater use blah #1
Line #2 @cheat~!gTo report a cheater use blah #2
Line #3 @cheat~!gTo report a cheater use blah #3

Player 1 types : cheat
Server replies with Line #1

Player 1 types : cheat (second time)
Server replies with Line #2

Player 1 types : cheat (third time)
Server replies with Line #3

OM NOM NOM NOM 02-02-2010 21:15

Re: Autoresponder modification
 
Oh sorry about that, my edit button, gave me 404.

fysiks 02-02-2010 21:17

Re: Autoresponder modification
 
Do you realize how annoying it is to read all italics?

OM NOM NOM NOM 02-02-2010 21:20

Re: Autoresponder modification
 
I didn't realize I had any italics till now.

-fixed-

fysiks 02-02-2010 21:27

Re: Autoresponder modification
 
To me, it looks like it would be much easier to create another plugin just for this.

OM NOM NOM NOM 02-02-2010 23:48

Re: Autoresponder modification
 
I though about it, yet I wanted to see if you could change [1] to a random value without having much to modify other lines, since I couldn’t do it myself, I decided to come here. (Too many lines, they make me mad).

Thanks, I’ll go bug a different section.
J

fysiks 02-03-2010 01:23

Re: Autoresponder modification
 
Well, it looks like this should have been in the Requests forum also :).


All times are GMT -4. The time now is 07:27.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.