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

Solved How do I get the AWP number?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vortex.
AlliedModders Donor
Join Date: Jan 2017
Location: OnGameFrame()
Old 04-28-2017 , 16:26   How do I get the AWP number?
Reply With Quote #1

When freeze time is over, A similar message will pass:

INFO -> 4 CT AWP, 1 T AWP

Like this. How get AWP number?
__________________

Last edited by vortex.; 07-19-2017 at 14:29.
vortex. is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 04-28-2017 , 17:43   Re: How do I get the AWP number?
Reply With Quote #2

Maybe there is an more effektiv way, but I would spontanly solve it like:

Loop all players by teams -> check players primary weapon slot for awp -> count numbers

edit:
something like

PHP Code:
int AWPct;
int AWPt;

for (
int i 1<= MaxClientsi++) 
{
    
char weaponname[32];
    
int weaponindex GetPlayerWeaponSlot(clientCS_SLOT_PRIMARY);
    if (
weaponindex != -1)
    {
        
GetEntityClassname(indexweaponnamesizeof(weaponname));
        
        if(
StrContains(weaponname"awp"))
        {
            if (
GetClientTeam(i) == CS_TEAM_CT)
            {
                
AWPct++;
            }
            else
            {
                
AWPt++;
            }
        }
    }

not tested
__________________
coding & free software

Last edited by shanapu; 04-28-2017 at 17:46.
shanapu is offline
wwahgnerbp
Member
Join Date: Mar 2013
Location: Earth, Solar System
Old 04-28-2017 , 17:54   Re: How do I get the AWP number?
Reply With Quote #3

Code:
char WeaponOfPlayer[MAXPLAYERS+1][64];

for (int i=1; i <= MAXPLAYERS+1; i++)
{
     weaponindex = GetPlayerWeaponSlot(i, 0);
     GetEntityClassname(weaponindex, WeaponOfPlayer[i], sizeof(WeaponOfPlayer[]));
}
So you have the weapons of players. If you want to check if it's AWP do something like this:

Code:
if(StrEqual(WeaponOfPlayer[client], "weapon_awp", true))
{
      //Do something here
}
You can put that inside a loop too

Code:
for (int i=1; i <= MAXPLAYERS+1; i++)
{
     if(StrEqual(WeaponOfPlayer[i], "weapon_awp", true))
     {
           //Do something here
     }
}
I posted this after reading shanapu's post. He hadn't posted something yet then I started to write this. When I finished this he already had finished his code. (facepalm)

By the way you need to reset the counters at round end if you use shanapu's code

Last edited by wwahgnerbp; 04-28-2017 at 18:07. Reason: shanapu
wwahgnerbp is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-29-2017 , 04:51   Re: How do I get the AWP number?
Reply With Quote #4

It is a lot more efficient to enumerate through all weapon_awp entities and check their owner.
__________________
asherkin is offline
vortex.
AlliedModders Donor
Join Date: Jan 2017
Location: OnGameFrame()
Old 04-29-2017 , 05:46   Re: How do I get the AWP number?
Reply With Quote #5

Quote:
Originally Posted by asherkin View Post
It is a lot more efficient to enumerate through all weapon_awp entities and check their owner.
Send me example please?

I'm trying different ways.
__________________
vortex. is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 04-29-2017 , 22:37   Re: How do I get the AWP number?
Reply With Quote #6

Quote:
Originally Posted by asherkin View Post
It is a lot more efficient to enumerate through all weapon_awp entities and check their owner.
something like this?
PHP Code:
int AWPct 0;
int AWPt 0;
int iWeapons = -1;

while((
iWeapons FindEntityByClassname(iWeapons"weapon_awp")) != -1)
{
    
int iOwner = -1;
    if (
iOwner GetEntPropEnt(iWeaponsProp_Send"m_hOwnerEntity") != -1)
    {
        if (
GetClientTeam(iOwner) == CS_TEAM_CT)
        {
            
AWPct++;
        }
        else
        {
            
AWPt++;
        }
    }

__________________
coding & free software
shanapu is offline
Reply


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 00:40.


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