/* AMX Mod script.
*
* (c) Copyright 2003, Gevurah
* <gevurah@comcast.net>
* This file is provided as is (no warranties).
*
* Thanks for some of the code to the creators of:
* Gore Plugin
* AMX wounded
* Admin Fire
* Lugwigs Jetpack
*/

/*
* AMX REALMOD V 1.4.2
*
* Requires Fun Module and CSStats Module and admin_vote plugin
*
* Makes mods like CS more "realistic"
* Adds bleeding effects like Gore Plugin (removed decals: caused lag on slower machines)
* Slows Players down depending on how many times they've been hit in the legs
* Decreases health depending on how many times they've been hit (bleeding)
* If you are hit by a HE grenade you light on fire
* If you stand too close to someone whos on fire, you catch fire
* If you are slashed by a knife you bleed a lot
*
* Bandages can only be bought at the beginning of the round until the buytime
* for the server is reached. also, you must be in the buyzone to buy them.
* 
* Same goes for fire extinguishers.
*
* You may buy as many bandages as you want. A bandage can be used to stop the
* bleeding of a single wound. You may use as many as you have bought. If you
* die you lose all of your bandages.
*
* Same rules apply for fire extinguishers.
*
* If you are on fire you can use a fire extinguisher to put yourself out.
*
* Console Commands: realmod_buy <bandage|fire> - buys a bandage. costs $100.
*												 Can be used to stop bleeding
*                   realmod_use <bandage|fire> - uses a bought bandage.
*												 will stop wound that is
*                                 				 bleeding the most
*					my_wounds - reports your wounds
*					realmod_help - brings up realmod info
*					realmod_menu - opens menu (YAY)
*
* Admin Commands: amx_realmod <on|off> : turns Realmod on or off
*
* Server Commands: set_realmod <on|off> : turns Realmod on or off
*
* CVARS: realmod - if set to 1 plugin on, if set to 0 plugin off
*        realmod_blood - if set to 1 blood effects on, if set to 0 blood effects off
*        realmod_speed - if set to 0, speed effects off. the higher you set it, the less
*						 your max speed is each time you're hit in the legs
*        realmod_damage - if set to 0 bleeding does not cause damage. the higher u set
*                         realmod_damage the more damage bleeding does.
*		 realmod_fire - if 1 fire is enabled. if 0 fire is off
*		 realmod_fireothers - if 1 players can be lit on fire by other players if they
*							  they stand too close to a player thats on fire. 0 is off
*		 realmod_knife - if set to 0, knife hits have no effects. the higher you set it
*						 the more damage bleeding from knife wounds does.
*		 realmod_vote - if set to 1, voting enabled. if 0 voting disabled
*		
* say /voterealmod - starts a vote to start Realmod
* 
*		       contact me with suggestions or bugs
*/

/************************************************************
* INCLUDES
************************************************************/

#include <amxmodx>
#include <amxmisc>
#include <csstats>
#include <file>
#include <string>
#include <fun>
#include <cstrike>

/************************************************************
* DEFINES
************************************************************/

#define	TE_BLOODSTREAM		101

/************************************************************
* GLOBALS
************************************************************/

new playerbody[32][8]
new bool:playerbuy[32]
new bandages[32]
new Float:speedpercent[32]=100.0
new gmsgDamage
new onfire[32]
new knifed[32]
new leghits[32]
new option[2] //vote
new extinguisher[32]
new exhaust
new smoke1

/************************************************************
* CLIENT CONNECT - GOOD
************************************************************/

public client_connect(id) {
	new i
	for(i=0;i<8;i++)
		playerbody[id][i]=0
	bandages[id]=0
	onfire[id]=0
	knifed[id]=0
	leghits[id]=0
	extinguisher[id]=0
	speedpercent[id]=100.0
	return PLUGIN_CONTINUE 
}

public client_putinserver(id){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	help(id)
	return PLUGIN_CONTINUE
}


