Im making a plugin, which allows the player to carry several weapons. So I have tried a lot of ways, but this is most simple. Here is my code:
Code:
public Action:EventItemPickup2(client, entity)
{
char buffer[64];
GetEntityClassname(entity,buffer,sizeof(buffer));
if(weaponInHand[client]==0)
{
weaponInHand[client]=1;
}
for(int i=0;i<weaponCount;i++)
{
if((!weapPick[i]) && (entList[i]==entity))
{
weapPick[i]=true;
new ammotype = GetEntProp(entity, Prop_Send, "m_iPrimaryAmmoType");
SetEntProp(client, Prop_Send, "m_iAmmo", weaponReserve(buffer), _, ammotype);
SetEntProp(entity, Prop_Send, "m_iClip1", weaponClip(buffer));
clientsWeapon[client][weaponInHand[client]]=entity;
return Plugin_Continue;
}
else if((weapPick[i]) && (clientsWeapon[client][i]==entity))
{
new ammotype = GetEntProp(entity, Prop_Send, "m_iPrimaryAmmoType");
SetEntProp(client, Prop_Send, "m_iAmmo", weaponAmmo[client][i], _, ammotype);
}
}
return Plugin_Continue;
}
public Action:OnEntityTouch(entity, other)
{
if((IsValidPlayer(other)) && (isWeapon(entity)))
{
float pos[3]={0.0,0.0,-100.0};
int j=1;
while(clientsWeapon[other][j]!=0)
{
j++;
}
clientsWeapon[other][j]=entity;
PrintToChat(other,"Weapon %i was added to your backpack",entity);
if(weaponInHand[other]==0)
{
weaponInHand[other]=1;
}
else
{
TeleportEntity(entity, pos, NULL_VECTOR, NULL_VECTOR);
}
}
}
void scrollBackpack(int client)
{
char buffer[40];
float pos[3]={0.0,0.0,-100.0};
PrintToChat(client,"Номер оружия в руках %i", weaponInHand[client]);
int nextWeap=weaponInHand[client]+1;
if((weaponInHand[client]==35) || (clientsWeapon[client][weaponInHand[client]]==0))
nextWeap=1;
PrintToChat(client,"Номер следующего оружия в руках %i", nextWeap);
if(clientsWeapon[client][weaponInHand[client]]!=0)
{
new ammotype = GetEntProp(clientsWeapon[client][weaponInHand[client]], Prop_Send, "m_iPrimaryAmmoType");
weaponAmmo[client][weaponInHand[client]]=GetEntProp(client, Prop_Send, "m_iAmmo", _, ammotype);
CS_DropWeapon(client, clientsWeapon[client][weaponInHand[client]], true, true);
PrintToChat(client,"Оружие %i сброшено", clientsWeapon[client][weaponInHand[client]]);
TeleportEntity(clientsWeapon[client][weaponInHand[client]], pos, NULL_VECTOR, NULL_VECTOR);
SetEntPropEnt(clientsWeapon[client][nextWeap], Prop_Send, "m_hOwnerEntity", client);
2477: EquipPlayerWeapon(client, clientsWeapon[client][nextWeap]);
ammotype = GetEntProp(weaponAmmo[client][nextWeap], Prop_Send, "m_iPrimaryAmmoType");
SetEntProp(client, Prop_Send, "m_iAmmo", weaponAmmo[client][weaponInHand[client]], _, ammotype);
}
weaponInHand[client]=nextWeap;
}
It works very strangely. I have changed it a lot of times, but it gives in logs the same exeption:
L 05/19/2017 - 17
2
9: [SM] Exception reported: Property "m_iPrimaryAmmoType" not found (entity 0/worldspawn)
L 05/19/2017 - 17
2
9: [SM] Blaming: deathmatch-ryukzak_cherez_sbros.smx
L 05/19/2017 - 17
2
9: [SM] Call stack trace:
L 05/19/2017 - 17
2
9: [SM] [0] GetEntProp
L 05/19/2017 - 17
2
9: [SM] [1] Line 2477
It put weapon in a "backpack" correctly, but didn't scroll it. I hope for your help, mb I missed something.