Code:
new Handle:Weapons[MAXPLAYERS+1];
/**
* This module's identifier.
*/
new Module:g_modulerecovery;
new g_recoveryUpgradeConfigCache[UpgradeConfigs];
/**
* Register this module.
*/
recovery_Register()
{
// Define all the module's data as layed out by enum ModuleData in project.inc.
new moduledata[ModuleData];
moduledata[ModuleData_Disabled] = false;
moduledata[ModuleData_Hidden] = false;
strcopy(moduledata[ModuleData_FullName], MM_DATA_FULLNAME, "recovery Weapon");
strcopy(moduledata[ModuleData_ShortName], MM_DATA_SHORTNAME, "recovery");
strcopy(moduledata[ModuleData_Description], MM_DATA_DESCRIPTION, "recovery Weapon");
new Module:dependencies[MM_DATA_DEPENDENCIES];
dependencies[0] = g_moduleCore;
dependencies[1] = INVALID_MODULE;
moduledata[ModuleData_Dependencies] = dependencies;
new Module:interlocks[MM_DATA_INTERLOCKS];
interlocks[0] = INVALID_MODULE;
moduledata[ModuleData_Interlocks] = interlocks;
moduledata[ModuleData_TeamLock] = 0;
moduledata[ModuleData_MaxLevel] = 3;
moduledata[ModuleData_Cost] = 15;
moduledata[ModuleData_iCost] = 25;
// Send this array of data to the module manager.
g_modulerecovery = ModuleMgr_Register(moduledata);
// Now register the events we're going to use.
#if defined EVENT_MANAGER
EventMgr_RegisterEvent(g_modulerecovery, "Event_OnEventsRegister", "recovery_OnEventsRegister");
#endif
// Register config file(s) that this module will use.
#if defined CONFIG_MANAGER
ConfigMgr_Register(g_modulerecovery, "recovery_OnConfigReload", "configs/thc_rpg/recovery.txt");
#endif
}
/**
* Register all events here.
*/
public recovery_OnEventsRegister()
{
// Register all the events needed for this module.
EventMgr_RegisterEvent(g_modulerecovery, "Event_OnMapStart", "recovery_OnMapStart");
EventMgr_RegisterEvent(g_modulerecovery, "Event_OnClientDisconnect", "recovery_OnClientDisconnect");
EventMgr_RegisterEvent(g_modulerecovery, "Event_OnConfigsExecuted", "recovery_OnConfigsExecuted");
//EventMgr_RegisterEvent(g_modulerecovery, "Event_OnClientPutInServer", "recovery_OnClientPutInServer");
#if defined PROJECT_GAME_CSS
//EventMgr_RegisterEvent(g_modulerecovery, "Event_PlayerDeath", "recovery_PlayerDeath");
//EventMgr_RegisterEvent(g_modulerecovery, "Event_PlayerHurt", "recovery_PlayerHurt");
EventMgr_RegisterEvent(g_modulerecovery, "Event_RoundEnd", "recovery_RoundEnd");
EventMgr_RegisterEvent(g_modulerecovery, "Event_PlayerSpawn", "recovery_PlayerSpawn");
#endif
}
/**
* All modules and events have been registered by this point. Event priority can be changed here.
*/
public recovery_OnEventsReady()
{
}
#if defined CONFIG_MANAGER
/**
* Called when a registered config file (by this module) is manually reloaded.
*/
public recovery_OnConfigReload(configindex)
{
#if defined LOG_MANAGER
LogMgr_Print(g_modulerecovery, LogType_Normal, "recoveryConfigReload", "Reloaded recovery module's config (index %d)", configindex);
#endif
ConfigMgr_CacheKv(g_modulerecovery, CM_CONFIGINDEX_FIRST, "recoveryModule_ConfigCache");
}
/**
* Read config values
*/
public KvCache:recoveryModule_ConfigCache(Handle:kv, sectionindex, const String:sectionname[])
{
// Read Upgrade config
if(StrEqual(sectionname, "recovery", false))
{
g_recoveryUpgradeConfigCache[UpgradeConfig_Disable] = KvGetNum(kv, "disable");
g_recoveryUpgradeConfigCache[UpgradeConfig_TeamLock] = KvGetNum(kv, "teamlock");
g_recoveryUpgradeConfigCache[UpgradeConfig_MaxLevel] = KvGetNum(kv, "maxlevel");
g_recoveryUpgradeConfigCache[UpgradeConfig_Cost] = KvGetNum(kv, "cost");
g_recoveryUpgradeConfigCache[UpgradeConfig_iCost] = KvGetNum(kv, "icost");
if(g_recoveryUpgradeConfigCache[UpgradeConfig_Disable]==1)
ModuleMgr_Disable(g_modulerecovery);
ModuleMgr_WriteCell(g_modulerecovery, ModuleData_MaxLevel, g_recoveryUpgradeConfigCache[UpgradeConfig_MaxLevel]);
ModuleMgr_WriteCell(g_modulerecovery, ModuleData_Cost, g_recoveryUpgradeConfigCache[UpgradeConfig_Cost]);
ModuleMgr_WriteCell(g_modulerecovery, ModuleData_iCost, g_recoveryUpgradeConfigCache[UpgradeConfig_iCost]);
}
}
#endif
/**
* The map has started.
*/
public recovery_OnMapStart()
{
#if defined CONFIG_MANAGER
ConfigMgr_CacheKv(g_modulerecovery, CM_CONFIGINDEX_FIRST, "recoveryModule_ConfigCache");
#endif
}
public recovery_OnConfigsExecuted()
{
for (new i = 1; i <= MaxClients; i++)
{
Weapons[i] = CreateArray(128);
}
}
public Action:CS_OnCSWeaponDrop(client, weaponIndex)
{
if (!IsValidPlayer(client) || !IsValidEdict(weaponIndex))
return;
new level=GetPlayerUpgradeLevel(client, g_modulerecovery);
if(weaponIndex < 1 || GetClientHealth(client) > 0 || level < 1)
return;
decl String:weapon[64];
GetEdictClassname(weaponIndex, weapon, sizeof(weapon));
if(!StrEqual(weapon, "weapon_c4"))
{
if(level>=1 && (StrEqual(weapon, "weapon_hegrenade") || StrEqual(weapon, "weapon_flashbang") || StrEqual(weapon, "weapon_smokegrenade")))
PushArrayString(Weapons[client], weapon);
if(level>=2 && (StrEqual(weapon, "weapon_glock") || StrEqual(weapon, "weapon_usp") || StrEqual(weapon, "weapon_p228") || StrEqual(weapon, "weapon_deagle") || StrEqual(weapon, "weapon_elite") || StrEqual(weapon, "weapon_fiveseven")))
PushArrayString(Weapons[client], weapon);
if(level>=3)
PushArrayString(Weapons[client], weapon);
}
}
public OnEntityDestroyed(entity)
{
if (!IsValidEdict(entity))
return;
decl String:classname[64];
GetEdictClassname(entity, classname, sizeof(classname));
if (StrContains(classname, "weapon_") == -1)
return;
new client = GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity");
if (client == -1 || !IsValidPlayer(client))
return;
new level=GetPlayerUpgradeLevel(client, g_modulerecovery);
if(IsPlayerAlive(client) || level < 1)
return;
if(level>=1 && (StrEqual(classname, "weapon_hegrenade") || StrEqual(classname, "weapon_flashbang") || StrEqual(classname, "weapon_smokegrenade")))
PushArrayString(Weapons[client], classname);
if(level>=2 && (StrEqual(classname, "weapon_glock") || StrEqual(classname, "weapon_usp") || StrEqual(classname, "weapon_p228") || StrEqual(classname, "weapon_deagle") || StrEqual(classname, "weapon_elite") || StrEqual(classname, "weapon_fiveseven")))
PushArrayString(Weapons[client], classname);
if(level>=3)
PushArrayString(Weapons[client], classname);
}
public recovery_RoundEnd(winner)
{
new Handle:restart_delay=FindConVar("mp_round_restart_delay");
new Float:convar=GetConVarFloat(restart_delay);
if(convar > 0.1)
CreateTimer(convar-0.1, RoundEndPushArray);
else
CreateTimer(0.0, RoundEndPushArray);
}
public Action:RoundEndPushArray(Handle:timer)
{
for(new client=1; client<=MaxClients; client++)
{
if(client < 1 || !IsValidPlayer(client))
continue;
new level=GetPlayerUpgradeLevel(client, g_modulerecovery);
if(!IsPlayerAlive(client) || level < 1)
continue;
for(new x=0; x<=3; x++)
{
new weapons = GetPlayerWeaponSlot(client, x);
if(weapons == -1)
continue;
decl String:weapon[64];
GetEdictClassname(weapons, weapon, sizeof(weapon));
if(level>=1 && (StrEqual(weapon, "weapon_hegrenade") || StrEqual(weapon, "weapon_flashbang") || StrEqual(weapon, "weapon_smokegrenade")))
PushArrayString(Weapons[client], weapon);
if(level>=2 && (StrEqual(weapon, "weapon_glock") || StrEqual(weapon, "weapon_usp") || StrEqual(weapon, "weapon_p228") || StrEqual(weapon, "weapon_deagle") || StrEqual(weapon, "weapon_elite") || StrEqual(weapon, "weapon_fiveseven")))
PushArrayString(Weapons[client], weapon);
if(level>=3)
PushArrayString(Weapons[client], weapon);
}
}
}
public recovery_PlayerSpawn(client)
{
new level=GetPlayerUpgradeLevel(client,g_modulerecovery);
if(level>0)
{
new weapons = GetArraySize(Weapons[client]);
if (!weapons)
return;
for (new x=0; x<=3; x++)
{
new remove_weapon=GetPlayerWeaponSlot(client, x);
if(!IsValidEdict(remove_weapon))
continue;
decl String:remove_weapon_name[64];
GetEdictClassname(remove_weapon, remove_weapon_name, sizeof(remove_weapon_name));
if(StrEqual(remove_weapon_name, "weapon_c4")||StrEqual(remove_weapon_name, "weapon_knife"))
continue;
if(x == 1 && level < 2)
continue;
if(x == 0 && level < 3)
continue;
RemovePlayerItem(client, remove_weapon);
AcceptEntityInput(remove_weapon, "Kill");
}
for (new i, String:weapon[64]; i < weapons; i++)
{
GetArrayString(Weapons[client], i, weapon, sizeof(weapon));
GivePlayerItem(client, weapon);
}
ClearArray(Weapons[client]);
}
}
public recovery_OnClientDisconnect(client)
{
ClearArray(Weapons[client]);
}