/************************************************************
* ROUND START/END - GOOD
************************************************************/

public round_start(){
	set_task(get_cvar_float("mp_buytime")*60.0,"buy_time_up",51)
	set_cvar_num("amx_buytimeup",0)
	return PLUGIN_CONTINUE
}

public new_round(id){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	new i
	for(i=0;i<8;i++)
		playerbody[id][i]=0
	playerbuy[id]=true
	speedpercent[id]=100.0
	onfire[id]=0
	knifed[id]=0
	leghits[id]=0
	set_user_maxspeed(id,240.0)
	return PLUGIN_CONTINUE
}


public round_end(){
	remove_task(51)
	return PLUGIN_CONTINUE
}

/************************************************************
* BUY ZONE - GOOD
************************************************************/

public buy_zone_func(id){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	if(get_cvar_num("amx_buytimeup"))
		return PLUGIN_CONTINUE
	if (read_data(1))
		playerbuy[id] = true
	else 
	playerbuy[id] = false
	return PLUGIN_CONTINUE
}

public buy_time_up(){
	set_cvar_num("amx_buytimeup",1)
	new plrs[32],nbr,i
	get_players(plrs,nbr)
	for(i=0;i<nbr;i++)
		playerbuy[plrs[i]] = false
	return PLUGIN_CONTINUE
}

/************************************************************
* DAMAGE AND DEATH - GOOD
************************************************************/

public damage_event(id){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	new wpn,bhit
	get_user_attacker(id,wpn,bhit)
	if(wpn!=4&&wpn!=29&&(get_cvar_num("realmod_damage")||get_cvar_num("realmod_blood")))
		playerbody[id][bhit]++
	if((bhit==6||bhit==7)&&get_cvar_num("realmod_speed")){
		leghits[id]++
		speedpercent[id]=70.0
	}
	if(get_cvar_num("realmod_fire")&&onfire[id]==0&&wpn==4){
		client_print(id,print_chat,"* [AMXX] An HE Grenade has lit you on FIRE")
		onfire[id]=1
		new skIndex[2]
		skIndex[0]=id
		ignite_effects(skIndex) 
		ignite_player(skIndex)
	}
	if (get_cvar_num("realmod_knife")&&wpn==29){
		client_print(id,print_chat,"* [AMXX] You were slashed with a knife")
		knifed[id]++
	}
	return PLUGIN_CONTINUE
}

public death(){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	if(!get_cvar_num("realmod_blood")&&!get_cvar_num("realmod_damage")&&!get_cvar_num("realmod_fire"))
		return PLUGIN_CONTINUE
	new id = read_data(2)
	if(bandages[id]||extinguisher[id])
		client_print(id,print_chat,"* [AMXX] You lost all your items when you died")
	bandages[id]=0
	extinguisher[id]=0
	return PLUGIN_CONTINUE
}

/************************************************************
* PLAYER COMMANDS
************************************************************/

