Raised This Month: $32 Target: $400
 8% 

Getting weapon entity index by classname


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-10-2019 , 09:44   Getting weapon entity index by classname
Reply With Quote #1

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.
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: Stefan Milivojevic#5311
I am inevitable is offline
Whai
Senior Member
Join Date: Jul 2018
Old 07-10-2019 , 10:31   Re: Getting weapon entity index by classname
Reply With Quote #2

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;

__________________

Last edited by Whai; 07-10-2019 at 10:32.
Whai is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-10-2019 , 10:51   Re: Getting weapon entity index by classname
Reply With Quote #3

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;

__________________
I do make plugins upon requests, so hit me up on discord if you're interested: Stefan Milivojevic#5311

Last edited by I am inevitable; 07-10-2019 at 11:07. Reason: nvm lol
I am inevitable is offline
Reply



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 19:58.


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