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(player, userCmdHandle, randomSeed)
{
if(!is_user_alive(player))
return
if(get_uc(userCmdHandle, UC_Buttons) & IN_USE && !(entity_get_int(player, EV_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(iWbox, EV_ENT_owner)
ArrayPushArray(wboxInfos, wboxInfo)
entity_set_int(iWbox, EV_INT_solid, SOLID_BBOX)
entity_set_edict(iWbox, EV_ENT_owner, 0)
RelinkEntity(iWbox)
entity_set_vector(iWbox, EV_VEC_size, Float:{1.0, 0.0, 0.0})
}
const iMaxDistance = 100
static iHitEnt, iHitGroup
get_user_aiming(player, iHitEnt, iHitGroup, iMaxDistance)
new iHitWbox = 0
if(iHitEnt != 0)
{
new iWeaponID = GetWeaponBoxWeaponType(iHitEnt)
static szClassName[MAX_PLAYERS]
entity_get_string(iHitEnt, EV_SZ_classname, szClassName, charsmax(szClassName))
if(equal(szClassName, "weaponbox"))
{
iHitWbox = iHitEnt
static szWeapon[MAX_PLAYERS], szOwnerName[MAX_PLAYERS]
get_weaponname(iWeaponID, szWeapon, charsmax(szWeapon))
get_user_name(wboxInfo[WboxInfo_Owner], szOwnerName, charsmax(szOwnerName))
replace(szWeapon, charsmax(szWeapon), "weapon_", "")
strtoupper(szWeapon)
}
}
new wboxCount = ArraySize(wboxInfos)
for(new i = 0; i < wboxCount; i++)
{
static wboxInfo[WboxInfo]
ArrayGetArray(wboxInfos, i, wboxInfo)
new iWbox = wboxInfo[WboxInfo_Ent]
entity_set_edict(iWbox, EV_ENT_owner, wboxInfo[WboxInfo_Owner])
entity_set_int(iWbox, EV_INT_solid, SOLID_TRIGGER)
RelinkEntity(iWbox)
}
ArrayDestroy(wboxInfos)
if(iHitWbox != 0)
{
new ammo = get_pdata_int(iHitWbox, m_iClip, 4);
client_print(player, print_chat, "CLIP: %d", ammo);
PickupWeapon(player, iHitWbox, get_pdata_int(iHitWbox, m_iClip, 4))
entity_set_int(iHitWbox, EV_INT_flags, entity_get_int(iHitWbox, EV_INT_flags)|FL_KILLME)
client_print(player, print_chat, "ENT: %d | AMMO: %d", iHitWbox, ammo);
}
}
RelinkEntity(ent)
{
static Float:origin[3]
entity_get_vector(ent, EV_VEC_origin, origin)
entity_set_origin(ent, origin)
}
GetWeaponBoxWeaponType(iEnt)
{
new iWeapon
for(new i; i < 5; i++)
{
iWeapon = get_pdata_cbase(iEnt, m_rgpPlayerItems_CWeaponBox[i], XO_CWEAPONBOX)
if(iWeapon > 0)
{
return cs_get_weapon_id(iWeapon)
}
}
return 0
}
PickupWeapon(player, weaponbox, ammo)
{
if((pev(weaponbox, pev_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_CanDrop, iWeapon))
return
new szClassName[MAX_PLAYERS]
pev(iWeapon, pev_classname, szClassName, charsmax(szClassName))
switch(wpn_id)
{
case CSW_GLOCK18, CSW_USP, CSW_P228, CSW_DEAGLE, CSW_FIVESEVEN, CSW_ELITE:
drop_weapons(player, 2);
default:
drop_weapons(player, 1);
}
}
new weapon_name[32];
get_weaponname(wpn_id, weapon_name, charsmax(weapon_name));
new weapon = give_item(player, weapon_name);
cs_set_weapon_ammo(weapon, ammo);
}
GetWeaponboxSlot(weaponbox)
{
const SlotCount = 6
for (new i = 1; i < SlotCount; i++)
{
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(id, dropwhat)
{
// Get user weapons
static weapons[32], num, i, weaponid
num = 0 // reset passed weapons count (bugfix)
get_user_weapons(id, weapons, num)
// Loop through them and drop primaries or secondaries
for (i = 0; i < num; i++)
{
// Prevent re-indexing the array
weaponid = weapons[i]
if ((dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM)) || (dropwhat == 2 && ((1<<weaponid) & SECONDARY_WEAPONS_BIT_SUM)))
{
// Get weapon entity
static wname[32]
get_weaponname(weaponid, wname, charsmax(wname))
// Player drops the weapon and looses his bpammo
engclient_cmd(id, "drop", wname)
}
}
}
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
but that means I needed another way for the "Press E to Pick-up Weapon" function to work (Thor uses
). 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...