public realmod_buy(id){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	new pitem[16]
	read_argv(1,pitem,15)
	if(pitem[0]==0){
		console_print(id,"You did not specify an item to buy")
		return PLUGIN_CONTINUE
	}
	if((!equal(pitem,"bandage"))&&(!equal(pitem,"fire"))){
		console_print(id,"%s is not an acceptable item to buy",pitem)
		return PLUGIN_CONTINUE
	}
	if(equal(pitem,"bandage")&&!get_cvar_num("realmod_blood")&&!get_cvar_num("realmod_damage")){
		client_print(id,print_chat,"* [AMXX] Blood and damage are off. Bandages are useless")
		return PLUGIN_CONTINUE
	}
	if(equal(pitem,"fire")&&!get_cvar_num("realmod_fire")){
		client_print(id,print_chat,"* [AMXX] Fire is off. Fire extinguishers are useless")
		return PLUGIN_CONTINUE
	}
	if(is_user_alive(id)==0){
		client_print(id,print_chat,"* [AMXX] Dead people don't need %s",equal(pitem,"bandage") ? "bandages" : "fire extinguishers")
		return PLUGIN_CONTINUE
	}
	if(get_cvar_num("amx_buytimeup")){
		client_print(id,print_center,"Buytime is up^n^nWait until next round to buy more...")
		return PLUGIN_CONTINUE
	}
	if(!playerbuy[id]){
		client_print(id,print_center,"You must be in a buyzone to buy")
		return PLUGIN_CONTINUE
	}
	else{
		if(cs_get_user_money(id)<100&&equal(pitem,"bandage")){
			client_print(id,print_center,"$100 is required to buy a bandage. You have too little money")
			return PLUGIN_CONTINUE
		}
		if(cs_get_user_money(id)<300&&equal(pitem,"fire")){
			client_print(id,print_center,"$300 is required to buy a fire extinguisher. You have too little money")
			return PLUGIN_CONTINUE
		}
		if(equal(pitem,"fire")){
			cs_set_user_money(id,(cs_get_user_money(id)-300))
			extinguisher[id]++
			client_print(id,print_center,"You bought a fire extinguisher. You now have %i fire extinguishers",extinguisher[id])
		}
		if(equal(pitem,"bandage")){
			cs_set_user_money(id,(cs_get_user_money(id)-100))
			bandages[id]++
			client_print(id,print_center,"You bought a bandage. You now have %i bandages",bandages[id])
		}
	}
	return PLUGIN_CONTINUE
}

public realmod_use(id){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	new pitem[16]
	read_argv(1,pitem,15)
	if(pitem[0]==0){
		console_print(id,"You did not specify an item to use")
		return PLUGIN_CONTINUE
	}
	if((!equal(pitem,"bandage"))&&(!equal(pitem,"fire"))){
		console_print(id,"%s is not an acceptable item to use",pitem)
		return PLUGIN_CONTINUE
	}
	if(equal(pitem,"bandage")&&!get_cvar_num("realmod_blood")&&!get_cvar_num("realmod_damage")){
		client_print(id,print_chat,"* [AMXX] Blood and damage are off. Bandages are useless")
		return PLUGIN_CONTINUE
	}
	if(equal(pitem,"fire")&&!get_cvar_num("realmod_fire")){
		client_print(id,print_chat,"* [AMXX] Fire is off. Fire extinguishers are useless")
		return PLUGIN_CONTINUE
	}
	if(is_user_alive(id)==0){
		client_print(id,print_chat,"* [AMXX] Using a %s when you're dead is pointless",equal(pitem,"bandage") ? "bandage" : "fire extinguisher")
		return PLUGIN_CONTINUE
	}
	if(equal(pitem,"fire")&&extinguisher[id]==0){
		client_print(id,print_chat,"* [AMXX] You have no fire extinguishers to use")
		return PLUGIN_CONTINUE
	}
	if(equal(pitem,"bandage")&&bandages[id]==0){
		client_print(id,print_chat,"* [AMXX] You have no bandages to use")
		return PLUGIN_CONTINUE
	}
	if(onfire[id]==0&&equal(pitem,"fire")){
		client_print(id,print_chat,"* [AMXX] You are not on fire. You don't need to use a fire extinguisher.")
		return PLUGIN_CONTINUE
	}
	if(equal(pitem,"fire")){
		onfire[id]=0
		extinguisher[id]--
		client_print(id,print_chat,"* [AMXX] A fire extinguisher was used. You have %i left",extinguisher[id])
	}
	if(equal(pitem,"bandage")){
		new i,temp[2]
		temp[0]=0
		temp[1]=0
		for(i=1;i<8;i++){
			if(temp[0]<playerbody[id][i]){
				temp[0]=playerbody[id][i]
				temp[1]=i
			}
			else
			if(temp[0]==playerbody[id][i])
				if((temp[1]==4||temp[1]==5)&&(i==6||i==7)){
				temp[0]=playerbody[id][i]
				temp[1]=i
			}
		}
		if(temp[1]==0)
			client_print(id,print_chat,"* [AMXX] You have not been shot. You don't need to use a bandage.")
		else{
			playerbody[id][temp[1]]--
			bandages[id]--
			client_print(id,print_chat,"* [AMXX] A bandage was used. You have %i left",bandages[id])
		}
	}
	return PLUGIN_CONTINUE
}

public wound_report(id){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	if(is_user_alive(id)==0){
		client_print(id,print_center,"Theres no use...you're already dead")
		return PLUGIN_CONTINUE
	}
	new wound,i
	for(i=1;i<8;i++)
		wound += playerbody[id][i]
	if(wound==0&&knifed[id]==0&&onfire[id]==0)
		client_print(id,print_chat,"* [AMXX] You are not wounded")
	if(wound)
		client_print(id,print_chat,"* [AMXX] You are bleeding from %i gunshot wounds",wound)
	if(knifed[id])
		client_print(id,print_chat,"* [AMXX] You are bleeding from %i knife wounds",knifed[id])
	if(onfire[id])
		client_print(id,print_chat,"* [AMXX] You are on fire")
	return PLUGIN_CONTINUE
}

/************************************************************
* ADMIN COMMANDS
************************************************************/

public realmod_on(id,level,cid){
	if (!cmd_access(id,level,cid,0))
		return PLUGIN_CONTINUE
	new msg[8]
	read_argv(1,msg,7)
	if(!equal("on",msg)&&!equal("off",msg)){
		console_print(id,"USAGE: amx_realmod <on|off>")
		return PLUGIN_CONTINUE
	}
	if(equal("on",msg)&&get_cvar_num("realmod"))
		console_print(id,"Realmod is already enabled")
	else{
		if(equal("off",msg)&&(get_cvar_num("realmod")==0))
			console_print(id,"Realmod is already disabled")
		else{
			server_cmd("set_realmod %s",msg)
			console_print(id,"Realmod has been turned %s",msg)
		}
	}
	return PLUGIN_CONTINUE
}

public realmod_func(){
	new msg[8]
	read_argv(1,msg,7)
	set_cvar_num("realmod",equal("on",msg))
	realmod_init()
	client_print(0,print_chat,"* Realmod has been %s",get_cvar_num("realmod") ? "enabled. Type realmod_menu in console for commands." : "disabled")
}

/************************************************************
* VOTING
************************************************************/

public vote_realmod(id){ 
	if(!get_cvar_num("realmod_vote"))
		client_print(id,print_chat,"* Voting has been disabled")
	new Float:voting = get_cvar_float("amx_last_voting") 
	if (voting > get_gametime()){ 
		client_print(id,print_chat,"* There is already one voting...") 
		return PLUGIN_HANDLED
	}
	if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime()) { 
		client_print(id,print_chat,"* Voting not allowed at this time...") 
		return PLUGIN_HANDLED
	} 
	new menu_msg[256] 
	format(menu_msg,255,"\yAMX %s Realmod?\w^n^n1. Yes^n2. No",get_cvar_num("realmod") ? "Disable" : "Enable") 
	new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
	set_cvar_float("amx_last_voting",  get_gametime() + vote_time ) 
	show_menu(0,(1<<0)|(1<<1),menu_msg,floatround(vote_time)) 
	set_task(vote_time,"check_votes") 
	client_print(0,print_chat,"* Voting has started...") 
	option[0]=option[1]=0 
	return PLUGIN_HANDLED   
} 

public vote_count(id,key){ 
	if ( get_cvar_float("amx_vote_answers") ) { 
		new name[32] 
		get_user_name(id,name,31) 
		client_print(0,print_chat,"* %s voted %s", name, key ? "against" : "for" ) 
	}
	++option[key]
	return PLUGIN_HANDLED
} 

