Raised This Month: $32 Target: $400
 8% 

ArrayFindString


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 05-27-2019 , 12:27   ArrayFindString
Reply With Quote #1

It doesn't work or am I doing something wrong?
I get -1 even tho Array String is filled with user's name and I'm searching using same variable.
PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "PLUGIN"
#define VERSION "1.0.0"
#define AUTHOR "AUTHOR"

enum _:MarketData
{
    
RowId,
    
Seller[32],
    
SkinId,
    
CaseId,
    
KeyId,
    
Quantity,
    
Float:Price
}


new Array:
g_aArray;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say test""testout");

    
g_aArray ArrayCreate(MarketData);
}

public 
testout(id) {
    new 
Data[MarketData];

    new 
szName[32];
    
get_user_name(idszNamecharsmax(szName));

    for (new 
i5i++)
    {
        
Data[RowId] = i;
        
copy(Data[Seller], charsmax(Data[Seller]), szName);
        
Data[SkinId] = random_num(159);
        
Data[CaseId] = random_num(159);
        
Data[KeyId] = random_num(159);
        
Data[Quantity] = random_num(159);
        
Data[Price] = random_float(1.059.0);
        
ArrayPushArray(g_aArrayData);
    }

    new 
ItemExists ArrayFindString(g_aArrayszName);
    
client_print_color(idprint_team_default"%d"ItemExists);

__________________

Last edited by Airkish; 05-27-2019 at 12:32.
Airkish is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 05-27-2019 , 12:38   Re: ArrayFindString
Reply With Quote #2

What you did doesn't make any sense, you should probably use celltrie instead.
Untested.
Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "PLUGIN" #define VERSION "1.0.0" #define AUTHOR "AUTHOR" enum _:MarketData {     RowId,     Seller[32],     SkinId,     CaseId,     KeyId,     Quantity,     Float:Price } new Trie:g_trieArray; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("say test", "testout");     g_trieArray = TrieCreate(); } public testout(id) {     new Data[MarketData];     new szName[32];     get_user_name(id, szName, charsmax(szName));     Data[RowId] = 1;     copy(Data[Seller], charsmax(Data[Seller]), szName);     Data[SkinId] = random_num(1, 59);     Data[CaseId] = random_num(1, 59);     Data[KeyId] = random_num(1, 59);     Data[Quantity] = random_num(1, 59);     Data[Price] = random_float(1.0, 59.0);     TrieSetArray(g_trieArray, szName, Data, sizeof Data);     /*for (new i; i < 5; i++)     {         Data[RowId] = i;         copy(Data[Seller], charsmax(Data[Seller]), szName);         Data[SkinId] = random_num(1, 59);         Data[CaseId] = random_num(1, 59);         Data[KeyId] = random_num(1, 59);         Data[Quantity] = random_num(1, 59);         Data[Price] = random_float(1.0, 59.0);         ArrayPushArray(g_aArray, Data);     }*/     new ItemExists = TrieKeyExists(g_trieArray, szName); // Return true if the key is set, false otherwise     client_print_color(id, print_team_default, "%d", ItemExists); }
__________________









Last edited by CrazY.; 05-27-2019 at 12:39.
CrazY. is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 05-27-2019 , 13:08   Re: ArrayFindString
Reply With Quote #3

Not sure what you're trying to do but try this.
PHP Code:
#include < amxmodx >

new const g_szNames[ ] =
{
    
"John",
    
"Mark",
    
"Jimmy",
    
"Charles",
    
"Tim"
}

enum _:MarketData
{
    
szSeller32 ],
    
iSkinId,
    
iCaseId,
    
iKeyId,
    
iQuantity,
    
Float:fPrice
}

const 
iItemsCount 5;

new Array:
g_aArray;

public 
plugin_init( )
{
    
register_clcmd"say /market""@Market" );

    
g_aArray ArrayCreateMarketData );
}

@
Marketid )
{
    new 
eDataMarketData ];
    
    for( new 
iiItemsCounti++ )
    {
        
eDataszSeller ] = g_szNames];
        
eDataiSkinId ] = random_num159 );
        
eDataiCaseId ] = random_num159 );
        
eDataiKeyId ] = random_num159 );
        
eDataiQuantity ] = random_num159 );
        
eDatafPrice ] = _:random_float1.059.0 );
        
        
ArrayPushArrayg_aArrayeData );
    }

    
arrayseteData0sizeofeData[ ] ) );
    
    new 
szName32 ], iExists;
    
get_user_nameidszNamecharsmaxszName ) );
    
    for( new 
iArraySizeg_aArray ); i++ )
    {
        
ArrayGetArrayg_aArrayieData );
        
        if( 
equalszNameeDataszSeller ] ) )
        {
            
iExists i;
            break;
        }
    }
    
client_print_coloridprint_team_default"%d"iExists );

__________________

Last edited by edon1337; 05-27-2019 at 13:08.
edon1337 is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 05-27-2019 , 13:44   Re: ArrayFindString
Reply With Quote #4

Thanks for answers, both working fine, gonna use 'em.
But can anyone tell me why exactly is ArrayFindString doesn't work?

P.S. This plugin is just for testing purposes, since u asked what I'm trying to achieve.
__________________

Last edited by Airkish; 05-27-2019 at 13:44.
Airkish is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 05-27-2019 , 14:00   Re: ArrayFindString
Reply With Quote #5

It doesn't work because you're searching for a string in an "array of arrays", I mean, a cellarray where arrays are stored.

Quote:
for (new i; i < 5; i++)
{
Data[RowId] = i;
copy(Data[Seller], charsmax(Data[Seller]), szName);
Data[SkinId] = random_num(1, 59);
Data[CaseId] = random_num(1, 59);
Data[KeyId] = random_num(1, 59);
Data[Quantity] = random_num(1, 59);
Data[Price] = random_float(1.0, 59.0);
ArrayPushArray(g_aArray, Data);
}
ArrayFindString will only work properly if you search through an array of strings as the example below.

Code:
new Array:aStrings = ArrayCreate(32, 1); ArrayPushString(aStrings, "String 2"); ArrayPushString(aStrings, "String 1"); ArrayPushString(aStrings, "String 5"); ArrayPushString(aStrings, "String 3"); ArrayPushString(aStrings, "String 4"); server_print("^"String 5^" index = %d", ArrayFindString(aStrings, "String 5"))

If you're searching for a string in an array of arrays, edon's code it's the solution.
__________________









Last edited by CrazY.; 05-27-2019 at 14:04.
CrazY. 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 21:19.


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