AlliedModders

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

-B1ng0- 07-13-2010 13:44

How to indexed array
 
Hello guys, i make a test plugin for show my problem

Code:

#include <amxmodx>
#include <amxmisc>


public plugin_init()
{
        register_plugin("test", "1.0", "-B1ng0-")
       
        register_concmd("amx_test", "test_command", ADMIN_KICK, "<name> <message>")
}

public test_command(id, level, cid)
{
        if(!cmd_access(id, level, cid, 3))
        {
                return PLUGIN_HANDLED
        }
       
        new target[24], message[64]
        read_argv(1, target, 23)
        read_argv(2, message, 63)
       
       
        new player = cmd_target(id, target, 9)
        if (!player)
        {
                return PLUGIN_HANDLED
        }
       
        new array[2]
        array[0] = id
        array[1] = player
       
        set_task(1.0,"ssm_testexecute",message+3322,_,_,"a")
       
        return PLUGIN_HANDLED
}
 
public ssm_testexecute(array[2])
{
        new id = array[0]
        new player = array[1] 
       
        new name[32]
        get_user_name(id, name, 31)
           
        client_print(player, print_chat, "ADMIN %: %s", name, message)
       
        return PLUGIN_CONTINUE;
}

Error 033: array must be indexed (variable: message)
Here: set_task(1.0,"ssm_testexecute",message+3322,_ ,_,"a")


Help me solve this please

#8 SickneSS 07-13-2010 14:05

Re: How to indexed array
 
Its id+3322

RedRobster 07-13-2010 14:06

Re: How to indexed array
 
You can't set a task with an entire array. What it wants you to do is:
PHP Code:

set_task(1.0"ssm_testexecute"message[0]+3322//If you only want the task to repeat once, there is no need for the "a" flag. 

So, I'd advise that you put the message in a global array, and use that. I actually don't think that what you want to do will work with a task *unless you create a global variable for one of the id's*. Try:
PHP Code:

#include <amxmodx>
#include <amxmisc>

new gMessage[64]

public 
plugin_init() 

    
register_plugin("test""1.0""-B1ng0-")
    
    
register_concmd("amx_test""test_command"ADMIN_KICK"<name> <message>")
}

public 
test_command(idlevelcid)
{
    if(!
cmd_access(idlevelcid3))
    {
        return 
PLUGIN_HANDLED
    
}
    
    new 
target[24]
    
read_argv(1target23)
    
read_argv(2gMessage63)
    
    
    new 
player cmd_target(idtarget9
    if (!
player)
    {
        return 
PLUGIN_HANDLED
    
}
    
    new array[
2]
    array[
0] = id
    
array[1] = player
    
    ssm_testexecute
(array)
        
    return 
PLUGIN_HANDLED
}
 
public 
ssm_testexecute(array[2])
{
    new 
id = array[0]
    new 
player = array[1]   
    
    new 
name[32]
    
get_user_name(idname31
        
    
client_print(playerprint_chat"ADMIN %: %s"namegMessage)
    
    return 
PLUGIN_CONTINUE;



-B1ng0- 07-13-2010 14:20

Re: How to indexed array
 
I need to use message in next public and i need to use task because i need to repeat this public ssm_testexecute 3 times

set_task(1.0,"ssm_testexecute",0,array,2,"a", 3) like this but in public ssm_testexecute i need tu use message in clien_print ..

RedRobster 07-13-2010 14:41

Re: How to indexed array
 
Then I would advise creating a global variable: gPlayer and assigning the player variable to it. Then do:
PHP Code:

set_task(1.0"ssm_testexecute"id,_,_"a"3


-B1ng0- 07-13-2010 15:04

Re: How to indexed array
 
dont work RedRoboster he show me my name but not my text

He show me this: ADMIN -B1ng0-: -B1ng0-
but i type this command amx_test -B1ng0- Test_message
need show me this: ADMIN -B1ng0-: Test_message

RedRobster 07-13-2010 15:12

Re: How to indexed array
 
PHP Code:

#include <amxmodx>
#include <amxmisc>

new gMessage[64]
new 
gPlayer

public plugin_init() 

    
register_plugin("test""1.0""-B1ng0-")
    
    
register_concmd("amx_test""test_command"ADMIN_KICK"<name> <message>")
}

public 
test_command(idlevelcid)
{
    if(!
cmd_access(idlevelcid3))
    {
        return 
PLUGIN_HANDLED
    
}
    
    
gPlayer 0
    
    
new target[24]
    
read_argv(1target23)
    
read_argv(2gMessage63)
    
    
    
gPlayer cmd_target(idtarget9
    if (!
gPlayer)
    {
        return 
PLUGIN_HANDLED
    
}
    
    
set_task(1.0"ssm_testexecute"id,_,_,"a"3)
        
    return 
PLUGIN_HANDLED
}
 
public 
ssm_testexecute(id)
{
    new 
name[32]
    
get_user_name(idname31
        
    
client_print(gPlayerprint_chat"ADMIN %: %s"namegMessage)
    
    return 
PLUGIN_CONTINUE;


Try this.

-B1ng0- 07-13-2010 15:21

Re: How to indexed array
 
@RedRobster THX YOU i found my problem

client_print(gPlayer, print_chat, "ADMIN %: %s", name, gMessage)

Here is it look at ADMIN % i forgot s = %s Thank You mate

fysiks 07-13-2010 17:07

Re: How to indexed array
 
That could cause race conditions if amx_test is used by someone else (or the same person; different problem) before it has finished printing.

I believe you can send string through a set_task like:

Code:

set_task(time, "function", id+offset, string, sizeof(string), "a", 3)

public function(yourstring[])
{
    //  . . .
}


Bugsy 07-14-2010 09:02

Re: How to indexed array
 
Quote:

Originally Posted by fysiks (Post 1238098)
That could cause race conditions if amx_test is used by someone else (or the same person; different problem) before it has finished printing.

I believe you can send string through a set_task like:

Code:

set_task(time, "function", id+offset, string, sizeof(string), "a", 3)

public function(yourstring[])
{
    //  . . .
}


You can pass an array and integer to the called function.

PHP Code:

new szText[] = "hi hello";
set_task1.0 "TheFunc" id szText sizeofszText ) , "a" );

public 
TheFuncarrData[] , id )
{
    
client_printid print_chat "Msg=%s" arrData );    




All times are GMT -4. The time now is 07:14.

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