RemovePlayerWeaponsEx [DEBUG] Spam
#1

Код:
[13:39:19] [debug] Run time error 4: "Array index out of bounds"
[13:39:19] [debug] Accessing element at index 50 past array upper bound 43
[13:39:19] [debug] AMX backtrace:
[13:39:19] [debug] #0 002831ec in public RemovePlayerWeaponEx (playerid=2, weaponid=50) at CSRPbeta.pwn:51451
[13:39:19] [debug] #1 00294730 in public OnPlayerUpdate (playerid=2) at CSRPbeta.pwn:53121
[13:39:19] [debug] Run time error 4: "Array index out of bounds"
[13:39:19] [debug] Accessing element at index 50 past array upper bound 43
[13:39:19] [debug] AMX backtrace:
[13:39:19] [debug] #0 002831ec in public RemovePlayerWeaponEx (playerid=2, weaponid=50) at CSRPbeta.pwn:51451
[13:39:19] [debug] #1 00294730 in public OnPlayerUpdate (playerid=2) at CSRPbeta.pwn:53121
[13:39:19] [debug] Run time error 4: "Array index out of bounds"
[13:39:19] [debug] Accessing element at index 50 past array upper bound 43
[13:39:19] [debug] AMX backtrace:
[13:39:19] [debug] #0 002831ec in public RemovePlayerWeaponEx (playerid=2, weaponid=50) at CSRPbeta.pwn:51451
[13:39:19] [debug] #1 00294730 in public OnPlayerUpdate (playerid=2) at CSRPbeta.pwn:53121
[13:39:19] [debug] Run time error 4: "Array index out of bounds"
[13:39:19] [debug] Accessing element at index 50 past array upper bound 43
[13:39:19] [debug] AMX backtrace:
[13:39:19] [debug] #0 002831ec in public RemovePlayerWeaponEx (playerid=2, weaponid=50) at CSRPbeta.pwn:51451
[13:39:19] [debug] #1 00294730 in public OnPlayerUpdate (playerid=2) at CSRPbeta.pwn:53121
We're not sure exactly what is causing this. We do know that this tends to happen the more players that are on the server.
I've asked one person to take a look, and he's asked me to adjust this:
pawn Код:
new plyWeapons[14] = 0;
new plyAmmo[14] = 0;
to 13 and then try 14 (was originally 12)
However, both times I still got spam in the server logs. Now I know I am missing something here, and I'm going to feel really really stupid when it's found.

HERE IS THE OnPlayerUpdate: http://pastebin.com/kkLabssZ

pawn Код:
forward RemovePlayerWeaponEx(playerid, weaponid);
public RemovePlayerWeaponEx(playerid, weaponid)
{
    new plyWeapons[14] = 0;
    new plyAmmo[14] = 0;
    for(new slot = 0; slot != 12; slot++)
    {
        new wep, ammo;
        GetPlayerWeaponData(playerid, slot, wep, ammo);

        if(wep != weaponid && ammo != 0)
        {
            GetPlayerWeaponData(playerid, slot, plyWeapons[slot], plyAmmo[slot]);
        }
    }

    ResetPlayerWeaponsEx(playerid);
    for(new slot = 0; slot != 12; slot++)
    {
        if(plyAmmo[slot] != 0)
        {
            GivePlayerWeaponEx(playerid, plyWeapons[slot], plyAmmo[slot]);
        }
    }
    SetPlayerArmedWeapon(playerid,0);
    Weapons[playerid][weaponid] = 0;
    return 1;
}

forward IsAnOwnableCar(vehid);
public IsAnOwnableCar(vehid)
{
    if(VehicleOwned[vehid] != SCRIPT_CARS)
    {
        return 1;
    }
    return 0;
}
Reply
#2

problem with this variable:
pawn Код:
Weapons[playerid][weaponid]
second dimension is 43 cells big, and you're accessing 50'th cell. You need to resize your array.
Reply
#3

Quote:
Originally Posted by Scottas
Посмотреть сообщение
problem with this variable:
pawn Код:
Weapons[playerid][weaponid]
second dimension is 43 cells big, and you're accessing 50'th cell. You need to resize your array.
I'm assuming this is what you're talking about? I found this at the top of the script:

pawn Код:
new Weapons[MAX_PLAYERS][44];
Reply
#4

You need to extend size to 'max weapon id+1' size.
Reply
#5

Quote:
Originally Posted by Scottas
Посмотреть сообщение
You need to extend size to 'max weapon id+1' size.
I'll be honest, and I know you're going to laugh (or someone will) but you've got me confused
Reply
#6

The weapons variable is the issue instead of re-sizing the array I would make a some kind of valid weapon check function before doing any code in this function for instance.

pawn Код:
IsValidWeapon(weaponid)
{
    switch(weaponid)
    {
        case 0: { return 0; }
        case 50: { return 0; }
    }
    return 1;
}
Then all you need to do is put in if(!IsValidWeapon(weaponid)) return 0;
Reply
#7

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
The weapons variable is the issue instead of re-sizing the array I would make a some kind of valid weapon check function before doing any code in this function for instance.

pawn Код:
IsValidWeapon(weaponid)
{
    switch(weaponid)
    {
        case 0: { return 0; }
        case 50: { return 0; }
    }
    return 1;
}
Then all you need to do is put in if(!IsValidWeapon(weaponid)) return 0;
If I'm not mistaking, I think this is what you're talking about. If you see the OnPlayerUpdate in the pastebin link i put, it's called.

pawn Код:
forward IsBadGun(weaponid);
public IsBadGun(weaponid)
{
    if(weaponid==8||weaponid==9||(weaponid>15&&weaponid<22)||weaponid==27||(weaponid>34&&weaponid<43)||weaponid>43)
    {
        return 1;
    }
    return 0;
}
Reply
#8

Well it's fucked up then look

(weaponid>34&&weaponid<43)||weaponid>43)

Use a damn switch not this colluded if-statement non-sense you got going on.
Reply
#9

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Well it's fucked up then look

(weaponid>34&&weaponid<43)||weaponid>43)

Use a damn switch not this colluded if-statement non-sense you got going on.
Ok first off: I'm learning as I'm going
Second off, I didn't even put that

Not everyone starts off as a fucking expert, so no need to be like this. Just because you may know everything under the sun about this, doesn't make you any better. Why not share what you know? If not, get the hell out of the scripting help section and let someone else that's willing to share their knowledge and have some patience assist people that's willing to learn.

And P.S.
Your signature pretty much shows your true character
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)