AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   General (https://forums.alliedmods.net/forumdisplay.php?f=7)
-   -   Suggestion - arraycheck (https://forums.alliedmods.net/showthread.php?t=307473)

Relaxing 05-11-2018 15:06

Suggestion - arraycheck
 
Code:
/* Usage  * array - Array to check  * size - Size of array  * Description  * Checks if any element of array has a non-zero value  * Return  * 1 when any element is non-zero or  * 0 when all elements are undefined/reseted/untouched/equal to 0*/ native arraycheck(array[], size)

klippy 05-11-2018 16:20

Re: Suggestion - arraycheck
 
That isn't really useful and takes only like 3 lines of code to write. This won't make it into AMXX.

Relaxing 05-11-2018 16:24

Re: Suggestion - arraycheck
 
Quote:

Originally Posted by KliPPy (Post 2591750)
That isn't really useful and takes only like 3 lines of code to write. This won't make it into AMXX.

That is fine.

HamletEagle 05-11-2018 16:33

Re: Suggestion - arraycheck
 
Just curious, what was the reason?

Relaxing 05-12-2018 00:59

Re: Suggestion - arraycheck
 
I just wanted to make sure that all connected players have claimed their daily reward bonus. The array turns 1 for each id and if all were claimed, a minigame(menu) shows up. Also for my personal votemap system. To check if all players have voted, a simple way of getting it and to save TIME, those 4 seconds.
Generally a better way retrieving statistics for an array.

Mistrick 05-12-2018 07:00

Re: Suggestion - arraycheck
 
What problem to write a stock?
PHP Code:

/* Usage
 * array - Array to check
 * size - Size of array

 * Description
 * Checks if any element of array has a non-zero value

 * Return
 * 1 when any element is non-zero or
 * 0 when all elements are undefined/reseted/untouched/equal to 0*/
stock arraycheck(array[], size)
{
    for(new 
isizei++) {
        if(array[
i]) {
            return 
1;
        }
    }
    return 
0;



Black Rose 05-13-2018 13:12

Re: Suggestion - arraycheck
 
Quote:

Originally Posted by Relaxing (Post 2591776)
I just wanted to make sure that all connected players have claimed their daily reward bonus. The array turns 1 for each id and if all were claimed, a minigame(menu) shows up. Also for my personal votemap system. To check if all players have voted, a simple way of getting it and to save TIME, those 4 seconds.
Generally a better way retrieving statistics for an array.

By using bitfields instead of an array of booleans you can use !varBitField to see if it's empty. It will return positive if any value is true.
Worth it? Probably not.

Relaxing 05-13-2018 15:55

Re: Suggestion - arraycheck
 
Quote:

Originally Posted by Black Rose (Post 2592022)
By using bitfields instead of an array of booleans you can use !varBitField to see if it's empty. It will return positive if any value is true.
Worth it? Probably not.

That is an option. But why not for other posibilities.

meTaLiCroSS 05-22-2018 00:35

Re: Suggestion - arraycheck
 
Quote:

Originally Posted by Relaxing (Post 2592048)
That is an option. But why not for other posibilities.

You're actually making it slower with a native. Number of instructions that needs a native to interact on a module are a lot more than a simple loop which iterates over an array (and without needing module dependencies)

Relaxing 05-22-2018 02:25

Re: Suggestion - arraycheck
 
Quote:

Originally Posted by meTaLiCroSS (Post 2593219)
You're actually making it slower with a native. Number of instructions that needs a native to interact on a module are a lot more than a simple loop which iterates over an array (and without needing module dependencies)

That's not overpowered.
Code:
static cell AMX_NATIVE_CALL arrayset(AMX *amx, cell *params) {     cell value = params[2];     if (!value)     {         memset(get_amxaddr(amx, params[1]), 0, params[3] * sizeof(cell));     } else {         int size = params[3];         cell *addr = get_amxaddr(amx, params[1]);         for (int i=0; i<size; i++)         {             addr[i] = value;         }     }     return 1; }


All times are GMT -4. The time now is 12:56.

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