Raised This Month: $51 Target: $400
 12% 

[TF2] Array Index is out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Bitl
Senior Member
Join Date: Jul 2012
Old 10-11-2013 , 19:21   Re: [TF2] Array Index is out of bounds
Reply With Quote #11

Sorry to bump this, but the problem is still there when I was working on a new plugin.

Here's an example:

Code:
new RandomNumbersArrayScout[20] = {45,220,448,772,46,163,222,449,773,812,44,221,317,325,349,355,450,452,572,648};
    new randomnumScout = GetRandomInt(0, 20);

new RandomNumbersArrayRaresScout[2] = {160,423};
    new randomnumRaresScout = GetRandomInt(0, 2);

new rareChance = GetRandomInt(0,200);

if (TF2_GetPlayerClass(client) == TFClass_Scout)
    {
        if (IsValidClient(client))
        {
            if (rareChance == 200)
            {
                TF2Items_GiveWeapon(client, RandomNumbersArrayRaresScout[randomnumRaresScout]);
            }
            else
            {
                TF2Items_GiveWeapon(client, RandomNumbersArrayScout[randomnumScout]);
            }
        }
    }
Any way to fix this?
__________________
My Plugins
Modified Plugins:
Building Spawner
Monster
It's Raining Men!
Tutorials:
Custom Gamemode

I DON'T DO PLUGIN REQUESTS.
Bitl is offline
noodleboy347
AlliedModders Donor
Join Date: Mar 2009
Old 10-11-2013 , 23:10   Re: [TF2] Array Index is out of bounds
Reply With Quote #12

I don't think you're getting it

just use this

PHP Code:
new RandomNumbersArrayScout[20] = {45,220,448,772,46,163,222,449,773,812,44,221,317,325,349,355,450,452,572,648};
new 
randomnumScout GetRandomInt(0sizeof(RandomNumbersArrayScout)-1); // 0-19

new RandomNumbersArrayRaresScout[2] = {160,423};
new 
randomnumRaresScout GetRandomInt(0sizeof(RandomNumbersArrayRaresScout)-1); // 0-1
/* RandomNumbersArrayRaresScout[0] = 160;
    RandomNumbersArrayRaresScout[1] = 423;
    RandomNumbersArrayRaresScout[2] = invalid; */

new rareChance GetRandomInt(0,200);

if(
TF2_GetPlayerClass(client) == TFClass_Scout)
{
    if(
IsValidClient(client))
    {
        if(
rareChance == 200)
        {
            
TF2Items_GiveWeapon(clientRandomNumbersArrayRaresScout[randomnumRaresScout]);
        }
        else
        {
            
TF2Items_GiveWeapon(clientRandomNumbersArrayScout[randomnumScout]);
        }
    }


Last edited by noodleboy347; 10-11-2013 at 23:12.
noodleboy347 is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 10-12-2013 , 02:10   Re: [TF2] Array Index is out of bounds
Reply With Quote #13

one more note about array indexes
String is also array of chars, so

let's take some word - constant (8 characters)
new String:strBuffer[9] = "constant";

so array of chars will look like:
1st line - indexes
2nd line - characters
Code:
0 1 2 3 4 5 6 7 8  9
c o n s t a n t \0 ?
that's why GetRandomInt( 0, sizeof( strBuffer ) - 1 ).

alsio there's odd(?) item #8 - \0 - that's because in (Source-)Pawn (as well as in other languages based on C/C++) null character means end of string, and it is required.

best explain ever.
__________________
Leonardo is offline
Bitl
Senior Member
Join Date: Jul 2012
Old 10-12-2013 , 14:58   Re: [TF2] Array Index is out of bounds
Reply With Quote #14

Thanks guys
__________________
My Plugins
Modified Plugins:
Building Spawner
Monster
It's Raining Men!
Tutorials:
Custom Gamemode

I DON'T DO PLUGIN REQUESTS.
Bitl 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 17:02.


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