Raised This Month: $51 Target: $400
 12% 

ArrayDeleteItem() - Delete First Entry


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Drak
Veteran Member
Join Date: Jul 2005
Old 03-20-2010 , 16:21   ArrayDeleteItem() - Delete First Entry
Reply With Quote #1

I have an array, visually would look like this:

Code:
Slot 1: STEAM_ID_LAN|PLAYER: Hello World 1
Slot 2: STEAM_ID_LAN|PLAYER: Hello World 2
Slot 3: STEAM_ID_LAN|PLAYER: Hello World 3
Code:
            // Delete our previous one             for(new Count;Count < Size;Count++)             {                 ArrayGetString(g_NewspaperArray,Count,Message,255);                 strtok(Message,ArrayAuthID,35,Temp,1,'|');                                 trim(ArrayAuthID);                 remove_quotes(ArrayAuthID);                                                 if(equali(AuthID,ArrayAuthID))                 {                     if(++Num >= MAX_ADS)                     {                         server_print("we reached our max");                         ArrayDeleteItem(g_NewspaperArray,Count);                         break                     }                 }                             }
This will delete the latest entry in the array. (When it reaches it's max, three.) This will delete: STEAM_ID_LAN|PLAYER: Hello World 3 - I want it to delete: STEAM_ID_LAN|PLAYER: Hello World 1. How would I go about doing this?

EDIT:
I apparently can't think - id just snip the thread, but my fix obvious is to use "ArrayDeleteItem(g_NewspaperArray,Count - MAX_ADS)"
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-20-2010 , 17:43   Re: ArrayDeleteItem() - Delete First Entry
Reply With Quote #2

ArrayDeleteItem( g_NewspaperArray , 0 );?

I'm assuming this array holds data for each player so it will not be in order so using just 0 will not always work properly. Maybe you can include a timestamp (get_systime()) in the string and use that to delete the oldest? Then scan through items and find the entry with oldest timestamp (get_systime()-timestamp) and delete that one?

I don't understand 100% what you are trying to do, if you can explain further I can probably provide a better answer, or attempt to atleast.
__________________

Last edited by Bugsy; 03-20-2010 at 17:46.
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-20-2010 , 18:12   Re: ArrayDeleteItem() - Delete First Entry
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
ArrayDeleteItem( g_NewspaperArray , 0 );?

I'm assuming this array holds data for each player so it will not be in order so using just 0 will not always work properly.
If all entries remain in the same order as they are placed in the dynamic array and if when an entry is deleted all the rest just shift down to fill in using 0 should work correctly every time, I think.

Is one of those two things not true with dynamic arrays?
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-20-2010 , 19:42   Re: ArrayDeleteItem() - Delete First Entry
Reply With Quote #4

Console command add\delete will show order in which items are added\removed. If you're always trying to remove the oldest item added to your array then using ArrayDeleteItem( g_NewspaperArray, 0 ) should always work.
PHP Code:
#include <amxmodx>

new Array:g_NewspaperArray;
new 
g_Added 3;

public 
plugin_init()
{
    
g_NewspaperArray ArrayCreate255 32 );
    
ArrayPushStringg_NewspaperArray"STEAM_ID_LAN|PLAYER: Hello World 1" );
    
ArrayPushStringg_NewspaperArray"STEAM_ID_LAN|PLAYER: Hello World 2" );
    
ArrayPushStringg_NewspaperArray"STEAM_ID_LAN|PLAYER: Hello World 3" );

    
register_concmd"add" "AddItem" );
    
register_concmd"delete" "DeleteItem" );    
}

public 
AddItem()
{
    new 
Message256 ];
    
    
formatexMessage 255 "STEAM_ID_LAN|PLAYER: Hello World %d" , ++g_Added );
    
ArrayPushStringg_NewspaperArray Message );
    
    for( new 
Count Count ArraySizeg_NewspaperArray ) ; Count++ )
    {
        
ArrayGetStringg_NewspaperArray Count Message 255 );
        
server_printMessage );
    }
}

public 
DeleteItem()
{
    new 
Message256 ];
    
ArrayDeleteItemg_NewspaperArray );
    
    for( new 
Count Count ArraySizeg_NewspaperArray ) ; Count++ )
    {
        
ArrayGetStringg_NewspaperArray Count Message 255 );
        
server_printMessage );
    }

__________________
Bugsy is offline
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 23:43.


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