Raised This Month: $ Target: $400
 0% 

Setting Weapon Alpha


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 12-29-2009 , 00:16   Setting Weapon Alpha
Reply With Quote #1

If you can answer this question first, then don't bother with the rest of the post.

Are the weapons attached to a player (in CS:S) the same weapons that they hold and shoot?


I ask because I am trying to set the weapons a player is carrying to the same alpha as the player. When the weapon is deployed, it's invisible. But when the weapon is not in the player's hands then it is visible. For example the pistol on the player's leg.

Is there any way to make those invisible as well?

Here's some code. Assume that all the functions and forwarded functions not shown are fully functional. This snippet is coming from ZR, which is huge and has several modules that I don't feel like searching through to post.

This is from my weaponalpha.inc module.

Code:
/**
 * Client has just picked up a weapon.
 * 
 * @param client    The client index.
 * @param weapon    The weapon index.   
 */
WeaponAlphaOnItemPickupPost(client, weapon)
{
    // Get client's current alpha.
    new alpha = ToolsGetEntityAlpha(client);
    
    // Set new alpha on weapons.
    WeaponAlphaApplyWeaponAlpha(weapon, alpha);
}

/**
 * Callback function for Weapon_Drop.
 * Called when a client drops their weapon.
 * 
 * @param client    The client index.
 * @param weapon    The weapon index.
 */
#if defined USE_SDKHOOKS
public Action:WeaponAlphaDrop(client, weapon)
#else
public ZRTools_Action:WeaponAlphaDrop(client, weapon)
#endif
{
    // If weapon isn't a valid entity, then stop.
    if (weapon < MaxClients)
    {
        return;
    }
    
    // Set new alpha on weapons.
    WeaponAlphaApplyWeaponAlpha(weapon, WEAPONALPHA_DEFAULT_VALUE);
}

/**
 * A client's alpha has been changed by the plugin.
 * 
 * @param client    The client index.
 */
WeaponAlphaOnClientAlphaChanged(client, alpha)
{
    // Set new alpha on weapons.
    WeaponAlphaApplyWeaponAlpha(client, alpha);
}

/**
 * Set's the alpha on a client's weapons.
 * 
 * @param entity    If client index is given, alpha will be set on all their weapons.
 *                  If a non-client index is given, alpha will be set on given entity.
 * @param alpha     The alpha to set the weapons to.
 */
WeaponAlphaApplyWeaponAlpha(entity, alpha)
{
    if (entity > MaxClients)
    {
        // Turn rendermode on, on the weapon.
        SetEntityRenderMode(entity, RENDER_TRANSALPHA);
        
        // Set alpha value on the weapon.
        SetEntityRenderColor(entity, _, _, _, alpha);
        
        // Entity alpha has been set, so stop.
        return;
    }
    
    // Get client's list of weapons.
    new weapons[WeaponsSlot];
    WeaponsGetClientWeapons(entity, weapons);
    
    // Loop through array slots and set alpha.
    // x = weapon slot.
    for (new x = 0; x < WEAPONS_SLOTS_MAX; x++)
    {
        // If weapon is invalid, then stop.
        if (weapons[x] == -1)
        {
            continue;
        }
        
        // Turn rendermode on, on the weapon.
        SetEntityRenderMode(weapons[x], RENDER_TRANSALPHA);
        
        // Set alpha value on the weapon.
        SetEntityRenderColor(weapons[x], _, _, _, alpha);
    }
}
Code:
/**
 * Return an array that contains all client's weapon indexes.
 * 
 * @param client    The client index.
 * @param weapons   The weapon index array.
 *                  -1 if no weapon in slot. 
 */
stock WeaponsGetClientWeapons(client, weapons[WeaponsSlot])
{
    // x = Weapon slot.
    for (new x = 0; x < WEAPONS_SLOTS_MAX; x++)
    {
        weapons[x] = GetPlayerWeaponSlot(client, x);
    }
}
__________________
Greyscale is offline
 



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 17:52.


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