Raised This Month: $32 Target: $400
 8% 

[CS:GO] GivePlayerItem, EquipPlayerWeapon item duplication


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Indarello
Senior Member
Join Date: Nov 2015
Location: Russia
Old 12-28-2018 , 12:31   [CS:GO] GivePlayerItem, EquipPlayerWeapon item duplication
Reply With Quote #1

if somebody give weapon which client already can pick up and equip it:
new zweapon = GivePlayerItem(client, "weapon_glock");
if(zweapon != -1 ) EquipPlayerWeapon(i, zweapon);

you will need to clear duplication in this table
Code:
g_iMyWeapons = FindSendPropInfo("CBaseCombatCharacter", "m_hMyWeapons");

for (new i = 0; i <= 128; i += 4)
{
	new weaponentity = -1;
	new String:weaponname[32];
	weaponentity = GetEntDataEnt2(client, (g_iMyWeapons + i));
	if ( IsValidEdict(weaponentity) )
	{
		GetEdictClassname(weaponentity, weaponname, sizeof(weaponname));
		PrintToChatAll("[%d][%d][%s]", i, weaponentity, weaponname);
	}
}
So maybe i found a solution for this problem
https://forums.alliedmods.net/showthread.php?t=281687
When :
Code:
    if(knife != -1)
    {
        PrintToServer("EquipPlayerWeapon(%N, %i)", client, knife);
        EquipPlayerWeapon(client, knife);
    }
he make duplication in table m_hMyWeapons
This duplication can make server freeze until you restart server manualy

Here is my solution, may not work with grenades:
Code:
int zweapon = GivePlayerItem(client, "weapon_glock");
if(zweapon != -1) EquipPlayerWeapon2(client, zweapon);

bool EquipPlayerWeapon2(int client, int weapon)
{
	for (int i = 0; i <= 128; i += 4)
	{
		int weaponentity = -1;
		weaponentity = GetEntDataEnt2(client, (g_iMyWeapons + i));
		if (weaponentity == weapon)
		{
			return false;
		}
	}
	for (int i = 0; i <= 128; i += 4)
	{
		int weaponentity = -1;
		weaponentity = GetEntDataEnt2(client, (g_iMyWeapons + i));
		if (!IsValidEdict(weaponentity))
		{
			SetEntDataEnt2(client, (g_iMyWeapons + i), weapon);
			return true;
		}
	}
	return false;
}

Last edited by Indarello; 12-29-2018 at 06:01.
Indarello is offline
Reply



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 11:46.


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