View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 05-09-2012 , 12:47   Re: Array Question
Reply With Quote #8

Quote:
Originally Posted by berni View Post
Either create a string array and a cell array...
example, if I understand what berni means cell array
PHP Code:
// String array
new String:g_key[][] =
{
    
"Smoke",
    
"Flash",
    
"Godmode"
}

// Cell array
new g_value[] =
{
    
5000,
    
6000,
    
8000
}

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_test"cmd_callback"Test array by give number between 0 - 2");
}

public 
Action:cmd_callback(clientargs)
{
    if(
args 1// Typed only cmd
    
{
        
ReplyToCommand(client"Array g_key size %i,  g_value size %i"sizeof(g_key), sizeof(g_value));
        return 
Plugin_Handled;
    }

    new 
number;
    new 
String:arg[3];
    
GetCmdArg(1argsizeof(arg));
    
number StringToInt(arg);

    if(
number > -&& number sizeof(g_key) && number sizeof(g_value)) // Make sure not get error - [SM] Plugin encountered error 15: Array index is out of bounds
    
{
        
ReplyToCommand(client"key %s value %i"g_key[number], g_value[number]);
    }
    else
    {
        
ReplyToCommand(client"Invalid number. Array index is out of bounds");
    }
    return 
Plugin_Handled;

Bacardi is offline