AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [SNIPPET][CSGO] Safely remove weapons without crashes (https://forums.alliedmods.net/showthread.php?t=288614)

SM9 10-03-2016 12:20

[SNIPPET][CSGO] Safely remove weapons without crashes
 
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;



kaeming 10-03-2016 12:34

Re: [SNIPPET][CSGO] Safely remove weapons without crashes
 
sick!! trying this out later on

Bacardi 10-03-2016 12:49

Re: [SNIPPET][CSGO] Safely remove weapons without crashes
 
wou, when this have came up ? :)
HasEntProp

Indarello 10-04-2016 01:40

Re: [SNIPPET][CSGO] Safely remove weapons without crashes
 
Quote:

Originally Posted by Bacardi (Post 2458874)
wou, when this have came up ? :)
HasEntProp

Latest unstable, development build have it
http://www.sourcemod.net/downloads.p...h=master&all=1
Code:

stock bool HasEntProp(int entity, PropType type, const char[] prop)
{
        if (type == Prop_Data) {
                return (FindDataMapInfo(entity, prop) != -1);
        }

        if (type != Prop_Send) {
                return false;
        }

        char cls[64];
        if (!GetEntityNetClass(entity, cls, sizeof(cls))) {
                return false;
        }

        return (FindSendPropInfo(cls, prop) != -1);
}


Indarello 10-04-2016 02:02

Re: [SNIPPET][CSGO] Safely remove weapons without crashes
 
I still have crashes
here is Bacardi's code:
Spoiler

I try to apply command
Spoiler

But still crash, and i realy dont understand his code, because he first remove glock then equip knife that already exist on player
Spoiler

And this code also crash server like Bacari's
But if we change EquipPlayerWeapon(client, glock); = No crash
But:
Spoiler

= No crush
Now I realy dont understand nothing

shavit 10-04-2016 03:41

Re: [SNIPPET][CSGO] Safely remove weapons without crashes
 
Quote:

Originally Posted by Bacardi (Post 2458874)
wou, when this have came up ? :)
HasEntProp

SourceMod 1.8 :)

Neuro Toxin 10-04-2016 04:13

Re: [SNIPPET][CSGO] Safely remove weapons without crashes
 
Just calling AcceptEntityInput with "Kill" has worked for donkies years without side effects.


Why does this need to be so complex?

SM9 10-04-2016 10:20

Re: [SNIPPET][CSGO] Safely remove weapons without crashes
 
Quote:

Originally Posted by Indarello (Post 2459028)
I still have crashes
here is Bacardi's code:
Spoiler

I try to apply command
Spoiler

But still crash, and i realy dont understand his code, because he first remove glock then equip knife that already exist on player
Spoiler

And this code also crash server like Bacari's
But if we change EquipPlayerWeapon(client, glock); = No crash
But:
Spoiler

= No crush
Now I realy dont understand nothing

What are you trying to do?

Take a look at these examples.

First include CSGOItems. Download here: https://bitbucket.org/SM91337/csgo-items/overview
PHP Code:

#include <csgoitems> 

If you want to remove all weapons except the clients knife you can do this:
PHP Code:

CSGOItems_RemoveAllWeapons(iClientCS_SLOT_KNIFE); 

If you want to remove just his knife, (without removing Zeus unlike other methods)
PHP Code:

CSGOItems_RemoveKnife(iClient); 

If you want to give the client a weapon (This function also auto equips knives and also with this function you don't have to remove the clients previous weapons, it will automatically handle that for you, though I suggest not giving knives since they will trigger a ban)
PHP Code:

CSGOItems_GiveWeapon(iClient"weapon_glock"); 

Same as above, but lets specify reserve and clip and also have it switch to his knife after.
PHP Code:

int iReserveAmmo 30;
int iClipAmmo 2;
CSGOItems_GiveWeapon(iClient"weapon_glock"iReserveAmmoiClipAmmoCS_SLOT_KNIFE); 

I have also implemented the crash workaround into CSGOItems.

:)

shanapu 10-04-2016 12:11

Re: [SNIPPET][CSGO] Safely remove weapons without crashes
 
Quote:

Originally Posted by xCoderx (Post 2458853)
...
So instead of doing:
PHP Code:

RemovePlayerItem(iClientiWeapon);
AcceptEntityInput(iWeapon"Kill"); 

You would do this:
PHP Code:

SafeRemoveWeapon(iClientiWeapon); // True on success. 

...

Quote:

Originally Posted by Neuro Toxin (Post 2459047)
Just calling AcceptEntityInput with "Kill" has worked for donkies years without side effects.
...

Some time ago a read in a thread to use SDKHooks_DropWeapon instead of RemovePlayerItem or CS_DropWeapon. But unfortunately I can't find it or remember the advanced of using SDKHooks instead. Also, I never recognized a crash related to RemovePlayerItem.

PHP Code:

SDKHooks_DropWeapon(clientweaponNULL_VECTORNULL_VECTOR); 
AcceptEntityInput(iWeapon"Kill"); 


Indarello 10-05-2016 09:48

Re: [SNIPPET][CSGO] Safely remove weapons without crashes
 
Quote:

Originally Posted by shanapu (Post 2459180)
Some time ago a read in a thread to use SDKHooks_DropWeapon instead of RemovePlayerItem or CS_DropWeapon. But unfortunately I can't find it or remember the advanced of using SDKHooks instead. Also, I never recognized a crash related to RemovePlayerItem.

PHP Code:

SDKHooks_DropWeapon(clientweaponNULL_VECTORNULL_VECTOR); 
AcceptEntityInput(iWeapon"Kill"); 


Still crash
Code:

#include <sdkhooks>

public OnPluginStart()
{
    RegConsoleCmd("sm_testi", test);
}

public Action:test(client, args)
{
        new glock = GetPlayerWeaponSlot(client, 1);
        new knife = GetPlayerWeaponSlot(client, CS_SLOT_KNIFE);
       
        SDKHooks_DropWeapon(client, glock, NULL_VECTOR, NULL_VECTOR);
        EquipPlayerWeapon(client, knife);

        return Plugin_Handled;
}

But if we will pick pistol or buy, there will be no crash


All times are GMT -4. The time now is 18:56.

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