Raised This Month: $ Target: $400
 0% 

[SNIPPET][CSGO] Safely remove weapons without crashes


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 10-03-2016 , 12:20   [SNIPPET][CSGO] Safely remove weapons without crashes
Reply With Quote #1

Hello guys, based on some research from Bacardi I have created a stock which will safely remove clients weapons without crashes, this is better than RemovePlayerItem and from current testing my servers have not crashed once yet.

So instead of doing:
PHP Code:
RemovePlayerItem(iClientiWeapon);
AcceptEntityInput(iWeapon"Kill"); 
You would do this:
PHP Code:
SafeRemoveWeapon(iClientiWeapon); // True on success. 

PHP Code:
stock bool SafeRemoveWeapon(int iClientint iWeapon)
{
    if (!
IsValidEntity(iWeapon) || !IsValidEdict(iWeapon)) {
        return 
false;
    }
    
    if (!
HasEntProp(iWeaponProp_Send"m_hOwnerEntity")) {
        return 
false;
    }
    
    
int iOwnerEntity GetEntPropEnt(iWeaponProp_Send"m_hOwnerEntity");
    
    if (
iOwnerEntity != iClient) {
        
SetEntPropEnt(iWeaponProp_Send"m_hOwnerEntity"iClient);
    }
    
    
CS_DropWeapon(iClientiWeaponfalse);
    
    if (
HasEntProp(iWeaponProp_Send"m_hWeaponWorldModel")) {
        
int iWorldModel GetEntPropEnt(iWeaponProp_Send"m_hWeaponWorldModel");
        
        if (
IsValidEdict(iWorldModel) && IsValidEntity(iWorldModel)) {
            if (!
AcceptEntityInput(iWorldModel"Kill")) {
                return 
false;
            }
        }
    }
    
    if (!
AcceptEntityInput(iWeapon"Kill")) {
        return 
false;
    }
    
    return 
true;


Last edited by SM9; 10-03-2016 at 21:03.
SM9 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 18:56.


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