After playing around with SourceMod, I've found a couple of really useful functions within sdktools that allow me to see what weapon is in which slot (GetPlayerWeaponSlot) and to remove weapons that weapon from it (RemovePlayerItem). Using these functions I was able to write my own function that removes a weapon from the specified slot.
PHP Code:
/**
* Removes weapon from the specified client's slot.
* ChadlyTubbs
*/
public bool:RemoveWeaponFromSlot(client, slot)
{
//get the entity id of the weapon in the client's slot specified
new bool:isRemoved;
new weapon_entid = GetPlayerWeaponSlot(client,slot);
//attempt to retrieve the weapon's entity id from the slot..
if(weapon_entid >= 0)
{
//get the classname of the weapon
new String:weapon_classname[32];
GetEdictClassname(weapon_entid, weapon_classname, 32);
//attempt to remove the weapon
isRemoved = RemovePlayerItem(client,weapon_entid);
RemoveEdict(weapon_entid);
if(isRemoved)
{
PrintToConsole(client,"Removed %s (entid:%d) from slot %d",weapon_classname,weapon_entid,slot);
}
else
{
PrintToConsole(client,"Could NOT remove %s (entid:%d) from slot %d",weapon_classname,weapon_entid,slot);
}
}
else
{
isRemoved = false;
PrintToConsole(client,"No weapon to remove from slot %d",slot);
}
return isRemoved;
}
This is close to what I'm trying to accomplish. What I'm really going for is a function like
PHP Code:
/**
* Removes the specified weapon type from the client
*/
public bool:RemoveWeapon(client, String:weapon_classname)
The only problem with this, is that HL2DM can store multiple weapons in the same slot. For example slot0 can potentially store up to 3 weapons: weapon_crowbar, weapon_stunstick, and weapon_physcannon. Using the GetPlayerWeaponSlot function, I can only retrieve 1 at a time. Is there anyway to loop through the weapons stored in the slot?
As for dropping the weapon on the ground, I guess the process would be:
1) Temporarily storing the amount of ammo in the weapon.
2) Getting the remove weapon function above to work.
3) Spawning a new weapon of the same type with the same ammo in front of the player on the ground.
I could still use a push in the right direction for this type of function.
Again, any help is most definitely appreciated. Thanks.
EDIT: Bug Report [Disregard. Error on my part. See next edit.]
This code actually causes glitch where some of the models of the removed weapons will appear to "float" around the user; even after the player dies and respawns. I filed a bug report and attached my testing plugin to it. Here's the link:
http://bugs.alliedmods.net/index.php...s&task_id=1521
EDIT: Solution [duh]
RemoveEdict after RemovePlayerItem fixed the issue. The code above has been updated.