AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Getting weapon entity index by classname (https://forums.alliedmods.net/showthread.php?t=317384)

I am inevitable 07-10-2019 09:44

Getting weapon entity index by classname
 
Yeah, how?

Is this even possible?

I ran some tests, getting and printing the entity index of my weapons in different contexts, and it seems like they're dynamic.

Whai 07-10-2019 10:31

Re: Getting weapon entity index by classname
 
Try this :
PHP Code:

int GetEntityIndexByClassname(int iClient, const char[] strClassname)
{
    if(!
HasEntProp(iClientProp_Send"m_hActiveWeapon"))
        return -
1;
        
    
int iEntity = -1;
    
    while((
iEntity FindEntityByClassname(iEntitystrClassname)) != INVALID_ENT_REFERENCE)
    {
        if(
iEntity == GetEntPropEnt(iClientProp_Send"m_hActiveWeapon"))
            return 
iEntity;
    }
    
    return -
1;



I am inevitable 07-10-2019 10:51

Re: Getting weapon entity index by classname
 
damn that worked better than I expected.

thanks m8

okay, so here's an updated version of your logic, looping through every weapon the client has:
PHP Code:

stock int GetWeaponEntityIndexByClassname(int iClientchar[] sWeapon_Classname)
{
    for (
int i 04i++)
    {
        
int iWeapon_Entity_Index GetPlayerWeaponSlot(iClienti);
        
        if (
iWeapon_Entity_Index != -1)
        {
            
int iEntity = -1;
            
            while ((
iEntity FindEntityByClassname(iEntitysWeapon_Classname)) != INVALID_ENT_REFERENCE)
            {
                if (
iWeapon_Entity_Index == iEntity)
                    return 
iEntity;
            }
        }
    }
    
    return -
1;




All times are GMT -4. The time now is 06:15.

Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.