public check_votes(id){ 
	if (option[0] > option[1]){ 
		server_cmd("set_realmod %s",get_cvar_num("realmod") ? "off" : "on" ) 
		client_print(0,print_chat,"* Voting successful (yes ^"%d^") (no ^"%d^").",option[0],option[1]) 
	} 
	else{ 
		client_print(0,print_chat,"* Voting failed (yes ^"%d^") (no ^"%d^").",option[0],option[1]) 
	} 
	return PLUGIN_HANDLED 
}

/************************************************************
* SPEED EFFECTS
************************************************************/

public setup_speed(){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	if(!get_cvar_num("realmod_speed"))
		return PLUGIN_CONTINUE
	new plrs[32],nbr,i
	get_players(plrs,nbr,"a")
	for(i=0;i<nbr;i++){
		if(speedpercent[plrs[i]]<100&&speedpercent[plrs[i]]>92.4)
			speedpercent[plrs[i]]+=1.5
		else
		if(speedpercent[plrs[i]]<92.5&&speedpercent[plrs[i]]>80.4)
			speedpercent[plrs[i]]+=3
		else
		if(speedpercent[plrs[i]]<80.5)
			speedpercent[plrs[i]]+=3.5
		set_user_maxspeed(plrs[i],(240-(leghits[plrs[i]]*get_cvar_num("realmod_speed")))*0.01*speedpercent[plrs[i]])
	}
	return PLUGIN_CONTINUE
}

public weapon_speed(id){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	if(!get_cvar_num("realmod_speed"))
		return PLUGIN_CONTINUE
	set_user_maxspeed(id,(240-(leghits[id]*get_cvar_num("realmod_speed")))*0.01*speedpercent[id])
	return PLUGIN_CONTINUE
}

/************************************************************
* BLEEDING DAMAGE
************************************************************/

public setup_head(){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	new plrs[32],nbr,i,hits
	get_players(plrs,nbr,"a")
	for(i=0;i<nbr;i++){
		hits=playerbody[plrs[i]][1]
		set_user_health(plrs[i],get_user_health(plrs[i])-(hits*get_cvar_num("realmod_damage")))
		if(get_cvar_num("realmod_blood")&&hits)
			bleed(plrs[i],hits)
	}
	return PLUGIN_CONTINUE
}

public setup_torso(){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	new plrs[32],nbr,i,hits
	get_players(plrs,nbr,"a")
	for(i=0;i<nbr;i++){
		hits=playerbody[plrs[i]][2]+playerbody[plrs[i]][3]
		set_user_health(plrs[i],get_user_health(plrs[i])-(hits*get_cvar_num("realmod_damage")))
		if(get_cvar_num("realmod_blood")&&hits)
			bleed(plrs[i],hits)
	}
	return PLUGIN_CONTINUE
}

public setup_arms(){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	new plrs[32],nbr,i,hits
	get_players(plrs,nbr,"a")
	for(i=0;i<nbr;i++){
		hits=playerbody[plrs[i]][4]+playerbody[plrs[i]][5]
		set_user_health(plrs[i],get_user_health(plrs[i])-(hits*get_cvar_num("realmod_damage")))
		if(get_cvar_num("realmod_blood")&&hits)
			bleed(plrs[i],hits)
	}
	return PLUGIN_CONTINUE
}

public setup_legs(){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	new plrs[32],nbr,i,hits
	get_players(plrs,nbr,"a")
	for(i=0;i<nbr;i++){
		hits=playerbody[plrs[i]][6]+playerbody[plrs[i]][7]
		set_user_health(plrs[i],get_user_health(plrs[i])-(hits*get_cvar_num("realmod_damage")))
		if(get_cvar_num("realmod_blood")&&hits)
			bleed(plrs[i],hits)
	}
	return PLUGIN_CONTINUE
}

