AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Items Database In Array ( Add,Remove Items ) (https://forums.alliedmods.net/showthread.php?t=213484)

.Dare Devil. 04-15-2013 08:01

Items Database In Array ( Add,Remove Items )
 
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!

hornet 04-16-2013 07:20

Re: Items Database In Array ( Add,Remove Items )
 
It really depends on how you intend on removing the items. For example if you were to remove them by menu then it could be done differently, as oppose to eg. picking a random item id.


All times are GMT -4. The time now is 10:52.

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