Raised This Month: $ Target: $400
 0% 

Solved Get weapon's entity id, from weapon ID


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
GasmoN
Member
Join Date: Jul 2014
Old 12-11-2020 , 15:12   Re: Get weapon's entity id, from weapon ID
Reply With Quote #4

Quote:
Originally Posted by GasmoN View Post
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(
1<= g_maxplayersi++)
    {
        if(
is_user_alive(i))
        {
            
pf_check_user_inventory(i);
        }
    }
}

stock pf_check_user_inventory(id
{
    new 
weapons[32], num
    get_user_weapons
(idweaponsnum)
    
    for (new 
0numi++) 
    {
        if (
weapons[i] > 0
        {
            new 
iEnt pf_find_weapon_ent_id(idweapons[i]);
            new 
iEntLife entity_get_int(iEntENT_INDENT_LIFE);
            
            switch(
iEntLife)
            {
                case 
ENT_KEY_LIFE_ONEROUND:
                {
                    
fm_strip_user_gun(idweapons[i]);
                }
            }            
        }
    }
}

stock pf_find_weapon_ent_id(idCSW_ID)
{
    static 
entszClassname[24]; ent = -1;
    
get_weaponname(CSW_IDszClassnamecharsmax(szClassname));
    
    while ((
ent find_ent_by_class(entszClassname)) > && entity_get_edict(entEV_ENT_owner) != id) { }
    return (
ent && entity_get_edict(entEV_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 0iEnt iEntCountiEnt++)
    {
        if(!
is_valid_ent(iEnt))
        continue;
        
        
iEntOwner entity_get_edict(iEntEV_ENT_owner)
        
        if(
is_user_alive(iEntOwner))
        {
            switch(
entity_get_int(iEntENT_INDENT_LIFE))
            {
                case 
ENT_KEY_LIFE_ONEROUND:
                {
                    
iEntWeaponID cs_get_weapon_id(iEnt);
                    
                    if(
get_pdata_cbase(iEntOwnerm_pActiveItem) == iEnt)
                    
ExecuteHamB(Ham_Weapon_RetireWeaponiEnt);
                    
                    if(
ExecuteHamB(Ham_RemovePlayerItemiEntOwneriEnt))
                    {
                        
user_has_weapon(iEntOwneriEntWeaponID0);
                        
ExecuteHamB(Ham_Item_KilliEnt);
                    }                    
                }
            }
        }
    }

GasmoN is offline
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode