/* AMXX Mod script. 
* 
*Ported by Sp4rt4n
* (c) Copyright 2003, f117bomb 
* This file is provided as is (no warranties). 
*/  

#include <amxmodx> 
#include <amxmisc> 
#include <fun>

/* 
* Sets a player on fire with effects. Users can catch others on fire by standing next to them.
* Usage: amx_fire <authid, nick or #userid> 
* 
*/ 

new gmsgDamage,smoke,mflash
new onfire[33]

public ignite_effects(skIndex[])   {
	new kIndex = skIndex[0]
		
	if (is_user_alive(kIndex) && onfire[kIndex] )    {
		new korigin[3] 
		get_user_origin(kIndex,korigin)
				
		//TE_SPRITE - additive sprite, plays 1 cycle
		message_begin( MSG_BROADCAST,SVC_TEMPENTITY) 
		write_byte( 17 ) 
		write_coord(korigin[0])  // coord, coord, coord (position) 
		write_coord(korigin[1])  
		write_coord(korigin[2]) 
		write_short( mflash ) // short (sprite index) 
		write_byte( 20 ) // byte (scale in 0.1's)  
		write_byte( 200 ) // byte (brightness)
		message_end()
		
		//Smoke
		message_begin( MSG_BROADCAST,SVC_TEMPENTITY,korigin)
		write_byte( 5 )
		write_coord(korigin[0])// coord coord coord (position) 
		write_coord(korigin[1])
		write_coord(korigin[2])
		write_short( smoke )// short (sprite index)
		write_byte( 20 ) // byte (scale in 0.1's)
		write_byte( 15 ) // byte (framerate)
		message_end()
		
		set_task(0.2, "ignite_effects" , 0 , skIndex, 2)		
	}	
	else    {
		if( onfire[kIndex] )   {
			emit_sound(kIndex,CHAN_AUTO, "scientist/scream21.wav", 0.6, ATTN_NORM, 0, PITCH_HIGH)
			onfire[kIndex] = 0
		}
	}	
	return PLUGIN_CONTINUE
}

public ignite_player(skIndex[])   {
	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 - 10)
		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				
		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(0,3,"* [ATAC] OH! NO! %s has caught %s on fire!",kName,pName)
					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
}


public fire_player(id,level,cid) { 
	if (!cmd_access(id,level,cid,2)) 
		return PLUGIN_HANDLED 
	
	new arg[32]
	read_argv(1,arg,31)
	
	new victim = cmd_target(id,arg,7) 
	if (!victim) 
		return PLUGIN_HANDLED 

	new skIndex[2]
	skIndex[0] = victim	
	new name[32]
	get_user_name(victim,name,31) 
	
	onfire[victim] = 1
	ignite_effects(skIndex)
	ignite_player(skIndex)
		
	new adminname[32]  
        get_user_name(id,adminname,31)  
	switch(get_cvar_num("amx_show_activity"))   { 
	         case 2:   client_print(0,print_chat,"ADMIN %s: set %s on fire.",adminname,name) 
	         case 1:   client_print(0,print_chat,"ADMIN: set %s on fire.",name) 
	} 
		
	console_print(id,"Client ^"%s^" has been set on fire...",name) 
	
	return PLUGIN_HANDLED 
}  

public plugin_precache()   {  
	mflash = precache_model("sprites/muzzleflash.spr") 
	smoke = precache_model("sprites/steam1.spr")
	precache_sound("ambience/flameburst1.wav")
	precache_sound("scientist/scream21.wav")
	precache_sound("scientist/scream07.wav")
	
	return PLUGIN_CONTINUE 
} 

public plugin_init() {  
   register_plugin("Admin Fire","1.0.0","f117bomb")  
   register_concmd("amx_fire","fire_player",ADMIN_SLAY,"<authid, nick or #userid>")  
   gmsgDamage = get_user_msgid("Damage")
   
   return PLUGIN_CONTINUE  
} 

