View Single Post
Author Message
correia
Junior Member
Join Date: Mar 2022
Old 02-07-2023 , 12:22   Strange problem I cant fix :( (structs)
Reply With Quote #1

Hello, I recently started doing my first plugin, so I'm pretty new to all this. I began by using structs since it is less confusing and a bit easier to understand the code. Little did I know that structs are a mess in SourcePawn. Basically, I have this snippet of code where the first function works like a charm but the other two never work, they are implanted the same way, just can't get them to work.


Code:
enum eWaitingType
{
	NONE		   = 0,
	WAITING_TAG	   = 1,
	WAITING_W_SEED = 2,
	WAITING_G_SEED = 3,
}

// struct client
enum struct eClient
{
	eWaitingType waitingType;
	int			 TN[2];	   // TD[0] = team, TD[1] = weaponnum

	ArrayList	 arWeaponsT;
	ArrayList	 arWeaponsCT;
	eGlove		 gloveT;
	eGlove		 gloveCT;
	int			 knifeTDefIndex;
	int			 knifeCTDefIndex;
}

enum struct eGlove
{
	int	  gloveDefIndex;
	int	  skinDefIndex;
	float floatValue;
	int	  seed;
}

public int SetGloveSkinDefIndex(int client, int team, int gloveDefIndex, int skinDefIndex)
{
	eClient clientStruct;
	g_arClients.GetArray(client, clientStruct, sizeof(clientStruct));

	if (team == 0)
	{
		return SetGloveSkinDefIndex(client, 2, gloveDefIndex, skinDefIndex) + SetGloveSkinDefIndex(client, 3, gloveDefIndex, skinDefIndex);
	}
	else if (team == 2)
	{
		clientStruct.gloveT.skinDefIndex  = skinDefIndex;
		clientStruct.gloveT.gloveDefIndex = gloveDefIndex;
	}
	else if (team == 3) {
		clientStruct.gloveCT.skinDefIndex  = skinDefIndex;
		clientStruct.gloveCT.gloveDefIndex = gloveDefIndex;
	}
	return g_arClients.SetArray(client, clientStruct, sizeof(clientStruct));
}

//this does not work 
public int SetGloveFloatValue(int client, int team, float floatValue)
{
	eClient clientStruct;
	g_arClients.GetArray(client, clientStruct, sizeof(clientStruct));

	if (team == 0)
	{
		return SetGloveFloatValue(client, 2, floatValue) + SetGloveFloatValue(client, 3, floatValue);
	}
	else if (team == 2)
	{
		clientStruct.gloveT.floatValue = floatValue;
	}
	else if (team == 3)
	{
		clientStruct.gloveCT.floatValue = floatValue;
	}
	return g_arClients.SetArray(client, clientStruct, sizeof(clientStruct));
}

public int SetGloveSeed(int client, int team, int seed)
{
	eClient clientStruct;
	g_arClients.GetArray(client, clientStruct, sizeof(clientStruct));

	if (team == 0)
	{
		return SetGloveSeed(client, 2, seed) + SetGloveSeed(client, 3, seed);
	}
	else if (team == 2)
	{
		clientStruct.gloveT.seed = seed;
	}
	else if (team == 3) {
		clientStruct.gloveCT.seed = seed;
	}
	return g_arClients.SetArray(client, clientStruct, sizeof(clientStruct));
}
Again, I'm new to SouwcePawn so don't blame me for some rookie mistakes )
correia is offline