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

Problem with Array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Vit_amin
Senior Member
Join Date: Dec 2015
Location: Russian Federation
Old 01-21-2016 , 16:13   Problem with Array
Reply With Quote #1

I write code:
PHP Code:
                new szTest[33]
                new 
szTest2[128]
                
get_user_info(client"name"szTestcharsmax(szTest))
                new 
iTest 0
                
for (new 0<= charsmax(szTest2); i++)
                {
                    if (!
strcmp(szTest2[i], ""))
                    {
                        
iTest++
                        if (
iTest <= strlen(szTest))
                        {
                            
server_print("TEST 1")
                            
copy(szTest2[i], charsmax(szTest2), szTest[i])
                        }
                        else if (
iTest == strlen(szTest) + 1)
                        {
                            
server_print("TEST 2")
                            
copy(szTest2[i], charsmax(szTest2), ",")
                        }
                        else break
                    }
                }
                
server_print(szTest2
How output this format ? Name1, Name2, Name3, ...
Server output only Name1 or Name2 or Name3 or ...
Vit_amin is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-21-2016 , 16:17   Re: Problem with Array
Reply With Quote #2

Explain what you are trying to do with words, not code.
__________________
Bugsy is online now
Vit_amin
Senior Member
Join Date: Dec 2015
Location: Russian Federation
Old 01-21-2016 , 16:21   Re: Problem with Array
Reply With Quote #3

I want that the variable szTest2 output players this format: Name1, Name2, Name3 ...
But when client respawn i output only one player name (not format list)
Vit_amin is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 01-21-2016 , 16:45   Re: Problem with Array
Reply With Quote #4

Look these lines highlighted (L1397-L1410):

https://github.com/addonszz/Multi-Mod_Manager/blob/276bd6f2930625feb7a7c35d86f5a42d168e6e7f/scripting/multimod_manager.sma#L1397-L1410
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 01-21-2016 at 16:47. Reason: spelling fix
addons_zz is offline
Vit_amin
Senior Member
Join Date: Dec 2015
Location: Russian Federation
Old 01-21-2016 , 16:48   Re: Problem with Array
Reply With Quote #5

Thank you, tried this
Vit_amin is offline
Vit_amin
Senior Member
Join Date: Dec 2015
Location: Russian Federation
Old 01-21-2016 , 17:51   Re: Problem with Array
Reply With Quote #6

I don't understand. Write code:
PHP Code:
...
new Array:
g_aClientName
...
g_aClientName ArrayCreate(32)
...
public 
IsClientRetry(client)
{
    new 
client_name[32]
    
get_user_info(client"name"client_namecharsmax(client_name))
    
ArrayPushString(g_aClientNameclient_name)
    new 
size ArraySize(g_aClientName)
    new 
test1[32]
    
server_print("Size 1: %d"size)
    for (new 
0<= sizei++)
    {
        
server_print("Size 2: %d"size)
        
ArrayGetString(g_aClientNameitest1charsmax(test1))
        
server_print("%s"test1)
    }

Console Output:
Code:
L 01/22/2016 - 00:47:16: Invalid cellvector handle provided (6:1:1)
L 01/22/2016 - 00:47:16: [AMXX] Displaying debug trace (plugin "zombie_horde.amxx")
L 01/22/2016 - 00:47:16: [AMXX] Run time error 10: native error (native "ArrayGetString")
L 01/22/2016 - 00:47:16: [AMXX]    [0] zombie_horde.sma::IsClientRetry (line 596)
L 01/22/2016 - 00:47:16: [AMXX]    [1] zombie_horde.sma::Event_PlayerSpawn (line 564)

Last edited by Vit_amin; 01-21-2016 at 17:54.
Vit_amin is offline
Vit_amin
Senior Member
Join Date: Dec 2015
Location: Russian Federation
Old 01-21-2016 , 18:04   Re: Problem with Array
Reply With Quote #7

Solved
PHP Code:
for (new 0sizei++) 

Last edited by Vit_amin; 01-21-2016 at 18:04.
Vit_amin is offline
Vit_amin
Senior Member
Join Date: Dec 2015
Location: Russian Federation
Old 01-21-2016 , 21:55   Re: Problem with Array
Reply With Quote #8

But 1 Auestion:
When i added -> ArrayPushString(g_aClientName, szSteamID)
How check what if szSteamID add in g_aClientName ?

Last edited by Vit_amin; 01-21-2016 at 21:55.
Vit_amin is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 01-21-2016 , 22:11   Re: Problem with Array
Reply With Quote #9

ArrayFindString for AMXX 183 or superior.

Code:
new position = ArrayFindString(my_dynamic_array_pointer, my_string) if( position  == -1 )     server_print( "Not found" ) else     server_print( "Found at: %d position", position )
For the AMXX 182, consider using tries or do a loop throw the array. See also: The advantages of a trie over an array for strings storage.
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 01-21-2016 at 23:09. Reason: better information
addons_zz 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 09:32.


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