Raised This Month: $ Target: $400
 0% 

Items Database In Array ( Add,Remove Items )


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 04-15-2013 , 08:01   Items Database In Array ( Add,Remove Items )
Reply With Quote #1

Hi...
Lets start!

Here is my code:
PHP Code:
new Array:g_itemsdata[4]
new Array:
g_itemid
new g_item_count

public plugin_precache()
{
    new 
a
    
for( 04a++ )g_itemsdata[a] = ArrayCreate1,)    
    
g_itemid create_array1,)
    
g_item_count 0
}

stock g_add_itemitemdata[4] )
{
    new 
a
    
for( 04a++ ) ArrayPushCellg_itemsdata[a], itemdata[a]) 
    
ArrayPushCellg_itemidg_item_count
    
g_item_count++
    return 
g_item_count 1
}

stock g_remove_itemitemid )
{
    new 
ab
    
for( 0ArraySize(g_itemid); a++ )
    {
        if( 
itemid == ArrayGetCellg_itemid) )
        {
            for( 
04b++ )ArrayDeleteItem(g_itemsdata[b], a)
            
ArrayDeleteItem(g_itemsdata[b], a)
            
ArrayDeleteItem(g_itemida)
            break
        }
    }

This is how i usually do this.
This code is for example registering weapons, items, forwards, entities and everythings else.

Problem is, i feel that, there must be better method for doing this...
You see g_item_count get every times bigger and bigger if i for example add item...
If i remove item i can just do this: g_item_count--
and if i do, item index-s inside of g_itemid can have same values what also mean if i remove item again with that index then wrong item will be removed : /
( because of my gameplay, one map can last 1 - 3 hours, so that g_item_count can get very huge value and i think thats bad for cpu. )

Also can i somehow make this without loop ( loop in g_remove_item for searching right index... )
Thanks!
.Dare Devil. is offline
 



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 10:52.


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