To avoid a pential XY problem, here is my initial issue.
I've got a DM plugin, but when players select a P2000 and have an usp-s in its loadout, plugin when calling
PHP Code:
GivePlayerItem(client, "weapon_p2000");
actually gives ans usp-s.
Note that this was working great a few CS GO update ago...
I though of correcting this by checking the m_iItemDefinitionIndex and see if it matches the one I expect.
If it don't, I remove (kill) the weapon, Create a weapon using CreateEntityByName (this is to avoid having the game searching into the player loadout) and then I equip the player.
But created weapon is wierd. CreateEntityByName ("weapon_p2000") actually creates a P200, who sounds like a deagle, shot deagles bullet but at P2000 rate and accuracy.
Do you know what I'm doing wrong?
Here is the actual function:
PHP Code:
stock weapons_GivePlayerItem(clientIndex, String:weaponEntityName[], weaponId=NO_WEAPON_SELECTED)
{
new origTeam = CS_TEAM_NONE;
if(weaponId > NO_WEAPON_SELECTED)
origTeam = player_FakeTeamSwitch(clientIndex, weapons_GetSkinTeam(weaponId));
if(origTeam != weapons_GetSkinTeam(weaponId) && origTeam != CS_TEAM_NONE)
g_aWeapons_PlayerEquipment[clientIndex][weapons_PlayerEquipment_IsTeamInverted] = true;
new weaponEntity = GivePlayerItem(clientIndex, weaponEntityName);
// Some hacking to bypass inventory
if(weaponId > NO_WEAPON_SELECTED && weaponId != weapons_FindIdFromEntity(weaponEntity))
{
weapons_RemovePlayerWeapon(weaponEntity, clientIndex);
// Weapon is removed on a timer to prevent crash
CreateTimer(0.2, weapons_Timer_DelayedWeaponKill, EntIndexToEntRef(weaponEntity));
weaponEntity = CreateEntityByName(weaponEntityName);
DispatchSpawn(weaponEntity);
EquipPlayerWeapon(clientIndex, weaponEntity);
// For some reason clip and ammo are not initialized, fix this
weapons_RefillClip(EntIndexToEntRef(weaponEntity), weaponId);
weapons_GiveAmmo(clientIndex, weaponEntity, weapons_GetAmmoMax(weaponId));
}
if(weaponId > NO_WEAPON_SELECTED)
player_FakeTeamSwitch(clientIndex, origTeam);
weapons_TagEntity(weaponEntity, weaponId, clientIndex, .isCT = GetClientTeam(clientIndex) == CS_TEAM_CT);
g_aWeapons_PlayerEquipment[clientIndex][weapons_PlayerEquipment_IsTeamInverted] = false;
return weaponEntity;
}