View Single Post
Author Message
dubbeh
Senior Member
Join Date: Jul 2007
Old 09-05-2007 , 09:56   Stripping guns & setting active weapon to knife
Reply With Quote #1

Stuck trying to find a working way to do this

I've tried so many diffrent methods with no luck (always has some type of bug)

Currently I'm doing it this way but i can't get the knife set as active weapon (RemoveAllItems & GiveNameItem made my teammate nearly die from laughter when he could see 4 dancing knives on his side )

Code:
UTIL_RemoveAllButKnife (client)
{
    static iWeaponSlot = 0, iEntIndex = 0;
    decl String:szClassName[64] = "";
    
    for (iWeaponSlot = 0; iWeaponSlot <= (32 * 4); iWeaponSlot += 4)
    {
        iEntIndex = GetEntDataEnt (client, (g_iMyWeapons + iWeaponSlot));
        if (iEntIndex != 0)
        {
            GetEdictClassname (iEntIndex, szClassName, sizeof (szClassName));
            if (!strcmp (szClassName, "worldspawn", false))
                continue;
            if (!strcmp (szClassName, "weapon_knife", false) || !strcmp (szClassName, "knife", false))
            {
                SetEntData (client, g_iActiveWeapon, iEntIndex);
                continue;
            }

            RemovePlayerItem (client, iEntIndex);
            RemoveEdict (iEntIndex);
        }
    }
}

/* called at on plugin start */
UTIL_SetupOffsets ()
{
    g_iMyWeapons = FindSendPropOffs ("CBaseCombatCharacter", "m_hMyWeapons");
    if (g_iMyWeapons == -1)
        SetFailState ("[YGMSM] Error - Unable to get offset for CBaseCombatCharacter::m_hMyWeapons");
    
    g_iActiveWeapon = FindSendPropOffs ("CBaseCombatCharacter", "m_hActiveWeapon");
    if (g_iActiveWeapon == -1)
        SetFailState ("[YGMSM] Error - Unable to get offset for CBaseCombatCharacter::m_hActiveWeapon");
}
It manages to strip all the weapons but doesnt set the knife as active weapon & makes everyone look like jesus

Thanks for any help

dubbeh
__________________
SM Plugins - dubbeh.net - Plugin requests are welcome
dubbeh is offline