Raised This Month: $ Target: $400
 0% 

Update few plugins to use MAX_PLAYERS(1.8.3)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xkp
Member
Join Date: Jan 2015
Location: AlliedLand
Old 01-31-2015 , 05:58   Update few plugins to use MAX_PLAYERS(1.8.3)
Reply With Quote #1

Well as many of you know or not known Amxmodx are keep updating & optimize stuff (1.8.3-dev) and thats okey but it is very difficult to understand what exactly are repaired or fixed.

So i try to take a look at git and i find the new functionality in _amxconst_ MAX_PLAYERS that defines MAX_PLAYERS but when I try to update some of the plugins I encounter a lot of errors.

I like to update this plugin first: Voteban made by @Alka - i use the latest non-public version becouse is far more updated in this posts.

Original voteban-plugin:
Code:
#define MAX_PLAYERS 32 // All is here new g_iData[MAX_PLAYERS+1][MAX_PLAYERS+1];
New functuality from AMXX , amxconst.inc
---> #define MAX_PLAYERS 33 /* Maximum number of players AMX Mod X supports */

=================
With amxconst MAX_PLAYERS 33 and without + 1
Code:
new g_iData[MAX_PLAYERS][MAX_PLAYERS];
This returns: Error: Array index out of bounds (variable "g_iData") on line 66
=================
Without #define MAX_PLAYERS 32
Code:
new g_iData[MAX_PLAYERS+1][MAX_PLAYERS+1];
This is working but 33+1 (34?) - over the max limit.

Last edited by xkp; 01-31-2015 at 07:14.
xkp is offline
Send a message via Skype™ to xkp
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-31-2015 , 06:57   Re: Update few plugins to use MAX_PLAYERS(1.8.3)
Reply With Quote #2

If you compile the original plugin as it is, MAX_PLAYERS will be redefine to 32. You will get a warning with compiler but can be ignored without problem.

If you want to compile without warning, just remove the MAX_PLAYERS definition in plugin, and the +1 where MAX_PLAYERS is used (so what you did, but you did not removed previous MAX_PLAYERS definition)
__________________

Last edited by Arkshine; 01-31-2015 at 06:59.
Arkshine is offline
xkp
Member
Join Date: Jan 2015
Location: AlliedLand
Old 01-31-2015 , 07:10   Re: Update few plugins to use MAX_PLAYERS(1.8.3)
Reply With Quote #3

Well i removed the definion of MAX_PLAYERS from the source, and i remove the + 1 in g_iData.
Spoiler

Code:
AMX Mod X Compiler 1.8.3-dev+4537
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2013 AMX Mod X Team

Error: Array index out of bounds (variable "g_iData") on line 88
Error: Array index out of bounds (variable "g_iData") on line 90
Error: Array index out of bounds (variable "g_iData") on line 91
Error: Array index out of bounds (variable "g_iData") on line 98
Error: Array index out of bounds (variable "g_iData") on line 99
Error: Array index out of bounds (variable "g_iData") on line 112
Error: Array index out of bounds (variable "g_iData") on line 120
Error: Array index out of bounds (variable "g_iData") on line 184
Error: Array index out of bounds (variable "g_iData") on line 199
Error: Array index out of bounds (variable "g_iData") on line 222
Error: Array index out of bounds (variable "g_iData") on line 223
Error: Array index out of bounds (variable "g_iData") on line 233
Error: Array index out of bounds (variable "g_iData") on line 238

13 Errors.
Could not locate output file C:\Documents and Settings\Xakep\Desktop\Copy of voteban.amx (compile failed).

Last edited by xkp; 01-31-2015 at 07:11.
xkp is offline
Send a message via Skype™ to xkp
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-31-2015 , 07:20   Re: Update few plugins to use MAX_PLAYERS(1.8.3)
Reply With Quote #4

Yeah, author uses a very weird way to set/get/update vote datas.

g_iData[%0][MAX_PLAYERS-1] <= there, you need to add -1 (since MAX_PLAYERS is now 33 and g_iData has a max size of 33 ; purpose if this macro is set data to last entry, yeah it's fucking weird).
__________________

Last edited by Arkshine; 01-31-2015 at 07:23.
Arkshine is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 01-31-2015 , 08:24   Re: Update few plugins to use MAX_PLAYERS(1.8.3)
Reply With Quote #5

why is the MAX_PLAYERS 33 in the include??
jimaway is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-31-2015 , 08:49   Re: Update few plugins to use MAX_PLAYERS(1.8.3)
Reply With Quote #6

Because that's something almost all plugins are using, declaring such constants and doing +1 each time, so it makes sense to add it with 33 as value for convenience and readability. But it's okay, if you plugin has such define, it will be redefine with your value.
__________________
Arkshine is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-31-2015 , 11:46   Re: Update few plugins to use MAX_PLAYERS(1.8.3)
Reply With Quote #7

I think it's technically misleading because 32 is the actual number of max players. Adding 1 isn't really an issue IMO and is just an artifact of having zero-based array indexing, I just use 33 literally instead of defining anything since it will NEVER change.
__________________

Last edited by fysiks; 02-01-2015 at 02:04. Reason: fixed typo
fysiks is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-31-2015 , 14:14   Re: Update few plugins to use MAX_PLAYERS(1.8.3)
Reply With Quote #8

It's technically correct. Well, I wanted to use 32, because it makes sense since it's the technical limit, but we answered me (The motherfucker Nextra) it would be logic to use 33 as it's always this way MAX_PLAYERS is used in plugins. HIS FAULT! Well, if people have some difficulty with it, I guess we could change that to 32. It's still dev version, so any changes can happen!
__________________
Arkshine is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 01-31-2015 , 21:18   Re: Update few plugins to use MAX_PLAYERS(1.8.3)
Reply With Quote #9

It should be 32. Now it can't be used like this:
PHP Code:
new players[MAX_PLAYERS], num;
get_players(playersnum); 
Personally I've always used MAX_PLAYERS + 1 for player ID arrays.

Anyway, regarding the topic, the easiest way to remove the warning would be to undefine MAX_PLAYERS before it is defined in the plugin source file.
__________________

Last edited by hleV; 01-31-2015 at 21:23.
hleV is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-01-2015 , 00:34   Re: Update few plugins to use MAX_PLAYERS(1.8.3)
Reply With Quote #10

I agree, should be 32. When someone is using it to size an array, then they should know to add 1.
__________________
Bugsy is offline
Reply



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 09:51.


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