Raised This Month: $32 Target: $400
 8% 

Suggestion - arraycheck


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 05-11-2018 , 15:06   Suggestion - arraycheck
Reply With Quote #1

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)
__________________
Relaxing is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 05-11-2018 , 16:20   Re: Suggestion - arraycheck
Reply With Quote #2

That isn't really useful and takes only like 3 lines of code to write. This won't make it into AMXX.
__________________
klippy is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 05-11-2018 , 16:24   Re: Suggestion - arraycheck
Reply With Quote #3

Quote:
Originally Posted by KliPPy View Post
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.
__________________
Relaxing is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-11-2018 , 16:33   Re: Suggestion - arraycheck
Reply With Quote #4

Just curious, what was the reason?
__________________
HamletEagle is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 05-12-2018 , 00:59   Re: Suggestion - arraycheck
Reply With Quote #5

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.
__________________
Relaxing is offline
Mistrick
Senior Member
Join Date: Aug 2012
Location: Russia
Old 05-12-2018 , 07:00   Re: Suggestion - arraycheck
Reply With Quote #6

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;

Mistrick is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-13-2018 , 13:12   Re: Suggestion - arraycheck
Reply With Quote #7

Quote:
Originally Posted by Relaxing View Post
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.
__________________
Black Rose is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 05-13-2018 , 15:55   Re: Suggestion - arraycheck
Reply With Quote #8

Quote:
Originally Posted by Black Rose View Post
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.
__________________
Relaxing is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 05-22-2018 , 00:35   Re: Suggestion - arraycheck
Reply With Quote #9

Quote:
Originally Posted by Relaxing View Post
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)
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 05-22-2018 , 02:25   Re: Suggestion - arraycheck
Reply With Quote #10

Quote:
Originally Posted by meTaLiCroSS View Post
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; }
__________________
Relaxing is offline
Reply


Thread Tools
Display Modes

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 08:25.


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