AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   OFFSET_PRIMARYWEAPON issue (https://forums.alliedmods.net/showthread.php?t=164633)

Doc-Holiday 08-13-2011 23:42

OFFSET_PRIMARYWEAPON issue
 
Ok so i have tried a few different things and cant figure out what it actually returns.

ive tried using ID offset to get CSW and that didnt work. so... what does it actually return? i cant seem to find much info on it. and the only way i have an example of it being used is..

PHP Code:

stock StripUserWeapons(id)
{
    new 
iC4Ent get_pdata_cbase(idOFFSET_C4_SLOT);
    
    if( 
iC4Ent )
    {
        
set_pdata_cbase(idOFFSET_C4_SLOTFM_NULLENT);
    }

    
strip_user_weapons(id);
    
give_item(id"weapon_knife");
    
set_pdata_int(idOFFSET_PRIMARYWEAPON0);

    if( 
iC4Ent )
    {
        
set_pev(idpev_weaponspev(idpev_weapons) | (1<<CSW_C4));
        
set_pdata_cbase(idOFFSET_C4_SLOTiC4Ent);
        
cs_set_user_bpammo(idCSW_C41);
        
cs_set_user_plant(id1);
    }
    return 
PLUGIN_HANDLED;



Exolent[jNr] 08-14-2011 02:53

Re: OFFSET_PRIMARYWEAPON issue
 
Seems to be just a boolean value, only for showing if player has a primary weapon or not.

Doc-Holiday 08-14-2011 04:33

Re: OFFSET_PRIMARYWEAPON issue
 
Quote:

Originally Posted by Exolent[jNr] (Post 1532165)
Seems to be just a boolean value, only for showing if player has a primary weapon or not.

ahh Thanks.. i figured out how to use a define to do the check i needed.

PHP Code:

#define PRIMARY_WEAPON ((1 << CSW_SCOUT) | (1 << CSW_XM1014) | (1 << CSW_MAC10) | (1 << CSW_AUG) | (1 << CSW_UMP45) | (1 << CSW_SG550) | (1 << CSW_GALIL) | (1 << CSW_FAMAS) | (1 << CSW_AWP) | (1 << CSW_MP5NAVY) | (1 << CSW_M249) | (1 << CSW_M3) | (1 << CSW_M4A1) | (1 << CSW_TMP) | (1 << CSW_G3SG1) | (1 << CSW_SG552) | (1 << CSW_AK47) | (1 << CSW_P90))
#define SECONDARY_WEAPON ((1 << CSW_P228) | (1 << CSW_ELITE) | (1 << CSW_FIVESEVEN) | (1 << CSW_USP) | (1 << CSW_GLOCK18) | (1 << CSW_DEAGLE))
#define NO_BPAMMO ((1<<CSW_HEGRENADE)|(1<<CSW_SMOKEGRENADE)|(1<<CSW_FLASHBANG)|(1<<CSW_KNIFE)|(1<<CSW_C4))



new currentPrimaryAmmo;
                    new 
currentSecondaryAmmo;
                    new 
maxPrimaryAmmo;
                    new 
maxSecondaryAmmo;
                    new 
szWeapon[32], iWeapons[32], iWeaponNum;
        
                    
get_user_weapons(targetiWeaponsiWeaponNum);
                    
                    for(new 
0iWeaponNumi++)
                    {
                        
get_weaponname(iWeapons[i], szWeaponcharsmax(szWeapon));
                        
                        if(
NO_BPAMMO & (<< iWeapons[i]))
                            continue;
                        
                        if(
PRIMARY_WEAPON & (<< iWeapons[i]))
                        {
                            
client_print(idprint_chat"Player's Primary weapon: %s"szWeapon);
                            
client_print(targetprint_chat"Your Primary weapon: %s"szWeapon);
                            
g_iTargetPrimaryWeapon[target] = iWeapons[i];
                            
currentPrimaryAmmo cs_get_user_bpammo(targetiWeapons[i]);
                            
maxPrimaryAmmo g_WeaponBPAmmo[iWeapons[i]];
                        }
                        if(
SECONDARY_WEAPON & (<< iWeapons[i]))
                        {
                            
client_print(idprint_chat"Player's Secondary weapon: %s"szWeapon);
                            
client_print(targetprint_chat"Your Secondary weapon: %s"szWeapon);
                            
g_iTargetSecondaryWeapon[target] = iWeapons[i];
                            
currentSecondaryAmmo cs_get_user_bpammo(targetiWeapons[i]);
                            
maxSecondaryAmmo g_WeaponBPAmmo[iWeapons[i]];
                        }
                    } 


ConnorMcLeod 08-14-2011 05:48

Re: OFFSET_PRIMARYWEAPON issue
 
Set on 1, this offset prevents players from pigking up armoury_entity weapons, but not weaponbox.

Doc-Holiday 08-14-2011 05:53

Re: OFFSET_PRIMARYWEAPON issue
 
Quote:

Originally Posted by ConnorMcLeod (Post 1532212)
Set on 1, this offset prevents players from pigking up armoury_entity weapons, but not weaponbox.

Thanks for more info. I was trying to findsomething that let me check primary weapon ammo but i think that bit check is better.. allows me to filter both secondary/primary weapons while not getting ones with out BP...

to allow my engineer to give ammo.

ConnorMcLeod 08-14-2011 06:10

Re: OFFSET_PRIMARYWEAPON issue
 
So you don't know how to check which weapons a player have.
You can check get_pdata_cbase(id, with slots offsets (m_rgpPlayerItems), you will retrieve the first weapon a player have on each slot.
Then, if there is another weapon in this slot, the next weapon is linked to first weapon with weapon offset m_pNext (cbase), etc...

Player offsets, linux diff = 5
367-372 m_rgpPlayerItems[MAX_ITEM_TYPES] // 6 (cbase)
367 is not used, 368 is first slot.

Weapon offset, linux extra offset = 4
#define m_pNext 42

So, suppose i have an ak47 (entity 53 for example), a m4a1 (ent 57), a deagle (60), a glock (63) and an usp (65)

get_pdata_cbase(id, m_rgpPlayerItems_1 /* 368 */, 5) == 53
get_pdata_cbase(53, m_pNext, 4) == 57
get_pdata_cbase(57, m_pNext, 4) == 0 or -1 depending on linux/windows

get_pdata_cbase(id, m_rgpPlayerItems_2 /* 369 */, 5) == 60
get_pdata_cbase(60, m_pNext, 4) == 63
get_pdata_cbase(63, m_pNext, 4) == 65
get_pdata_cbase(65, m_pNext, 4) == 0 or -1 depending on linux/windows


Same method is used to know which weapons are in a weaponbox (if no plugin/addon change normal cs behavior, only 1 weapon is stored in a weaponbox).


For player weapons, you can also check pev_weapons bitsum, but it can, if you don't check it at the right moment (during strip process for example) return false results, should be reliable though, it's the way amxx uses for get_user_weapons and has_user_weapon natives.


All times are GMT -4. The time now is 03:27.

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