AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   array must be indexed (https://forums.alliedmods.net/showthread.php?t=89362)

card 04-05-2009 11:14

array must be indexed
 
PHP Code:

#include <amxmodx>

public plugin_init() {
    
register_plugin("Plugin""1.0""Author")
    
register_clcmd("say""SayCommand"0);
}

public 
SayCommand(id) {
    new 
message[256];
    
read_args(message255);
    if (
containi(message"/try ") == 1) {
        new 
num[4];
        
read_args(num3);
        
ChoosedNumber(idnum[3]);
    }
}

ChoosedNumber(idnum[]) {
    new 
cpu_number random_num(0100);
    if(
cpu_number == num) {
        
client_print(idprint_chat"Your number = %d. cpu number = %d. Theese numbers match."numcpu_number);
    } else
        
client_print(idprint_chat"Your number = %d. cpu number = %d. Theese numbers doesnt match."numcpu_number);


i have no idea how i must write this, maybe someone will help me fixing that array must be indexed from this line
if(cpu_number == num) {

Bugsy 04-05-2009 11:16

Re: array must be indexed
 
1. You are trying to pass only the last array element in your string to the function. ChoosedNumber(id, num[3]);
2. You are trying to compare if a number is == a string, which will not work. if(cpu_number == num)

PHP Code:

#include <amxmodx>

public plugin_init() {
    
register_plugin("Plugin""1.0"".nnnnn1")
    
register_clcmd("say""SayCommand"0);
}

public 
SayCommand(id
{
    new 
message[256];
    
read_args(message255);
    
    if (
containi(message"/try ") == 1
    {
        new 
num[4];
        
read_args(num3);
        
ChoosedNumber(idstr_to_num(num) );
    }
}

ChoosedNumber(idnum
{
    new 
cpu_number random_num(0100);
    
    
client_print(idprint_chat"Your number = %d. cpu number = %d. These numbers %s."numcpu_number , (cpu_number == num) ? "match" "do not match");



card 04-05-2009 11:27

Re: array must be indexed
 
.nnnnn1 : /try 3
Your number = 0. cpu number = 1. These numbers do not match.
.nnnnn1 : /try 4
.nnnnn1 : /try 1
Your number = 0. cpu number = 43. These numbers do not match.
.nnnnn1 : /try 5
.nnnnn1 : /try 2
Your number = 0. cpu number = 92. These numbers do not match.
.nnnnn1 : /try 3
.nnnnn1 : /try 6
Your number = 0. cpu number = 40. These numbers do


any number i type, he shows that my number is 0 ...

TheRadiance 04-05-2009 11:49

Re: array must be indexed
 
Not sure that will work, but try:
PHP Code:

public SayCommand(id
{
    new 
message[256];
    
read_args(message255);
    
    if (
equal(message"/try ") ) 
    {
        
replace_all message254"/try """ )
        
trim message )
        
ChoosedNumber(idstr_to_num(message) );
    } 


Bugsy 04-05-2009 11:52

Re: array must be indexed
 
Sorry, I didn't check to see if you were reading the arguments properly. Tested and working

PHP Code:

#include <amxmodx>

public plugin_init() 
{
    
register_plugin("Plugin""1.0"".nnnnn1")
    
register_clcmd("say""SayCommand");
}

public 
SayCommand(id
{
    new 
szArgs[11];
    
read_args (szArgs 10 );
    
remove_quotesszArgs );
    
trimszArgs[5] );

    if ( 
equal(szArgs"/try " ) && strlen(szArgs[5]) ) 
    {
        
ChoosedNumberid str_to_num(szArgs[5]) );
        return 
PLUGIN_HANDLED;
    }

    return 
PLUGIN_CONTINUE;
}

ChoosedNumber(idnum 
{
    new 
cpu_number random_num(0100);
    
    
client_print(idprint_chat"Your number = %d. cpu number = %d. These numbers %s."numcpu_number , (cpu_number == num) ? "match" "do not match");



card 04-05-2009 16:05

Re: array must be indexed
 
thanks a lot +k


All times are GMT -4. The time now is 02:18.

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