public setup_knife(){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	if(!get_cvar_num("realmod_knife"))
		return PLUGIN_CONTINUE
	new plrs[32],nbr,i
	get_players(plrs,nbr,"a")
	for(i=0;i<nbr;i++){
		set_user_health(plrs[i],get_user_health(plrs[i])-(knifed[plrs[i]]*get_cvar_num("realmod_knife")))
		if(get_cvar_num("realmod_blood")&&knifed[plrs[i]])
			bleed(plrs[i],knifed[plrs[i]])
	}
	return PLUGIN_CONTINUE
}

/************************************************************
* BLEEDING EFFECTS (GORE CODE)
************************************************************/

public bleed(id,num){
	new origin[3],i
	get_user_origin(id,origin)
	for(i=0;i<num;i++)
		fx_bleed(origin)
	return PLUGIN_CONTINUE
}

public fx_bleed(origin[3])
	{
	// Blood spray
	message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
	write_byte(TE_BLOODSTREAM)
	write_coord(origin[0])
	write_coord(origin[1])
	write_coord(origin[2]+10)
	write_coord(random_num(-100,100)) // x
	write_coord(random_num(-100,100)) // y
	write_coord(random_num(-10,10)) // z
	write_byte(70) // color
	write_byte(random_num(50,100)) // speed
	message_end()
	return PLUGIN_CONTINUE
}

/************************************************************
* FIRE EFFECTS (ADMIN FIRE)
************************************************************/

public ignite_effects(skIndex[])   {
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	if (!get_cvar_num("realmod_fire"))
		return PLUGIN_CONTINUE
	new kIndex = skIndex[0]
	if (is_user_alive(kIndex) && onfire[kIndex] )    { 
		new forigin[3],rx,ry,rz
		get_user_origin(kIndex,forigin)
		
		rx = random_num(-30,30) 
		ry = random_num(-30,30) 
		rz = random_num(-30,30)
		
		//TE_SPRAY    
		message_begin(MSG_BROADCAST,SVC_TEMPENTITY) 
		write_byte (120) // Throws a shower of sprites or models 
		write_coord(forigin[0]) // start pos 
		write_coord(forigin[1]) 
		write_coord(forigin[2]-30) 
		write_coord(random_num(-90,90)) // velocity 
		write_coord(random_num(-90,90))  
		write_coord(-100)
		write_short (exhaust) // spr 
		write_byte (4) // count 
		write_byte (4) // speed 
		write_byte (100) //(noise)
		write_byte (5) // (rendermode) 
		message_end()
		
		//Smoke 
		message_begin( MSG_BROADCAST,SVC_TEMPENTITY) 
		write_byte( 5 ) 
		write_coord(forigin[0]+(rx*2)) // coord, coord, coord (position) 
		write_coord(forigin[1]+(ry*2)) 
		write_coord(forigin[2]+100+(rz*2)) 
		write_short( smoke1 )// short (sprite index) 
		write_byte( 60 ) // byte (scale in 0.1's) 
		write_byte( 15 ) // byte (framerate) 
		message_end()
		
		set_task(0.2, "ignite_effects" , 0 , skIndex, 2)       
	}
	return PLUGIN_CONTINUE 
} 

