//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(filepath, 63); format(filepath, 63, "%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 a = 0; a < MAXADS && !feof(fHandle); a++) { //Get line fgets(fHandle, output, 511);
//Check if it contains conditions if(output[0] == COND_TKN) { //Cut the conditions off the string split(output, conditions, 127, output, 511, DEVIDE_STKN);
//Determine if its say check or normal ad type = output[0] == SAY_TKN ? 1 : 0;
//Put the conditions in own space for(new b = 0; b < 3; b++) { new sort[16], cond[32], numb;
//Remove the % from line conditions[0] = ' '; trim(conditions);
//Get one condition from the line split(conditions, temp, 64, conditions, 127, COND_STKN);
//Save it setString(STORE, NORM_AD, output, adCount[NORM_AD]); }
//Increment the right counter adCount[NORM_AD] += type == NORM_AD ? 1 : 0; adCount[SAY_AD] += type == SAY_AD ? 1 : 0; }
//Set a first task, if there are any normal ads if(adCount[NORM_AD] != 0) set_task(random_float(RAND_MIN, RAND_MAX), "eventTask");
//Close file to prevent lockup fclose(fHandle); } }
new currAd = -1;
public eventTask() { //Go past all ads and check conditions for(new a = 0; a < adCount[NORM_AD]; a++) { //Put current ad to the next one currAd = currAd == adCount[NORM_AD] - 1 ? 0 : currAd + 1;
if(checkConditions(currAd, NORM_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_MIN, RAND_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(talk, 63) ;
//En nu rennen voor jullie zakgeld klootzjakken! for(new a = 0; a < adCount[SAY_AD]; a++) { //Get the string getString(STORE, SAY_AD, keyword, 15, a, 0);
if(containi(talk, keyword) != -1) { //Check the rest if it fails to conditions if(!checkConditions(a, SAY_AD)) continue;
//Set the task set_task(0.3, "displayAd", 0, data, 3);
//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(STORE, params[1], message, 127, params[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") == 0 && params[2] != 0) { message_begin(MSG_ONE, gmsgSayText, {0,0,0}, params[2]); write_byte(params[2]); write_string(message); message_end();
} else { //Display the message to everyone new plist[32], playernum, player;
get_players(plist, playernum, "c");
for(new i = 0; i < playernum; i++) { player = plist[i];