Raised This Month: $ Target: $400
 0% 

ArrayGetArray problem, help with ArrayPushArray


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-08-2014 , 12:01   ArrayGetArray problem, help with ArrayPushArray
Reply With Quote #1

Hello, guys! I decided to practice a bit with arrays and started to make something like GAG plugin. So, the idea is just to learn how to properly use the arrays. Well, seems like my problem occurs in pushing array into array. Like when I have to gag the player and push the data into the array, I can't figure it out. However, the idea is that admin gags a player, then some strings and integers are saved into the array:
PHP Code:
enum _:GagInfo
{
    
Trie:Gagged,
    
Reason[64],
    
AdminName[32],
    
Date[32],
    
Len
    

The trie in the enum is the place where I save gagged IDs (it's a trie)
Well, every time I try to gag a player, I do the following:
PHP Code:
public cmdGag(idlevelcid)
{
    if(!
cmd_access(idlevelcid4))
        return 
PLUGIN_HANDLED
        
    
new arg1[32], arg2[32], arg3[32]
    
read_argv(1arg1charsmax(arg1))
    
read_argv(2arg2charsmax(arg2))
    
read_argv(3arg3charsmax(arg3))
    
    new 
target cmd_target(idarg10)
    new 
iTime str_to_num(arg2)
    
    if(
get_gagged_id(target) > -1)
    {
        
console_print(id"The player is already gagged")
        return 
PLUGIN_HANDLED
    
}
    
    new 
szID[16]
    
get_user_authid(targetszIDcharsmax(szID))
    
    new 
szTimeDate[64]
    
get_time("%d/%m/%Y %H:%M:%S"szTimeDatecharsmax(szTimeDate))
    
    new 
szAdminName[32]
    
get_user_name(idszAdminNamecharsmax(szAdminName))
    
    new 
aData[GagInfo]
    
    
aData[Gagged] = _:TrieCreate()
    
    
copy(aData[Reason], charsmax(aData[Reason]), arg3)
    
copy(aData[AdminName], charsmax(aData[AdminName]), szAdminName)
    
copy(aData[Date], charsmax(aData[Date]), szTimeDate)
    
aData[Len] = iTime
    ArrayPushArray
(g_aGaggedPlayersaData)
    
    
SetPlayerGagged(targetArraySize(g_aGaggedPlayers))
    
    
ArrayGetArray(g_aGaggedPlayersget_gagged_id(target), aData)
    
    
console_print(id"The player is successfuly gagged!")
    
console_print(id"Reason: %s"aData[Reason])
    
console_print(id"Admin: %s"aData[AdminName])
    
console_print(id"Date: %s"aData[Date])
    
console_print(id"Lenght: %d seconds"aData[Len])
    
    return 
PLUGIN_CONTINUE
    

g_aGaggedPlayers is my array, I create it like:
PHP Code:
new Array:g_aGaggedPlayers
/*INIT*/
g_aGaggedPlayers ArrayCreate(GagInfo
Okay, let's see the stocks:
PHP Code:
stock SetPlayerGagged(idsize)
{
    new 
aData[GagInfo]
    new 
szID[32]
    
get_user_authid(idszIDcharsmax(szID))
    
    if(
size > -1)
    {
        
ArrayGetArray(g_aGaggedPlayerssizeaData)
        
TrieSetCell(aData[Gagged], szID1)
        
ArraySetArray(g_aGaggedPlayerssizeaData)
    }
}

stock get_gagged_id(const id)
{
    new 
szID[32]
    
get_user_authid(idszIDcharsmax(szID))
    
    new 
aData[GagInfo]
    
    for(new 
iArraySize(g_aGaggedPlayers); i++)
    {
        
ArrayGetArray(g_aGaggedPlayersiaData)
        
        if(
TrieKeyExists(aData[Gagged], szID))
            return 
i
    
}
    return -
1

Where is the problem, I cant figure out. Why it is not properly pushing the array. Just to say, I got an error in arraygetarray in SetPlayerGagged stock. When I try to use it with the size of ArraySize(g_aGaggedPlayers).
Code:
L 08/08/2014 - 18:58:59: Invalid cellvector handle provided (1:1:1)
L 08/08/2014 - 18:58:59: [AMXX] Displaying debug trace (plugin "AdvancedGag.amxx")
L 08/08/2014 - 18:58:59: [AMXX] Run time error 10: native error (native "ArrayGetArray")
L 08/08/2014 - 18:58:59: [AMXX]    [0] AdvancedGag.sma::SetPlayerGagged (line 185)
L 08/08/2014 - 18:58:59: [AMXX]    [1] AdvancedGag.sma::cmdGag (line 115)
Any help appreciated!
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <colorchat>

#define PLUGIN "GAG"
#define VERSION "1.0"
#define AUTHOR "Flicker"

new const szPrefix[] = "[GAG]"

const ACCESS ADMIN_BAN

new Array:g_aGaggedPlayers

enum _
:GagInfo
{
    
Trie:Gagged,
    
Reason[64],
    
AdminName[32],
    
Date[32],
    
Len
    
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_concmd("amx_gag""cmdGag"ACCESS"<nick> <time> ^"reason^"")
    
register_concmd("amx_ungag""cmdUnGag"ACCESS"<nick>")
    
register_clcmd("say /gag""gagme")
    
    
register_clcmd("say""cmdSay")
    
register_clcmd("say_team""cmdSay")
    
    
g_aGaggedPlayers ArrayCreate(GagInfo)
}

public 
gagme(id)
{
    if(
get_gagged_id(id) > -1)
    {
        
RemovePlayerGag(idget_gagged_id(id))
        
client_print(idprint_chat"Ungagged")
    }
    else
    {
        new 
aData[GagInfo]
        
        
aData[Gagged] = _:TrieCreate()
        
copy(aData[Reason], charsmax(aData[Reason]), "")
        
copy(aData[AdminName], charsmax(aData[AdminName]), "")
        
copy(aData[Date], charsmax(aData[Date]), "")
        
aData[Len] = 0
        
        ArrayPushArray
(g_aGaggedPlayersaData)
        
        
SetPlayerGagged(idArraySize(g_aGaggedPlayers))
        
client_print(idprint_chat"Gagged!")
    }
}

public 
cmdSay(id)
{
        
    if(
get_gagged_id(id) > -1)
    {
        
client_print(idprint_chat"You are gagged!")
        return 
PLUGIN_HANDLED
    
}
    else    return 
PLUGIN_CONTINUE
    
    
    
return PLUGIN_CONTINUE
}

public 
cmdGag(idlevelcid)
{
    if(!
cmd_access(idlevelcid4))
        return 
PLUGIN_HANDLED
        
    
new arg1[32], arg2[32], arg3[32]
    
read_argv(1arg1charsmax(arg1))
    
read_argv(2arg2charsmax(arg2))
    
read_argv(3arg3charsmax(arg3))
    
    new 
target cmd_target(idarg10)
    new 
iTime str_to_num(arg2)
    
    if(
get_gagged_id(target) > -1)
    {
        
console_print(id"The player is already gagged")
        return 
PLUGIN_HANDLED
    
}
    
    new 
szID[16]
    
get_user_authid(targetszIDcharsmax(szID))
    
    new 
szTimeDate[64]
    
get_time("%d/%m/%Y %H:%M:%S"szTimeDatecharsmax(szTimeDate))
    
    new 
szAdminName[32]
    
get_user_name(idszAdminNamecharsmax(szAdminName))
    
    new 
aData[GagInfo]
    
    
aData[Gagged] = _:TrieCreate()
    
    
copy(aData[Reason], charsmax(aData[Reason]), arg3)
    
copy(aData[AdminName], charsmax(aData[AdminName]), szAdminName)
    
copy(aData[Date], charsmax(aData[Date]), szTimeDate)
    
aData[Len] = iTime
    ArrayPushArray
(g_aGaggedPlayersaData)
    
    
SetPlayerGagged(targetArraySize(g_aGaggedPlayers))
    
    
ArrayGetArray(g_aGaggedPlayersget_gagged_id(target), aData)
    
    
console_print(id"The player is successfuly gagged!")
    
console_print(id"Reason: %s"aData[Reason])
    
console_print(id"Admin: %s"aData[AdminName])
    
console_print(id"Date: %s"aData[Date])
    
console_print(id"Lenght: %d seconds"aData[Len])
    
    return 
PLUGIN_CONTINUE
    
}

public 
cmdUnGag(idlevelcid)
{
    if(!
cmd_access(idlevelcid2))
        return 
PLUGIN_HANDLED
    
        
    
new arg1[32]
    
read_argv(1arg1charsmax(arg1))
    
    new 
target cmd_target(idarg10)
    
    if(
get_gagged_id(target) < 0)
    {
        
console_print(id"The player is not gagged")
        return 
PLUGIN_HANDLED
    
}
        
        
    
RemovePlayerGag(targetget_gagged_id(target))
    
console_print(id"Player successfully ungagged!")
    
    return 
PLUGIN_CONTINUE
}

stock gChat(const id, const szMsg[], any:...)
{
    new 
szText[192]
    
vformat(szTextcharsmax(szText), szMsg3)
    
ColorChat(idGREEN"%s^1 %s"szPrefixszText)
}

stock get_gagged_id(const id)
{
    new 
szID[32]
    
get_user_authid(idszIDcharsmax(szID))
    
    new 
aData[GagInfo]
    
    for(new 
iArraySize(g_aGaggedPlayers); i++)
    {
        
ArrayGetArray(g_aGaggedPlayersiaData)
        
        if(
TrieKeyExists(aData[Gagged], szID))
            return 
i
    
}
    return -
1
}

stock SetPlayerGagged(idsize)
{
    new 
aData[GagInfo]
    new 
szID[32]
    
get_user_authid(idszIDcharsmax(szID))
    
    if(
size > -1)
    {
        
ArrayGetArray(g_aGaggedPlayerssizeaData)
        
TrieSetCell(aData[Gagged], szID1)
        
ArraySetArray(g_aGaggedPlayerssizeaData)
    }
}

stock RemovePlayerGag(idsize)
{
    new 
aData[GagInfo]
    new 
szID[32]
    
get_user_authid(idszIDcharsmax(szID))
    
    if(
size > -1)
    {
        
ArrayGetArray(g_aGaggedPlayerssizeaData)
        
TrieDeleteKey(aData[Gagged], szID)
        
ArraySetArray(g_aGaggedPlayerssizeaData)
    }

The command /gag (gagme()) is a test command. Doesn't matter!
__________________

Last edited by Flick3rR; 08-08-2014 at 12:12.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-08-2014 , 12:28   Re: ArrayGetArray problem, help with ArrayPushArray
Reply With Quote #2

Dynamic arrays are indexed from 0. Use ArraySize -1.
Backstabnoob is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-08-2014 , 13:17   Re: ArrayGetArray problem, help with ArrayPushArray
Reply With Quote #3

All the problems for this. It's rediculous. Thank you very much!
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-08-2014 , 17:57   Re: ArrayGetArray problem, help with ArrayPushArray
Reply With Quote #4

Quote:
Originally Posted by Flick3rR View Post
It's rediculous.
It's not ridiculous, it is normal. You should get used to using the zero index.
__________________
fysiks 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 13:12.


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