/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <fakemeta>
#include <engine>
#include <csx>
#define PLUGIN "Decoy Grenade"
#define VERSION "1.0.4"
#define AUTHOR "Kia"
// ===============================================================================
// Editing begins here
// ===============================================================================
// Time in Seconds how long the decoy grenade should make sounds //Meddig jatsza le a hangot
#define DECOY_FULL_TIME 14.5
// Time in Seconds when decoy should start after default explosion //Meddig lehesen hallani a dobasi hangot
#define DECOY_FIRST_DELAY 1.5
// Maximum delay between two sounds //Meddig lehessen hallani a 2. hangot
#define DECOY_MAX_DELAY 1.6
// Price of Decoy Grenade in $ // Mennyibe keruljon a granat
#define DECOY_PRICE 500
// ===============================================================================
// and stops here. DO NOT MODIFY BELOW UNLESS YOU KNOW WHAT YOU'RE DOING
// ===============================================================================
// ===============================================================================
// Variables
// ===============================================================================
#define TASK_ID_SOUND 9919
/* Consts */
new const g_szWeaponConsts[][] =
{
0, // NULL
CSW_P228,
0, // SHIELD
CSW_SCOUT,
0, // HEGRENADE
CSW_XM1014,
0, // C4
CSW_MAC10,
CSW_AUG,
0, // SMOKEGRENADE
CSW_ELITE,
CSW_FIVESEVEN,
CSW_UMP45,
CSW_SG550,
CSW_GALIL,
CSW_FAMAS,
CSW_USP,
CSW_GLOCK18,
CSW_AWP,
CSW_MP5NAVY,
CSW_M249,
CSW_M3,
CSW_M4A1,
CSW_TMP,
CSW_G3SG1,
0, // FLASHBANG
CSW_DEAGLE,
CSW_SG552,
CSW_AK47,
0, // KNIFE
CSW_P90
}
new const g_szWeaponSounds[sizeof(g_szWeaponConsts)][] =
{
"",
"p228-1.wav",
"",
"scout_fire-1.wav",
"",
"xm1014-1.wav",
"",
"mac10-1.wav",
"aug-1.wav",
"",
"elite_fire.wav",
"fiveseven-1.wav",
"ump45-1.wav",
"sg550-1.wav",
"galil-1.wav",
"famas-1.wav",
"usp1.wav",
"glock18-1.wav",
"awp1.wav",
"mp5-1.wav",
"m249-1.wav",
"m3-1.wav",
"m4a1-1.wav",
"tmp-1.wav",
"g3sg1-1.wav",
"",
"deagle-1.wav",
"sg552-1.wav",
"ak47-1.wav",
"",
"p90-1.wav"
}
/* Integer */
new g_iEnt[33]
new g_iEventIDSmoke
/* Boolean */
new bool:g_bHasDecoy[33]
/* Floats */
new Float:g_flDecoyOrigin[33][3]
/* Strings */
new g_szWeaponSound[33][33]
new HandleFwdPlaybackEvent;
new Array:HandleGrenadePlayerIdQueue;
// ===============================================================================
// plugin_init
// ===============================================================================
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
/* ClCmds */
register_clcmd("say /decoy", "ClCmd_Decoy")
register_clcmd("say_team /decoy", "ClCmd_Decoy")
/* Stuff */
g_iEventIDSmoke = engfunc(EngFunc_PrecacheEvent, 1, "events/createsmoke.sc")
}
// ===============================================================================
// client_putinserver - Called when a player joins the Server
// ===============================================================================
public client_putinserver(id)
{
g_iEnt[id] = 0
g_bHasDecoy[id] = false
}
// ===============================================================================
// ClCmd_Decoy - Called when a player types /decoy in the chat
// ===============================================================================
public ClCmd_Decoy(id)
{
// If we have not enough money or if we already have a decoy grenade, block the payment.
if(cs_get_user_money(id) < DECOY_PRICE || g_bHasDecoy[id] || !is_user_alive(id))
return PLUGIN_HANDLED
// If the player has no Smokegrenade, give him one.
if(!(user_has_weapon(id, CSW_SMOKEGRENADE)))
give_item(id, "weapon_smokegrenade")
// Taking the price
cs_set_user_money(id, cs_get_user_money(id) - DECOY_PRICE, 1)
// Telling the plugin that the player has a decoy.
g_bHasDecoy[id] = true
return PLUGIN_HANDLED
}
// ===============================================================================
// Thanks to Arkshine
// ===============================================================================
public grenade_throw( player, grenade, weaponId )
{
if( weaponId == CSW_SMOKEGRENADE && g_bHasDecoy[player] )
{
if( HandleGrenadePlayerIdQueue == Invalid_Array )
{
HandleGrenadePlayerIdQueue = ArrayCreate();
}
ArrayPushCell( HandleGrenadePlayerIdQueue, player );
if( !HandleFwdPlaybackEvent )
{
HandleFwdPlaybackEvent = register_forward( FM_PlaybackEvent, "OnPlaybackEvent" );
}
}
}
public OnPlaybackEvent( const flags, const client, const eventIndex, const Float:delay, const Float:origin[3] )
{
new player = ArrayGetCell( HandleGrenadePlayerIdQueue, 0 );
if( HandleFwdPlaybackEvent && g_iEventIDSmoke == eventIndex && g_bHasDecoy[player] )
{
ArrayDeleteItem( HandleGrenadePlayerIdQueue, 0 );
if( !ArraySize( HandleGrenadePlayerIdQueue ) )
{
ArrayDestroy( HandleGrenadePlayerIdQueue );
unregister_forward( FM_PlaybackEvent, HandleFwdPlaybackEvent );
HandleFwdPlaybackEvent = 0;
}
g_flDecoyOrigin[player] = origin
set_task(DECOY_FIRST_DELAY, "ExecuteDecoy", player)
}
}
// ===============================================================================
// ExecuteDecoy - Responsible for playing the sounds etc.
// ===============================================================================
public ExecuteDecoy(id)
{
// Getting the players weapon
new iWeapon = get_user_weapon(id)
// Finding the right sound of the weapon
for(new i = 0; i < sizeof(g_szWeaponSounds); i++)
{
//if(equali(iWeapon, g_szWeaponRealnames[i]))
if(iWeapon == g_szWeaponConsts[i][0])
formatex(g_szWeaponSound[id], charsmax(g_szWeaponSound), g_szWeaponSounds[i])
else
continue
}
// Starting the sounds
StartWeaponSounds(id)
}
// ===============================================================================
// StartWeaponSounds - Playing the sounds
// ===============================================================================
public StartWeaponSounds(id)
{
// Creating a Entity which plays the sound
new iEnt = create_entity("info_target")
g_iEnt[id] = iEnt
// Setting its position
entity_set_origin(g_iEnt[id], g_flDecoyOrigin[id])
// Playing the first sound
set_task(0.1, "PlayASound", id + TASK_ID_SOUND)
// Setting the time when it should stop playing sounds
set_task(DECOY_FULL_TIME, "StopDecoy", id)
}
public PlayASound(id)
{
// Getting the actual player
id -= TASK_ID_SOUND
// Getting full path
new szSoundPath[64]
formatex(szSoundPath, charsmax(szSoundPath), "weapons/%s", g_szWeaponSound[id])
// Playing the Sound
emit_sound(g_iEnt[id], CHAN_ITEM, szSoundPath, VOL_NORM, ATTN_NONE, 0, PITCH_NORM)
// Preparing next one
set_task(random_float(0.1, DECOY_MAX_DELAY), "StartWeaponSounds", id)
}
public StopDecoy(id)
{
// Removing Task which is playing sounds
if(task_exists(id + TASK_ID_SOUND))
remove_task(id + TASK_ID_SOUND)
// Disabling Decoy for player
g_bHasDecoy[id] = false
// Remove the Entity
remove_entity(g_iEnt[id])
}