Raised This Month: $ Target: $400
 0% 

[SNIPPET][CSGO] Safely remove weapons without crashes


Post New Thread Reply   
 
Thread Tools Display Modes
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
kaeming
Senior Member
Join Date: Nov 2015
Old 10-03-2016 , 12:34   Re: [SNIPPET][CSGO] Safely remove weapons without crashes
Reply With Quote #2

sick!! trying this out later on
__________________
Add me up HERE if you have inquiries regarding server related stuff!
CS:GO Multimod & Jailbreak Servers > I am selling my entire ready to play server, add me up on steam to discuss.

Last edited by kaeming; 10-03-2016 at 12:34.
kaeming is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-03-2016 , 12:49   Re: [SNIPPET][CSGO] Safely remove weapons without crashes
Reply With Quote #3

wou, when this have came up ?
HasEntProp
Bacardi is offline
Indarello
Senior Member
Join Date: Nov 2015
Location: Russia
Old 10-04-2016 , 01:40   Re: [SNIPPET][CSGO] Safely remove weapons without crashes
Reply With Quote #4

Quote:
Originally Posted by Bacardi View Post
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 is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 10-04-2016 , 03:41   Re: [SNIPPET][CSGO] Safely remove weapons without crashes
Reply With Quote #5

Quote:
Originally Posted by Bacardi View Post
wou, when this have came up ?
HasEntProp
SourceMod 1.8
__________________
retired
shavit is offline
Indarello
Senior Member
Join Date: Nov 2015
Location: Russia
Old 10-04-2016 , 02:02   Re: [SNIPPET][CSGO] Safely remove weapons without crashes
Reply With Quote #6

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

Last edited by Indarello; 10-04-2016 at 02:10.
Indarello is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 10-04-2016 , 10:20   Re: [SNIPPET][CSGO] Safely remove weapons without crashes
Reply With Quote #7

Quote:
Originally Posted by Indarello View Post
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.


Last edited by SM9; 10-04-2016 at 10:21.
SM9 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 10-04-2016 , 04:13   Re: [SNIPPET][CSGO] Safely remove weapons without crashes
Reply With Quote #8

Just calling AcceptEntityInput with "Kill" has worked for donkies years without side effects.


Why does this need to be so complex?
__________________
Neuro Toxin is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 10-04-2016 , 12:11   Re: [SNIPPET][CSGO] Safely remove weapons without crashes
Reply With Quote #9

Quote:
Originally Posted by xCoderx View Post
...
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 View Post
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"); 
__________________
coding & free software

Last edited by shanapu; 10-04-2016 at 15:13. Reason: typo
shanapu is offline
Indarello
Senior Member
Join Date: Nov 2015
Location: Russia
Old 10-05-2016 , 09:48   Re: [SNIPPET][CSGO] Safely remove weapons without crashes
Reply With Quote #10

Quote:
Originally Posted by shanapu View Post
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

Last edited by Indarello; 10-05-2016 at 10:04.
Indarello is offline
Reply


Thread Tools
Display Modes

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