Raised This Month: $ Target: $400
 0% 

Need help on building an array...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
V I R U S
Senior Member
Join Date: Jul 2004
Location: Russia / Germany
Old 10-10-2011 , 16:44   Need help on building an array...
Reply With Quote #1

Hello everyone!

I'm trying to write one plugin which is like simple banmenu. There is first menu which has usernames, and second for reasons.

So, i need an array to hold 3 items.
1. ID of user who used menu
2. ID of choosen user from menu
3. ID of the reason

Every time someone choose a player from menu, it should create array like array(1)(3) = (2,2,2)

And i need the possibility to add "2" items, delete them and count.

Can anyone help me on solving this? Thanks!
__________________
V I R U S is offline
Send a message via ICQ to V I R U S
V I R U S
Senior Member
Join Date: Jul 2004
Location: Russia / Germany
Old 10-13-2011 , 18:24   Re: Need help on building an array...
Reply With Quote #2

No one?
__________________
V I R U S is offline
Send a message via ICQ to V I R U S
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-13-2011 , 18:52   Re: Need help on building an array...
Reply With Quote #3

PHP Code:
enum _:BanArray
{
    
BAN_ADMIN,
    
BAN_CHOSEN,
    
BAN_REASON256 ]
}

new Array:
g_aBans;

new 
g_iTotalBans;

public 
plugin_init()
{
    
g_aBans ArrayCreateBanArray );
}

// Not a real function, just an example.

public player_bannediAdminiBannedPlayerszReason[ ] )
{
    new 
aDataBanArray ];
    
    
aDataBAN_ADMIN ] = iAdmin;
    
aDataBAN_CHOSEN ] = iBannedPlayer;
    
copyaDataBAN_REASON ], charsmaxaDataBAN_REASON ] ), szReason );
    
    
ArrayPushArrayg_aBansaData );
    
    
g_iTotalBans++;
    
    
// g_aBans now contains an array containing that information
    // To access it, do the following.
    
    
new aRetrieveInformationBanArray ];
    
ArrayGetArrayg_aBansg_iTotalBansaRetrieveInformation );
    
    
// aRetrieveInformation can now be used
    // in order to get the information
    // of the admin that banned, the banned player,
    // and the reason he got banned, using aRetrieveInformation[ BAN_* ]
    // where * is ADMIN, CHOSEN, or REASON
    
    // When retrieving the information from ArrayGetArray, make sure
    // that you pass the right index.

If you have any questions let me know.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-13-2011 , 20:20   Re: Need help on building an array...
Reply With Quote #4

I think he wants { int , int , int } according to his post; it looks like maybe he's using the index of a pre-defined list of reasons, this would also consume much less memory. He also needs to know how to remove items. For counting ArraySize() works instead of manually counting.
__________________

Last edited by Bugsy; 10-13-2011 at 20:30.
Bugsy is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-13-2011 , 20:29   Re: Need help on building an array...
Reply With Quote #5

Hmm, couldn't he just change the string BAN_REASON to an integer? Cause he said he wants to be able to add 2 items, so I'm guessing the dynamic array system would be the best way to do that.

@VIRUS
For counting how many items there are, you can use ArraySize( g_aBans );

For deleting a specific item, you can use ArrayDeleteItem( g_aBans, index );
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-13-2011 , 20:44   Re: Need help on building an array...
Reply With Quote #6

I was confused by his add "2"s statement, I assume he is referring to adding/removing/counting, in your example, a BanArray 'struct' to the array since he used all 2's to demonstrate.

Your method is fine, just saying his request post says { int , int , int } and not { int , int , int[] }, no biggie.
__________________
Bugsy is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-13-2011 , 20:51   Re: Need help on building an array...
Reply With Quote #7

Oh okay. I think OP will probably end up clarifying, and we can work from there
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
V I R U S
Senior Member
Join Date: Jul 2004
Location: Russia / Germany
Old 11-19-2011 , 21:39   Re: Need help on building an array...
Reply With Quote #8

Sooooo! Thanks for your answers!

Bugsy has right, i have 3 int's which are predifined. Either by AMXX system or by my own (arrays).

What i'm trying to do, is to build an array which will contain "id of reason(reason)", "id of player who has been voted(victim)", "id of player who voted(voter)".

At the end, the array should look like myArray[victim][reason][voter]. The reason, why i need this structure, is because i want:
1. Check if the voter already voted the victim with the selected reason.
2. Count number of votes for a victim by a reason.
3. Remove voters vote if he disconnected from the server.

So, what is the most simple way to realize it?!




One question more:
Is this structure
PHP Code:
g_ReasonsList[][] = {
  
"Reason",
  
"Reason",
  
"Reason"
}; 
And the
PHP Code:
g_ReasonsList[][][] = "Reason";
g_ReasonsList[][][] = "Reason";
g_ReasonsList[][][] = "Reason"
The same?!
__________________
V I R U S is offline
Send a message via ICQ to V I R U S
V I R U S
Senior Member
Join Date: Jul 2004
Location: Russia / Germany
Old 11-20-2011 , 17:31   Re: Need help on building an array...
Reply With Quote #9

Fast help is much appreciated!
__________________
V I R U S is offline
Send a message via ICQ to V I R U S
Reply



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 05:57.


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