
/* AMX Mod script.
*
* (c) Copyright 2002, Jonas Lindgren
* This file is provided as is (no warranties).
*
*/

#include <amxmod>

new hebought[33];	// How many grenades of each has he bought?
new flashbought[33];
new smokebought[33];
new damageboost_toggle[33];	// Has he recieved his first 'warning'?

public client_connect(id) {
	damageboost_toggle[id] = 0;	// Make sure a fresh player gets a warning first.
}

public hebuy(id){
	hebought[id]++;
	evaluate(id);
	return PLUGIN_CONTINUE;
}

public flashbuy(id){	// This one is a bit buggy, as only the first flash of 2 counts as weappickup, therefore I cannot count the second flash bought, and have to rely on them buying both flashes at once, thus outlawing buying one flash, throwing it then buying another. Suggestions?
	flashbought[id]++;
	evaluate(id);
	return PLUGIN_CONTINUE;
}

public smokebuy(id){
	smokebought[id]++;
	evaluate(id);
	return PLUGIN_CONTINUE;
}

public evaluate(id){
	if (hebought[id] > 1 || flashbought[id] > 1 || smokebought[id] > 1) {	// You'd think that flashbought should be bigger than 2, not 1, but not until I sort a bug with that out, see flashbuy.
		client_print(id,print_chat,"[AMX] You're only allowed to buy one full inventory of grenades each round.")
		if (damageboost_toggle[id] == 1) {	// If this is their second or more warning, cause them severe damage. (upgrade this to slay in the next version)
			user_slap(id,100);
		} else {	// Else, if this is their first warning, go easy on them and put them in line for real damage next time they do it.
			damageboost_toggle[id] = 1;
			user_slap(id,50);
		}
	}
}

public reset_hud(id) {
	hebought[id] = 0;
	flashbought[id] = 0;
	smokebought[id] = 0;
	return PLUGIN_CONTINUE;
}

public plugin_init(){
	register_plugin("Anti-grenadespam","1.2","Smygasaur")
	register_event("WeapPickup","hebuy","b","1=4");	// Do this when someone buys an HE
	register_event("WeapPickup","flashbuy","b","1=25");	// Do this when someone buys an flash (still a bit buggy, see flashbuy)
	register_event("WeapPickup","smokebuy","b","1=9");	// Do this when someone buys an smoke
	register_event("ResetHUD", "reset_hud", "b");	// Do this whenever a player respawns (I think)
	return PLUGIN_CONTINUE;
}

