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

Strange problem I cant fix :( (structs)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
correia
Junior Member
Join Date: Mar 2022
Old 02-07-2023 , 12:33   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
s1m0nSS
New Member
Join Date: Feb 2023
Old 02-07-2023 , 14:21   Re: Strange problem I cant fix :( (structs)
Reply With Quote #2

Hello,
just store everything in a JSON file and read from it.
s1m0nSS is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 02-07-2023 , 17:36   Re: Strange problem I cant fix :( (structs)
Reply With Quote #3

Quote:
Originally Posted by s1m0nSS View Post
Hello,
just store everything in a JSON file and read from it.
...do not listen this
__________________
Do not Private Message @me
Bacardi is offline
correia
Junior Member
Join Date: Mar 2022
Old 02-07-2023 , 18:52   Re: Strange problem I cant fix :( (structs)
Reply With Quote #4

Quote:
Originally Posted by Bacardi View Post
...do not listen this
haha, I know. In this case, is methodmaps better?
correia is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 02-08-2023 , 00:36   Re: Strange problem I cant fix :( (structs)
Reply With Quote #5

Lets focus on one thing a time.

You can find more info from here [TUT] SourcePawn Scripting - Tips, Basics to Advanced


enum struct
https://wiki.alliedmods.net/SourcePa...x#Enum_Structs




Don't know where you have copy that code, but you are not showing
Code:
g_arClients
...part.

But if I have to guess, it is global variable ArrayList, and you are going to push one of enum struck into array.


Also, eGlove struct appear later than eClient, what use eGlove, this will give you compile error.
You need code eGlove above eClient struct. (Need to be right order)




I have not done this complex code before. And I'm not sure do ArrayList inside enum stuct even work after saving in array...
Maybe if simplified coding :/

Try this. I maybe have created ArrayList g_arClients in wrong order. Not sure.
Code:
eClient size 15
[SM] Plugin test.smx reloaded successfully.
sm_test
clientStruct.gloveT.skinDefIndex = 2
clientStruct.gloveT.gloveDefIndex = 2
clientStruct.gloveT.floatValue = 2.200000
clientStruct.gloveT.seed = 2

PHP Code:

ArrayList g_arClients
;

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

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

// 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;
}

public 
int SetGloveSkinDefIndex(int clientint teamint gloveDefIndexint skinDefIndex)
{
    
eClient clientStruct;
    
g_arClients.GetArray(clientclientStructsizeof(clientStruct));

    if (
team == 0)
    {
        return 
SetGloveSkinDefIndex(client2gloveDefIndexskinDefIndex) + SetGloveSkinDefIndex(client3gloveDefIndexskinDefIndex);
    }
    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(clientclientStructsizeof(clientStruct));
}

public 
int SetGloveFloatValue(int clientint teamfloat floatValue)
{
    
eClient clientStruct;
    
g_arClients.GetArray(clientclientStructsizeof(clientStruct));

    if (
team == 0)
    {
        return 
SetGloveFloatValue(client2floatValue) + SetGloveFloatValue(client3floatValue);
    }
    else if (
team == 2)
    {
        
clientStruct.gloveT.floatValue floatValue;
    }
    else if (
team == 3)
    {
        
clientStruct.gloveCT.floatValue floatValue;
    }
    return 
g_arClients.SetArray(clientclientStructsizeof(clientStruct));
}

public 
int SetGloveSeed(int clientint teamint seed)
{
    
eClient clientStruct;
    
g_arClients.GetArray(clientclientStructsizeof(clientStruct));

    if (
team == 0)
    {
        return 
SetGloveSeed(client2seed) + SetGloveSeed(client3seed);
    }
    else if (
team == 2)
    {
        
clientStruct.gloveT.seed seed;
    }
    else if (
team == 3) {
        
clientStruct.gloveCT.seed seed;
    }
    return 
g_arClients.SetArray(clientclientStructsizeof(clientStruct));
}

public 
void OnPluginStart()
{
    
PrintToServer("eClient size %i"sizeof(eClient));

    
g_arClients = new ArrayList(sizeof(eClient), MAXPLAYERS);
    
RegConsoleCmd("sm_test"test);
}

public 
Action test(int clientint args)
{

    
SetGloveSkinDefIndex(client222);
    
SetGloveFloatValue(client22.2);
    
SetGloveSeed(client22);



    
eClient clientStruct;
    
g_arClients.GetArray(clientclientStructsizeof(clientStruct));

    
PrintToServer("clientStruct.gloveT.skinDefIndex = %i\nclientStruct.gloveT.gloveDefIndex = %i\n\
                clientStruct.gloveT.floatValue = %f\nclientStruct.gloveT.seed = %i"
,
                
clientStruct.gloveT.skinDefIndex,
                
clientStruct.gloveT.gloveDefIndex,
                
clientStruct.gloveT.floatValue,
                
clientStruct.gloveT.seed);

    return 
Plugin_Handled;

__________________
Do not Private Message @me

Last edited by Bacardi; 02-08-2023 at 00:38.
Bacardi is offline
Reply


Thread Tools
Display Modes

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 14:18.


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