public ignite_player(skIndex[])   {
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	if (!get_cvar_num("realmod_fire"))
		return PLUGIN_CONTINUE
	new kIndex = skIndex[0] 
	if (is_user_alive(kIndex) && onfire[kIndex] )    { 
		new korigin[3] 
		new players[32], inum = 0 
		new pOrigin[3]       
		new kHeath = get_user_health(kIndex) 
		get_user_origin(kIndex,korigin) 
		//create some damage 
		set_user_health(kIndex,kHeath - get_cvar_num("realmod_damage")) 
		message_begin(MSG_ONE, gmsgDamage, {0,0,0}, kIndex) 
		write_byte(30) // dmg_save 
		write_byte(30) // dmg_take 
		write_long(1<<21) // visibleDamageBits 
		write_coord(korigin[0]) // damageOrigin.x 
		write_coord(korigin[1]) // damageOrigin.y 
		write_coord(korigin[2]) // damageOrigin.z 
		message_end() 
		
		//create some sound 
		emit_sound(kIndex,CHAN_ITEM, "ambience/flameburst1.wav", 0.6, ATTN_NORM, 0, PITCH_NORM) 
		
		//Ignite Others 
		if (get_cvar_num("realmod_fireothers")==1)    {        
			get_players(players,inum,"a") 
			for(new i = 0 ;i < inum; ++i)   {                            
				get_user_origin(players[i],pOrigin)              
				if( get_distance(korigin,pOrigin) < 100  )   { 
					if( !onfire[players[i]] )   { 
						new spIndex[2] 
						spIndex[0] = players[i] 
						new pName[32], kName[32]                
						get_user_name(players[i],pName,31) 
						get_user_name(kIndex,kName,31) 
						emit_sound(players[i],CHAN_WEAPON ,"scientist/scream07.wav", 1.0, ATTN_NORM, 0, PITCH_HIGH) 
						client_print(players[i],print_chat,"* [AMXX] You have caught on fire from %s",kName) 
						onfire[players[i]] =1 
						ignite_player(players[i]) 
						ignite_effects(players[i])    
					}                
				} 
			}          
			players[0] = 0 
			pOrigin[0] = 0                
			korigin[0] = 0        
		} 
		//Call Again in 2 seconds       
		set_task(2.0, "ignite_player" , 0 , skIndex, 2)       
	}    
	
	return PLUGIN_CONTINUE 
}

/************************************************************
* REALMOD MENU
************************************************************/

public realmod_menu(id){
	if(!get_cvar_num("realmod"))
		return PLUGIN_CONTINUE
	new menu_body[512]
	copy(menu_body,511,"\yRealmod Menu^n\w^n\%1. Buy Bandage\w^n\%2. Use Bandage\w^n\%3. Buy Fire Extinguisher\w^n\%4. Use Fire Extinguisher\w^n\%5. My Wounds\w^n\%6. Realmod Help\w^n^n0. Exit")
	show_menu(id,(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<9),menu_body)
	return PLUGIN_HANDLED
}

public action_realmod(id,key){
	switch(key){
		case 0: {
			client_cmd(id,"realmod_buy bandage")
		}
		case 1: {
			client_cmd(id,"realmod_use bandage")
		}
		case 2: {
			client_cmd(id,"realmod_buy fire")
		}
		case 3: {
			client_cmd(id,"realmod_use fire")
		}
		case 4: {
			wound_report(id)
		}
		case 5: {
			help(id)
		}
	}
	return PLUGIN_HANDLED
}

public help(id){
	new help_msg[1300] 
	new temp[768] 
	temp = "Realmod has been enabled on this server.^n\ 
	Realmod is a mod that makes games like CS^n\ 
	more realistic. When you are shot, you will begin^n\ 
	to bleed. If you are slashed with a knife, you will^n\ 
	bleed a lot. Health is lost when you bleed. If you^n\ 
	get damaged by a HE Grenade, you will light on fire.^n" 
	add(help_msg,1299,temp) 
	temp = "Be careful of other people that are on fire. If^n\ 
	you stand too close to someone who is on fire, you^n\ 
	will light on fire. If you are shot in the legs, you^n\ 
	will run much slower. The more times you are shot in^n\ 
	the legs, the slower you will run.^n^n" 
	add(help_msg,1299,temp) 
	temp = "To open the Realmod menu type realmod_menu in the^n\ 
	console or bind a key to realmod_menu. From the menu^n\ 
	you can purchase and use bandages and fire^n\ 
	extinguishers. Bandages ($100) will stop the bleeding^n\ 
	on gunshot wounds. Fire extinguishers ($300) stop you^n\
	from burning. Knife wounds cannot be bandaged."
	add(help_msg,1299,temp) 
	show_motd(id,help_msg,"Realmod Help:") 
	return PLUGIN_HANDLED
}

