AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ H3LP ] Loop through client weapons (https://forums.alliedmods.net/showthread.php?t=303708)

CrazY. 12-18-2017 10:25

[ H3LP ] Loop through client weapons
 
Hello, how I can loop through player weapons? I need the entity of the weapon, not its index corresponding to the CSW *.

NiHiLaNTh 12-19-2017 07:33

Re: [ H3LP ] Loop through client weapons
 
Code:

#include <amxmodx>
#include <fakemeta>

#include <cstrike> // cs_get stuff

public plugin_init()
{
        register_clcmd("say /showwpn", "test");
}

public test(player)
{
        static entity
        for (new i = CS_WEAPONSLOT_PRIMARY; i <= CS_WEAPONSLOT_C4; i++)
        {
                // m_rgpPlayerItems array pointing to weapon ents in each slot
                entity = get_ent_data_entity(player, "CBasePlayer", "m_rgpPlayerItems", i);
       
                while (entity > 0)
                {
                        server_print("ENT: %d | WEAPON ID: %d | CLIP: %d", entity, cs_get_weapon_id(entity), cs_get_weapon_ammo(entity));
               
                        // points to the next weapon in the SAME slot (if the weapon does exist)
                        entity = get_ent_data_entity(entity, "CBasePlayerItem", "m_pNext");
                }
        }
}


Depresie 12-19-2017 14:26

Re: [ H3LP ] Loop through client weapons
 
Btw the code above is only for 1.8.3

CrazY. 12-19-2017 14:43

Re: [ H3LP ] Loop through client weapons
 
No problems since I'm using the 1.8.3 version.


All times are GMT -4. The time now is 11:41.

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