Raised This Month: $12 Target: $400
 3% 

Total weapons count on the map


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gold Fish
Senior Member
Join Date: Mar 2020
Old 03-03-2021 , 11:28   Total weapons count on the map
Reply With Quote #1

Hello, how can I calculate the total number of weapons on the map at the start of each round, as well as take into account the moment that the admins can issue weapons and the player can transfer weapons from another map? How can you make it easier?

Maybe you know in which plugin this feature has already been implemented?

Possibly through the "item pickup" event, but it is triggered on every event when the player picks up a weapon
And if you count the weapons through the "item pickup" after the spawn, then how best to know that the player did not pick up the weapon on the map?

sorry for my English


Note: all weapons on the map have been removed through a stripper, and the count of weapons is kept strictly

Last edited by Gold Fish; 03-03-2021 at 11:34.
Gold Fish is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 03-03-2021 , 14:30   Re: Total weapons count on the map
Reply With Quote #2

Well first you have to consider that the weapon_*_spawn entities can be picked more than once, unless you have set it's count do "1" either.

You can do a loop through all "weapon_*" entities and make a count.

But this includes prop/explosives , throwables and melees aswell

So maybe you need be more specific in the filters.
__________________

Last edited by Marttt; 03-03-2021 at 14:30.
Marttt is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 03-05-2021 , 09:07   Re: Total weapons count on the map
Reply With Quote #3

if you want to get weapons created by map itself, check on loop "i = 65, i < 2048" if entity classname contains weapon_ then try getting its prop m_iHammerID. if value is bigger than 0, then for sure it created by map.

Last edited by farawayf; 03-05-2021 at 09:08.
farawayf is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-05-2021 , 14:13   Re: Total weapons count on the map
Reply With Quote #4

Quote:
Originally Posted by farawayf View Post
if you want to get weapons created by map itself, check on loop "i = 65, i < 2048" if entity classname contains weapon_ then try getting its prop m_iHammerID. if value is bigger than 0, then for sure it created by map.
- I don't know what is topic game, but in some game weapons reset, those not have hammerid's.
- You can use FindEntityByClassname
PHP Code:
// All entities "*"
    
int a = -1;
    while((
FindEntityByClassname(a"*")) != -1)
    {
        
GetEntityClassname(a,classnamesizeof(classname));
        
PrintToServer("%s"classname);
    }

//  All weapon_ entities "weapon_*"
     
= -1
    
while((FindEntityByClassname(a"weapon_*")) != -1)
    {
        
GetEntityClassname(a,classnamesizeof(classname));
        
PrintToServer("%s"classname);
    } 
__________________
Do not Private Message @me
Bacardi is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-05-2021 , 14:48   Re: Total weapons count on the map
Reply With Quote #5

sry double post
I don't fully understand OP question.
So I throw some things what you can try.


Do you want track specific entity ?
- Use EntIndexToEntRef(entity) <-> EntRefToEntIndex(ref)
- This work like clients userid, if you not get valid entity index by using ref id then it is deleted.

Some other examples.
PHP Code:
#include <sdktools>
#include <sdkhooks>

// Weapon m_iState
#define WEAPON_NOT_CARRIED                0    // Weapon is on the ground
#define WEAPON_IS_CARRIED_BY_PLAYER        1    // This client is carrying this weapon.
#define WEAPON_IS_ACTIVE                2    // This client is carrying this weapon and it's the currently held weapon

char state[][] = {
    
"WEAPON_NOT_CARRIED",
    
"WEAPON_IS_CARRIED_BY_PLAYER",
    
"WEAPON_IS_ACTIVE"
};

public 
void OnPluginStart()
{
    
HookEventEx("player_spawn"player_spawn);
}

//    Moment when player spawn
// + Player get default spawn weapons, after death or game restart (cs:s = pistol, knife)
// + Player is carrying weapons from previous rounds
// - Player not pick weapon at this moment (cs:s = c4 or weapons on ground)
//
public void player_spawn(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));

    
int m_hMyWeapons GetEntPropArraySize(clientProp_Send"m_hMyWeapons");
    
int entity;
    
char classname[64];

    for(
int x 0m_hMyWeaponsx++)
    {
        
entity GetEntPropEnt(clientProp_Send"m_hMyWeapons"x);
        
        if(
entity == -1) continue;

        
GetEntityClassname(entityclassnamesizeof(classname));

        
PrintToServer("m_hMyWeapons %i %i - %s %N %s",
                                            
entity,
                                            
EntIndexToEntRef(entity),
                                            
classname,
                                            
GetEntPropEnt(entityProp_Send"m_hOwnerEntity"),
                                            
state[GetEntProp(entityProp_Send"m_iState")]);
    }
}

// Moment, entity created
// + all weapons created on map (cs:s = round restart)
//
public void OnEntityCreated(int entity, const char[] classname)
{
    if(
StrContains(classname"weapon_"true) != 0) return;

    
RequestFrame(nextframeEntIndexToEntRef(entity));
}


// Moment, entity created -> next frame delay
// + weapon created and player owns/carrying it (cs:s = c4 at round start, weapon buy, give weapon_*)
// - Player not pick weapon from ground at this moment
//
public void nextframe(int ref)
{
    
int entity EntRefToEntIndex(ref);
    
    if(!
IsValidEntity(entity)) return;

    
int owner GetEntPropEnt(entityProp_Send"m_hOwnerEntity");
    
    if(
owner == -1) return;

    
char classname[64];
    
GetEntityClassname(entityclassnamesizeof(classname));

    
//PrintToServer("nextframe %N %s", owner, classname);
    
PrintToServer("nextframe %i %i - %s %N %s",
                                        
entity,
                                        
EntIndexToEntRef(entity),
                                        
classname,
                                        
owner,
                                        
state[GetEntProp(entityProp_Send"m_iState")]);

__________________
Do not Private Message @me
Bacardi is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 03-05-2021 , 15:43   Re: Total weapons count on the map
Reply With Quote #6

Quote:
Originally Posted by Bacardi View Post
- You can use FindEntityByClassname
there is no difference between using it or using loop, because in your example you anyways getting its classname.
farawayf is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 03-06-2021 , 09:36   Re: Total weapons count on the map
Reply With Quote #7

Just use on round start FindEntityByClassname as of above.

Use:
int owner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");

owner will be equal to -1 if the weapon is not held by any player.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 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 15:49.


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