Raised This Month: $51 Target: $400
 12% 

[CS GO] Need to help fix code


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ElectricStalin
Member
Join Date: Apr 2017
Old 05-19-2017 , 19:07   [CS GO] Need to help fix code
Reply With Quote #1

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 - 1729: [SM] Exception reported: Property "m_iPrimaryAmmoType" not found (entity 0/worldspawn)
L 05/19/2017 - 1729: [SM] Blaming: deathmatch-ryukzak_cherez_sbros.smx
L 05/19/2017 - 1729: [SM] Call stack trace:
L 05/19/2017 - 1729: [SM] [0] GetEntProp
L 05/19/2017 - 1729: [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.
ElectricStalin is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-19-2017 , 22:28   Re: [CS GO] Need to help fix code
Reply With Quote #2

As the error message says, you're calling GetEntProp with entity ID 0. That's not a weapon.
Fyren is offline
ElectricStalin
Member
Join Date: Apr 2017
Old 05-20-2017 , 05:42   Re: [CS GO] Need to help fix code
Reply With Quote #3

Quote:
Originally Posted by Fyren View Post
As the error message says, you're calling GetEntProp with entity ID 0. That's not a weapon.
Yes, I know. But how can there be taken zero, cause i checked it:
if(clientsWeapon[client][weaponInHand[client]]!=0)

Last edited by ElectricStalin; 05-20-2017 at 06:24.
ElectricStalin is offline
Totenfluch
AlliedModders Donor
Join Date: Jan 2012
Location: Germany
Old 05-20-2017 , 06:24   Re: [CS GO] Need to help fix code
Reply With Quote #4

you should always store the reference to an entity, not the entity itself

https://sm.alliedmods.net/new-api/ha...tIndexToEntRef
https://sm.alliedmods.net/new-api/ha...tRefToEntIndex
__________________
Notable Projects:
Event Item Spawner | Scissors, Rock, Paper for ZephStore
tVip | Smart Link Remover
PLG & GGC - CS:GO Roleplay

and countless more...

I can make a helicopter shoot missles if you want me to...
Totenfluch is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-20-2017 , 12:35   Re: [CS GO] Need to help fix code
Reply With Quote #5

You have a ton of different calls to GetEntProp. The one immediately after that particular if statement is certainly not the one causing the error. You didn't provide enough information.
Fyren 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 00:35.


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