AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved [ H3LP ] Getting from Array? (https://forums.alliedmods.net/showthread.php?t=296060)

CrazY. 04-11-2017 09:18

[ H3LP ] Getting from Array?
 
Hello, how to get direct values from a Array? For example, I want do a "filter" into the Array and only get items that can have "number" 1 or only 2.

Code:
new Array:weapon_array; enum _:WeaponData {    WeaponName[32],    WeaponNum } public plugin_precache() {    weapon_array = ArrayCreate(WeaponData); } public test() {    new eWeaponData[WeaponData];    for (new i = 0; i < ArraySize(weapon_array); i++)    {         // Here I dont know how to get...        ArrayGetArray(weapon_array, i, eWeaponData, eWeaponData[WeaponNum] == 2);    } }

Arkshine 04-11-2017 10:31

Re: [ H3LP ] Getting from Array?
 
You can't. Just retrieve the array, and check afterward.

CrazY. 04-11-2017 10:53

Re: [ H3LP ] Getting from Array?
 
Ok, I think its possible skip the loop if the number of weapon dont is equal what I need.

Natsheh 04-11-2017 11:19

Re: [ H3LP ] Getting from Array?
 
PHP Code:

new Array:weapon_name, Array:weapon_num;

public 
plugin_precache()
{
   
weapon_name ArrayCreate(32);
   
weapon_num ArrayCreate(1);
}

public 
test()
{
   new 
eWeaponName[32], wpnnum;

   for (new 
0ArraySize(weapon_name); i++)
   {
        
// Here I dont know how to get...
       
ArrayGetString(weapon_nameieWeaponName31);
       
wpnnum ArrayGetCell(weapon_numi)
   }



Black Rose 04-11-2017 11:30

Re: [ H3LP ] Getting from Array?
 
Maybe there's a better way of doing things here.
As long as you provide an example that is not describing your actual code accurately there's nothing we can do.

A good way to avoid loops is using custom entity values which could point to a more specific data point or even an array handle.
Perhaps there's a better way of organizing the data in the arrays to make it more accessable.
Dynamic arrays within dynamic arrays sounds like a stupid idea but can be very clever in some cases.
Tries can be used with "custom pointers" so you don't have to search.

But it all depends on what you're doing.
Also, there's no point of avoiding loops if your action is reacting to, for example, a chat command which is not frequently called.

CrazY. 04-11-2017 15:48

Re: [ H3LP ] Getting from Array?
 
Hmm, Ok then, I wil do some tests, after I tell the result.

CrazY. 04-27-2017 18:37

Re: [ H3LP ] Getting from Array?
 
Solved.


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

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