/************************************************************
* PLUGIN INITIALIZE
************************************************************/

public plugin_precache()   { 
	smoke1 = precache_model("sprites/steam1.spr")
	exhaust = precache_model("sprites/muz1.spr")
	precache_sound("ambience/flameburst1.wav")
	precache_sound("scientist/scream07.wav")
	return PLUGIN_CONTINUE 
}

public realmod_init(){
	if(get_cvar_num("realmod")){
		new plrs[32],nbr,i
		set_task(1.0,"setup_speed",50,"",0,"b")
		set_task(3.0,"setup_head",50,"",0,"b")
		set_task(4.75,"setup_torso",50,"",0,"b")
		set_task(1.5,"setup_knife",50,"",0,"b")
		set_task(7.5,"setup_legs",50,"",0,"b")
		set_task(10.0,"setup_arms",50,"",0,"b")
		get_players(plrs,nbr,"a")
		for(i=0;i<nbr;i++){
			new_round(plrs[i])
			help(plrs[i])
		}
	}
	else
	remove_task(50)
}

public plugin_init() {
	register_plugin("AMX Realmod Plugin port by Panais","1.4.2a","Original by Gevurah")
	register_menucmd(register_menuid("Realmod?"),(1<<0)|(1<<1),"vote_count")
	register_menucmd(register_menuid("Realmod Menu"),(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<9),"action_realmod")
	register_concmd("say /wounds","wound_report",0,"- tells you how you have been wounded") //reports # of bandages and wounds
	register_concmd("realmod_use","realmod_use",0,"<bandage|fire> - uses a bandage or fire extinguisher") //buys a bandage
	register_concmd("realmod_buy","realmod_buy",0,"<bandage|fire> - buys a bandage or fire extinguisher") //uses a bandage
	register_concmd("realmod_help","help",0,"- Shows Realmod help")
	register_concmd("realmod_menu","realmod_menu",0,"- opens the realmod menu")
	register_concmd("say /voterealmod","vote_realmod",0,"- starts a vote to enable/disable realmod")
	register_concmd("amx_realmod","realmod_on",ADMIN_CVAR,"<on|off> - turns realmod on and off")
	register_srvcmd("set_realmod","realmod_func") //set_realmod <on|off> : turns realmod on and off
	register_event("ResetHUD","new_round","be")
	register_event("SendAudio","round_start","b","2=%!MRAD_GO","2=%!MRAD_MOVEOUT","2=%!MRAD_LETSGO","2=%!MRAD_LOCKNLOAD")
	register_event("StatusIcon","buy_zone_func","be","2=buyzone")
	register_event("DeathMsg","death","a")
	register_event("Damage","damage_event","be","2!0","3=0","4!0")
	register_event("SendAudio","round_end","a","2=%!MRAD_terwin","2=%!MRAD_ctwin","2=%!MRAD_rounddraw")
	register_event("CurWeapon","weapon_speed","be","1=1") 
	register_cvar("realmod","1",FCVAR_SERVER) //set to one to enable plugin
	register_cvar("amx_buytimeup","0")
	register_cvar("realmod_blood","1") //1 on/0 off
	register_cvar("realmod_damage","1")//higher the more damage bleed does
	register_cvar("realmod_speed","5") //higher the less your max speed is each time your hit
	register_cvar("realmod_fireothers","1") //1 on/0 off
	register_cvar("realmod_fire","1") //1 on/0 off
	register_cvar("realmod_knife","1") //higher the more damage knife bleed does
	register_cvar("realmod_vote","1") //if 1 voting for realmod enabled. if 0 disabled
	gmsgDamage = get_user_msgid("Damage")
}
