View Single Post
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