Portal SAMP
[Ajuda] un time error 4: "Array index out of bounds" - Versão de Impressão

+- Portal SAMP (https://portalsamp.com)
+-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5)
+--- Fórum: Área de suporte (https://portalsamp.com/forumdisplay.php?fid=6)
+--- Tópico: [Ajuda] un time error 4: "Array index out of bounds" (/showthread.php?tid=260)



un time error 4: "Array index out of bounds" - Rev - 31/10/2020

Como posso resolver isso?
Código:
[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at index 375831900 past array upper bound 1000
[debug] AMX backtrace:
[debug] #0 0034b370 in ?? (1, 869072810, 387008444, 367466648, 375831900) from gm.amx
[debug] #1 0058f5a0 in public dialog_DutyMenu (0, 1, 0, 387658312) from gm.amx
[debug] #2 native CallLocalFunction () from samp-server.exe
[debug] #3 0001e534 in public OnDialogResponse (0, 32700, 1, 0, 387658240) from gm.amx


Acho que o problema está aqui, mas não consigo identificar, código abaixo.

Código:
Dialog:DutyMenu(playerid, response, listitem, inputtext[])
{
if (!response) return 1;
   
    new faction = PlayerInfo[playerid][pFaction];
   
if (faction == 0 || !IsFactionLegal(faction)) return 1;
       
switch(listitem)
{
    case 0://duty
    {
if (CheckAdmin(playerid, ADMIN_LEVEL_1)) return SendErrorMessage(playerid, "Você tem que sair do serviço administrativo.");
    if (pTemp[playerid][pTaser]) return SendErrorMessage(playerid, "Você precisa remover a taser.");
    if (pTemp[playerid][pPatrol]) return SendErrorMessage(playerid, "Você tem que sair da patrulha (/callsign).");
            if (!IsPlayerAtUniform(playerid)) return SendErrorMessage(playerid, "Você não está no vestiário.");
   
        if (!PlayerInfo[playerid][pOnDuty])
{
if (PlayerInfo[playerid][pPlayerWeapon])
{
if (CheckInv(playerid)) cmd::putgun(playerid, "");
else return SendErrorMessage(playerid, "Coloque as armas no inventário primeiro.");
}

SetPVarInt(playerid, #pDelay, 1);

new count;
    for(new i; i < MAX_INV_SLOTS; i++)
{
if (inventory_items[Inventory[playerid][i][pInvItem]][itemType] != ITEM_TYPE_WEAPON &&
inventory_items[Inventory[playerid][i][pInvItem]][itemType] != ITEM_TYPE_AMMO) continue;

if (count >= MAX_COP_SLOTS)
{
for(new j; j < MAX_INV_SLOTS; j++)
{
PlayerInfo[playerid][pCopItem][j] = 0;
PlayerInfo[playerid][pCopQ][j] = 0;
PlayerInfo[playerid][pCopEx][j] = 0;
PlayerInfo[playerid][pCopS][j] = 0;
}

SetPVarInt(playerid, #pDelay, 0);
SendAdmMessage("%s tem um grande número de armas no inventário. [AVISO]", GetNameEx(playerid));
return SendErrorMessage(playerid, "Você tem muitas armas/munições! (Você só pode colocar em uma gaveta: 5 Itens)");
}

    PlayerInfo[playerid][pCopItem][count] = Inventory[playerid][i][pInvItem];
    PlayerInfo[playerid][pCopQ][count] = Inventory[playerid][i][pInvQ];
PlayerInfo[playerid][pCopEx][count] = Inventory[playerid][i][pInvEx];
PlayerInfo[playerid][pCopS][count] = Inventory[playerid][i][pInvItem];

count++;
}

ResetPlayerWeaponsEx(playerid);

if (IsFactionPolice(faction))
{
SendNearbyMessage(Range_Normal, playerid, COLOR_PURPLE, "%s %s pegou seu distintivo em seu armário.", GetRankName(playerid), GetNameWithMask(playerid));
}

PlayerInfo[playerid][pOnDuty] = 1;
SetPlayerColor(playerid, RemoveAlpha(Factions[faction][fColor]));
        SendFactionMessage(faction, COLOR_POLICECHAT, "** HQ: %s %s está em serviço. **", GetRankName(playerid), GetNameEx(playerid));
                GameTextForPlayer(playerid, "~g~ON DUTY", 5000, 3);

cmd::duty(playerid, "");
Save_User(playerid);

SetPVarInt(playerid, #pDelay, 0);
return 1;
}

ResetPlayerWeaponsEx(playerid);

if (IsPlayerAttachedObjectSlotUsed(playerid, 5)) RemovePlayerAttachedObject(playerid, 5);
if (IsPlayerAttachedObjectSlotUsed(playerid, 6)) RemovePlayerAttachedObject(playerid, 6);
    if (IsPlayerAttachedObjectSlotUsed(playerid, 7)) RemovePlayerAttachedObject(playerid, 7);

new copsitems = 0, playersitems = 0;
for(new i = 0; i < MAX_INV_SLOTS; i++)
{
if (i < MAX_COP_SLOTS) if (PlayerInfo[playerid][pCopItem][i]) copsitems++;
if (!Inventory[playerid][i][pInvItem]) playersitems++;
}

if (playersitems - copsitems >= 0)
{
for(new i = 0; i < MAX_COP_SLOTS; i++)
{
if (PlayerInfo[playerid][pCopItem][i])
{
new slotid = GetInvNextSlot(playerid);
if (slotid == -1) continue;

Inventory[playerid][slotid][pInvItem] = PlayerInfo[playerid][pCopItem][i];
Inventory[playerid][slotid][pInvQ] = PlayerInfo[playerid][pCopQ][i];
Inventory[playerid][slotid][pInvEx] = PlayerInfo[playerid][pCopEx][i];
Inventory[playerid][slotid][pInvS] = PlayerInfo[playerid][pCopS][i];
}

PlayerInfo[playerid][pCopItem][i] = 0;
PlayerInfo[playerid][pCopQ][i] = 0;
PlayerInfo[playerid][pCopEx][i] = 0;
PlayerInfo[playerid][pCopS][i] = 0;
}
}
else return SendErrorMessage(playerid, "Você não pode tirar nada de seu armário, seu inventário está cheio.");

if (IsFactionPolice(faction))
{
SendNearbyMessage(Range_Normal, playerid, COLOR_PURPLE, "%s %s coloca seu distintívo no armário", GetRankName(playerid), GetNameWithMask(playerid));
}

SendFactionMessage(faction, IsFactionPolice(faction) ? COLOR_LIGHTBLUE : LSFD_DUTY, "** HQ: %s %s saiu de serviço. **", GetRankName(playerid), GetNameEx(playerid));
GameTextForPlayer(playerid, "~r~OFF DUTY", 5000, 3);

DestroyAllBort(playerid);
    PlayerInfo[playerid][pChar] = 0;
PlayerInfo[playerid][pSwatDuty] = 0;
PlayerInfo[playerid][pOnDuty] = 0;

CallRemoteFunction("LoadHolsters","i",playerid);
SetPlayerColor(playerid, TEAM_HIT_COLOR);
SetPlayerArmour(playerid, 0);
SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
cmd::duty(playerid, "");

return Save_User(playerid);
    }
    case 1:
{
    if (!PlayerInfo[playerid][pOnDuty]) return SendErrorMessage(playerid, "Você deve estar em serviço.");
            if (!IsPlayerAtUniform(playerid)) return SendErrorMessage(playerid, "Você não está no vestiário.");
            if (PlayerInfo[playerid][pSwatDuty]) return SendErrorMessage(playerid, "Coloque o traje de S.W.A.T.");
               
if (IsFactionPolice(faction))
{
new submes[16],
mes[sizeof(police_skins)*sizeof(submes)];

for(new i = 0; i < sizeof(police_skins); i++)
{
format(submes, sizeof(submes), "%i\tID: %i\n", police_skins[i], i);
strcat(mes, submes);
}
Dialog_Show(playerid, MODEL_SELECTION_UNIFORM, DIALOG_STYLE_PREVIEW_MODEL, "Selecione um uniforme", mes, "Selecionar", "Cancelar");
}
else if (IsFactionMedic(faction) || IsFactionFire(faction))
    {
new submes[16], mes[sizeof(fd_skins)*sizeof(submes)];

for(new i = 0; i < sizeof(fd_skins); i++)
{
format(submes, sizeof(submes), "%i\tID: %i\n", fd_skins[i], i);
strcat(mes, submes);
}
Dialog_Show(playerid, MODEL_SELECTION_UNIFORM, DIALOG_STYLE_PREVIEW_MODEL, "Selecione um uniforme", mes, "Selecionar", "Cancelar");
}
else if (IsFactionDocs(faction))
    {
new mes[sizeof(docs_skins)*128];
for(new i = 0; i < sizeof(docs_skins); i++)
{
format(mes, sizeof(mes), "%s%i\tID: %i\n", mes, docs_skins[i], docs_skins[i]);
}
Dialog_Show(playerid, MODEL_SELECTION_UNIFORM, DIALOG_STYLE_PREVIEW_MODEL, "Selecione um uniforme", mes, "Selecionar", "Cancelar");
}
else if (IsFactionCity(faction))
{
new submes[128], mes[sizeof(city_skins)*sizeof(submes)];

for(new i = 0; i < sizeof(city_skins); i++)
{
format(submes, sizeof(submes), "%i\tID: %i\n", city_skins[i], i);
strcat(mes, submes);
}
Dialog_Show(playerid, MODEL_SELECTION_UNIFORM, DIALOG_STYLE_PREVIEW_MODEL, "Selecione um uniforme", mes, "Selecionar", "Cancelar");
}

else SendErrorMessage(playerid, "Esta função não está disponível para sua facção.");
}
case 2:
    {
        if (!PlayerInfo[playerid][pOnDuty]) return SendErrorMessage(playerid, "Primeiro você precisa entrar em serviço.");
            if (!IsPlayerAtUniform(playerid) && !IsPlayerAtSecondUniform(playerid)) return SendErrorMessage(playerid, "Você não está no vertiario.");
   
if (IsFactionPolice(faction))
{
return Dialog_Show(playerid, LSPDArmoury, DIALOG_STYLE_LIST, "Equipamentos & armas", "• Rádio\n• Armas\n• S.W.A.T Equipamento", "Selecionar", "Voltar");
}
else if (IsFactionDocs(faction))
{
return Dialog_Show(playerid, DOCSGUN, DIALOG_STYLE_LIST, "Armas", "• Rádio\n• Cacetete\n• Spray de pimenta\n• Desert Eagle ( .50AE .ext )\n\t{ffc46a}- Pegar mais cartuchos ( .50AE .ext )\n{FFFFFF}• MP5 ( 9x19mm .ext )\n\t{ffc46a}- Pegar mais cartuchos ( 9x19mm .ext )\n{FFFFFF}• Shotgun ( 12-G BIRDSHOT )\n\t{ffc46a}- Pegar mais cartuchos ( 12-G BIRDSHOT )\n\t{ffc46a}- Pegar munição não letal ( 12-G BEANBAG )\n{FFFFFF}• М4 ( 5.56x45mm (drum) )\n\t{ffc46a}- Pegar mais cartuchos ( 5.56x45mm (drum) )\n\t{ffc46a}- Pegar munição não letal ( 5.56x45mm (rubber) )\n{FFFFFF}• Sniper Rifle (7.62x51mm)\n\t{ffc46a}- Pegar mais cartuchos ( 7.62x51mm )\n{FFFFFF}• Газовая граната\n• Фотокамера\n{FF6347}• Entregar todas as armas", "Selecionar", "Cancelar");
}
else if (IsFactionCity(faction))
{
    return Dialog_Show(playerid, CITYGUN, DIALOG_STYLE_LIST, "Armas", "• Rádio\n• Desert Eagle ( .50AE .ext )\n\t{ffc46a}- Pegar mais cartuchos ( .50AE .ext )\n{FFFFFF}• MP5 ( 9x19mm .ext )\n\t{ffc46a}- Pegar mais cartuchos ( 9x19mm .ext )\n{FFFFFF}• М4 ( 5.56x45mm (drum) )\n\t{ffc46a}- Pegar mais cartuchos ( 5.56x45mm (drum) )\n\t{ffc46a}- Pegar munição não letal ( 5.56x45mm (rubber) )\n{FF6347}• Entregar todas as armas", "Selecionar", "Cancelar");
}
else if (IsFactionFire(faction) || IsFactionMedic(faction))
{
        return Dialog_Show(playerid, FDArmoury, DIALOG_STYLE_LIST, "Equipamento", "• Rádio\n• Motosserra\n• Extintor de incêndio\n{FF6347}• Entregar todos os equipamentos", "Selecionar", "Voltar");
}
    }
    case 3:
    {
        if (!PlayerInfo[playerid][pOnDuty]) return SendErrorMessage(playerid, "Primeiro você precisa entrar em serviço.");
        if (!IsFactionLegal(faction)) return SendErrorMessage(playerid, "Você deve ser um policial/paramédico.");
            if (!IsPlayerAtUniform(playerid) && !IsPlayerAtSecondUniform(playerid)) return SendErrorMessage(playerid, "Você não está no vestiário.");
   
    if (IsFactionMedic(faction) || IsFactionFire(faction)) SetPlayerArmour(playerid, 50.0);
else SetPlayerArmour(playerid, 100.0);

SendSyntaxMessage(playerid, "Você coloca um colete à prova de balas.");
            cmd::duty(playerid, "");
    }
    case 4:
    {
        if (!PlayerInfo[playerid][pOnDuty]) return SendErrorMessage(playerid, "Primeiro você precisa entrar em serviço (/duty).");
            if (!IsPlayerAtUniform(playerid)) return SendErrorMessage(playerid, "Você não está no vestiário.");

    SetPlayerHealth(playerid, 100.0);
   
SendSyntaxMessage(playerid, "Você restaurou a saúde.");
    cmd::duty(playerid, "");
    }
}
return 1;
}



RE: un time error 4: "Array index out of bounds" - Santana - 02/11/2020

analisei o codigo citado e não achei nada, provavelmente o erro está em uma das callback chamada, que olha, não são poucas, me fale o que deseja fazer e eu posso ver se arrumo para você