 |
|
Member
|

12-11-2020
, 15:12
Re: Get weapon's entity id, from weapon ID
|
#4
|
Quote:
Originally Posted by GasmoN
Thank you, this is how I fixed this
At the end of every round, I added pf_check_weapon_life()
If anyone know any better way, I would like to hear it.
PHP Code:
public zp_fw_gamemodes_end() // Round just ended.
{
pf_check_weapon_life();
}
stock pf_check_weapon_life()
{
new i;
for(i = 1; i <= g_maxplayers; i++)
{
if(is_user_alive(i))
{
pf_check_user_inventory(i);
}
}
}
stock pf_check_user_inventory(id)
{
new weapons[32], num
get_user_weapons(id, weapons, num)
for (new i = 0; i < num; i++)
{
if (weapons[i] > 0)
{
new iEnt = pf_find_weapon_ent_id(id, weapons[i]);
new iEntLife = entity_get_int(iEnt, ENT_INDENT_LIFE);
switch(iEntLife)
{
case ENT_KEY_LIFE_ONEROUND:
{
fm_strip_user_gun(id, weapons[i]);
}
}
}
}
}
stock pf_find_weapon_ent_id(id, CSW_ID)
{
static ent, szClassname[24]; ent = -1;
get_weaponname(CSW_ID, szClassname, charsmax(szClassname));
while ((ent = find_ent_by_class(ent, szClassname)) > 0 && entity_get_edict(ent, EV_ENT_owner) != id) { }
return (ent > 0 && entity_get_edict(ent, EV_ENT_owner) == id) ? ent:0;
}
|
Okay, so just a quick update. This started crashing server if there is more than 2 players. So after a while, I found another solution (I am writing this just in case someone need something like this).
The stock below is tested with 32/32 players while all of them had weapon that will be removed at the end of the round.
PHP Code:
stock pf_check_weapon_life()
{
new iEntCount = entity_count();
new iEntOwner;
new iEntWeaponID;
new iEnt;
for (iEnt = 0; iEnt < iEntCount; iEnt++)
{
if(!is_valid_ent(iEnt))
continue;
iEntOwner = entity_get_edict(iEnt, EV_ENT_owner)
if(is_user_alive(iEntOwner))
{
switch(entity_get_int(iEnt, ENT_INDENT_LIFE))
{
case ENT_KEY_LIFE_ONEROUND:
{
iEntWeaponID = cs_get_weapon_id(iEnt);
if(get_pdata_cbase(iEntOwner, m_pActiveItem) == iEnt)
ExecuteHamB(Ham_Weapon_RetireWeapon, iEnt);
if(ExecuteHamB(Ham_RemovePlayerItem, iEntOwner, iEnt))
{
user_has_weapon(iEntOwner, iEntWeaponID, 0);
ExecuteHamB(Ham_Item_Kill, iEnt);
}
}
}
}
}
}
|
|
|
|