Veteran Member
Join Date: Sep 2013
Location: United Kingdom
10-04-2016
, 10:20
Re: [SNIPPET][CSGO] Safely remove weapons without crashes
#2
Quote:
Originally Posted by
Indarello
I still have crashes
here is Bacardi's code:
Spoiler
Code:
#include <sdktools>
#include <cstrike>
public OnPluginStart()
{
RegConsoleCmd("sm_testi", test);
}
public Action:test(client, args)
{
new knife = GetPlayerWeaponSlot(client, CS_SLOT_KNIFE);
new c4 = GetPlayerWeaponSlot(client, CS_SLOT_C4);
new ent;
for(new x = 0; x < GetEntPropArraySize(client, Prop_Send, "m_hMyWeapons"); x++)
{
ent = GetEntPropEnt(client, Prop_Send, "m_hMyWeapons", x);
if(ent == -1 || ent == c4 || ent == knife) continue;
PrintToServer("RemovePlayerItem(%N, %i) %s", client, ent, RemovePlayerItem(client, ent) ? "Success":"Fail");
}
if(knife != -1)
{
PrintToServer("EquipPlayerWeapon(%N, %i)", client, knife);
EquipPlayerWeapon(client, knife);
}
return Plugin_Handled;
}
I try to apply command
Spoiler
Code:
#include <sdktools>
#include <cstrike>
public OnPluginStart()
{
RegConsoleCmd("sm_testi", test);
}
public Action:test(client, args)
{
new knife = GetPlayerWeaponSlot(client, CS_SLOT_KNIFE);
new c4 = GetPlayerWeaponSlot(client, CS_SLOT_C4);
new ent;
for(new x = 0; x < GetEntPropArraySize(client, Prop_Send, "m_hMyWeapons"); x++)
{
ent = GetEntPropEnt(client, Prop_Send, "m_hMyWeapons", x);
if(ent == -1 || ent == c4 || ent == knife) continue;
PrintToServer("RemovePlayerItem(%N, %i) %s", client, ent, SafeRemoveWeapon(client, ent) ? "Success":"Fail");
break;
}
if(knife != -1)
{
PrintToServer("EquipPlayerWeapon(%N, %i)", client, knife);
EquipPlayerWeapon(client, knife);
}
return Plugin_Handled;
}
bool:SafeRemoveWeapon(iClient, iWeapon)
{
if (!IsValidEntity(iWeapon) || !IsValidEdict(iWeapon)) {
return false;
}
if (!HasEntProp(iWeapon, Prop_Send, "m_hOwnerEntity")) {
return false;
}
new iOwnerEntity = GetEntPropEnt(iWeapon, Prop_Send, "m_hOwnerEntity");
if (iOwnerEntity != iClient) {
SetEntPropEnt(iWeapon, Prop_Send, "m_hOwnerEntity", iClient);
}
CS_DropWeapon(iClient, iWeapon, false);
if (HasEntProp(iWeapon, Prop_Send, "m_hWeaponWorldModel")) {
new iWorldModel = GetEntPropEnt(iWeapon, Prop_Send, "m_hWeaponWorldModel");
if (IsValidEdict(iWorldModel) && IsValidEntity(iWorldModel)) {
if (!AcceptEntityInput(iWorldModel, "Kill")) {
return false;
}
}
}
if (!AcceptEntityInput(iWeapon, "Kill"))
{
return false;
}
return true;
}
But still crash, and i realy dont understand his code, because he first remove glock then equip knife that already exist on player
And this code also crash server like Bacari's
But if we change EquipPlayerWeapon(client,
glock ); = No crash
But:
= 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 ( iClient , CS_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" , iReserveAmmo , iClipAmmo , CS_SLOT_KNIFE );
I have also implemented the crash workaround into CSGOItems.
Last edited by SM9; 10-04-2016 at 10:21 .