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

Solved Getting Ammo of Weapon on Ground


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hellmonja
Senior Member
Join Date: Oct 2015
Old 03-10-2018 , 16:54   Getting Ammo of Weapon on Ground
Reply With Quote #1

Hello! Would it be possible to get the amount of ammo inside a weapon's magazine that's on the floor?...
__________________

Last edited by hellmonja; 03-15-2018 at 11:17.
hellmonja is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 03-11-2018 , 20:29   Re: [HELP]Getting Ammo of Weapon on Ground
Reply With Quote #2

Lately trying to use m_iClip to retrieve the ammo. Code basically looks like this:

PHP Code:
new ammo get_pdata_int(iHitEntm_iClip4);
client_print(playerprint_chat"CLIP: %d"ammo);
...
get_user_aiming(playeriHitEntiHitGroupiMaxDistance
So far it's always returning '0' even though I've intentionally left some rounds in the mag. I don't have very in-depth knowledge of AMXX but perhaps 'get_pdata_int' and 'get_user_aiming' take different entity types. I really don't know...
__________________
hellmonja is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-12-2018 , 05:20   Re: [HELP]Getting Ammo of Weapon on Ground
Reply With Quote #3

You should show your real code that you tested.
__________________
klippy is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 03-12-2018 , 09:17   Re: [HELP]Getting Ammo of Weapon on Ground
Reply With Quote #4

Quote:
Originally Posted by KliPPy View Post
You should show your real code that you tested.
Oh! Well here is the whole actual code:
PHP Code:
#include <amxmodx>
#include <cstrike>
#include <engine>
#include <fakemeta>
#include <hamsandwich>

#if AMXX_VERSION_NUM 183
#define MAX_PLAYERS 32
#endif

const XO_CWEAPONBOX 4
new const m_rgpPlayerItems_CWeaponBox[6] =    {34,35,...}

new 
g_hSync

public plugin_init() 
{
    
register_plugin("Thor Weapon Pickup""1.0""EFFx/ProSToTeM@")
    
    
register_forward(FM_CmdStart"CmdStart", ._post=true)
    
    
g_hSync CreateHudSyncObj()
}

public 
CmdStart(playeruserCmdHandlerandomSeed
{
    if(!
is_user_alive(player))
        return

    if(
get_uc(userCmdHandleUC_Buttons) & IN_USE && !(entity_get_int(playerEV_INT_oldbuttons) & IN_USE)) 
    {
        
OnUsePress(player)
    }
}

OnUsePress(player
{    
    
enum _:WboxInfo 
    
{
        
WboxInfo_Ent,
        
WboxInfo_Owner
    
}
    
    new Array:
wboxInfos ArrayCreate(WboxInfo)
    static 
wboxInfo[WboxInfo]
    for(new 
iWbox 0; (iWbox find_ent_by_class(iWbox"weaponbox")) != 0;) 
    {
        
wboxInfo[WboxInfo_Ent] = iWbox
        wboxInfo
[WboxInfo_Owner] = entity_get_edict(iWboxEV_ENT_owner)
        
ArrayPushArray(wboxInfoswboxInfo)
        
        
entity_set_int(iWboxEV_INT_solidSOLID_BBOX)
        
entity_set_edict(iWboxEV_ENT_owner0)
        
RelinkEntity(iWbox)
        
entity_set_vector(iWboxEV_VEC_sizeFloat:{1.00.00.0})
    }
    
    const 
iMaxDistance 100
    
static iHitEntiHitGroup
    get_user_aiming
(playeriHitEntiHitGroupiMaxDistance)
    
    new 
iHitWbox 0
    
if(iHitEnt != 0
    {
        new 
iWeaponID GetWeaponBoxWeaponType(iHitEnt)
        
        static 
szClassName[MAX_PLAYERS]
        
entity_get_string(iHitEntEV_SZ_classnameszClassNamecharsmax(szClassName))
        if(
equal(szClassName"weaponbox")) 
        {
            
iHitWbox iHitEnt
            
            
static szWeapon[MAX_PLAYERS], szOwnerName[MAX_PLAYERS]
            
get_weaponname(iWeaponIDszWeaponcharsmax(szWeapon))
            
get_user_name(wboxInfo[WboxInfo_Owner], szOwnerNamecharsmax(szOwnerName))
            
            
replace(szWeaponcharsmax(szWeapon), "weapon_""")
            
strtoupper(szWeapon)
        }
    }
    
    new 
wboxCount ArraySize(wboxInfos)
    for(new 
0wboxCounti++) 
    {
        static 
wboxInfo[WboxInfo]
        
ArrayGetArray(wboxInfosiwboxInfo)
        new 
iWbox wboxInfo[WboxInfo_Ent]
        
        
entity_set_edict(iWboxEV_ENT_ownerwboxInfo[WboxInfo_Owner])
        
entity_set_int(iWboxEV_INT_solidSOLID_TRIGGER)
        
RelinkEntity(iWbox)
    }
    
    
ArrayDestroy(wboxInfos)
    
    if(
iHitWbox != 0)
    {
        new 
ammo get_pdata_int(iHitWboxm_iClip4);
        
client_print(playerprint_chat"CLIP: %d"ammo);
        
        
PickupWeapon(playeriHitWboxget_pdata_int(iHitWboxm_iClip4))
        
entity_set_int(iHitWboxEV_INT_flagsentity_get_int(iHitWboxEV_INT_flags)|FL_KILLME)
        
        
client_print(playerprint_chat"ENT: %d | AMMO: %d"iHitWboxammo);
    }
}

RelinkEntity(ent
{
    static 
Float:origin[3]
    
entity_get_vector(entEV_VEC_originorigin)
    
entity_set_origin(entorigin)
}

GetWeaponBoxWeaponType(iEnt

    new 
iWeapon
    
for(new i5i++) 
    { 
        
iWeapon get_pdata_cbase(iEntm_rgpPlayerItems_CWeaponBox[i], XO_CWEAPONBOX)
        if(
iWeapon 0
        { 
            return 
cs_get_weapon_id(iWeapon)
        } 
    } 
    
    return 
0


PickupWeapon(playerweaponboxammo
{
    if((
pev(weaponboxpev_flags) & FL_ONGROUND) == 0
        return
    
    new 
slot GetWeaponboxSlot(weaponbox)
    if(!
slot
        return
    
    const 
m_rgpPlayerItems = (1468 4)
    const 
m_rgpPlayerItems_diff = ((1488 4) - m_rgpPlayerItems)
    new 
iWeapon get_pdata_cbase(player, (m_rgpPlayerItems slot), m_rgpPlayerItems_diff)
    new 
wpn_id GetWeaponBoxWeaponType(weaponbox)
    
    if(
iWeapon 0
    {
        if(!
bool:ExecuteHamB(Ham_CS_Item_CanDropiWeapon)) 
            return
                
        new 
szClassName[MAX_PLAYERS]
        
pev(iWeaponpev_classnameszClassNamecharsmax(szClassName))
        
        switch(
wpn_id)
        {
            case 
CSW_GLOCK18CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVENCSW_ELITE:
                
drop_weapons(player2);
            default:
                
drop_weapons(player1);
        }
    }
    
    new 
weapon_name[32];

    
get_weaponname(wpn_idweapon_namecharsmax(weapon_name));
    new 
weapon give_item(playerweapon_name);
    
cs_set_weapon_ammo(weaponammo);
}

GetWeaponboxSlot(weaponbox
{
    const 
SlotCount 6
    
for (new 1SlotCounti++) 
    {
        const 
m_rgpPlayerItems = (136 4)
        const 
m_rgpPlayerItems_diff = ((152 4) - m_rgpPlayerItems)
        if(
get_pdata_cbase(weaponbox, (m_rgpPlayerItems i), m_rgpPlayerItems_diff) > 0
        {
            return 
i
        
}
    }
    
    return 
0
}

drop_weapons(iddropwhat)
{
    
// Get user weapons
    
static weapons[32], numiweaponid
    num 
// reset passed weapons count (bugfix)
    
get_user_weapons(idweaponsnum)
    
    
// Loop through them and drop primaries or secondaries
    
for (0numi++)
    {
        
// Prevent re-indexing the array
        
weaponid weapons[i]
        
        if ((
dropwhat == && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM)) || (dropwhat == && ((1<<weaponid) & SECONDARY_WEAPONS_BIT_SUM)))
        {
            
// Get weapon entity
            
static wname[32]
            
get_weaponname(weaponidwnamecharsmax(wname))

            
// Player drops the weapon and looses his bpammo
            
engclient_cmd(id"drop"wname)
        }
    }

It's the Thor Weapon Pickup that I'm modifying. My problem with the original is that you can still pickup weapons by stepping on them. I've blocked weapon pickups through Ham_Touch but that means I needed another way for the "Press E to Pick-up Weapon" function to work (Thor uses Ham_Touch). So I'm giving the player a new identical weapon and destroying the one on the floor. It's working great so far. Updating the clip on the new weapon with the one on the floor is the last piece of the puzzle...
__________________
hellmonja 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 04:33.


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