SA-MP Forums Archive
Please help!! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Please help!! (/showthread.php?tid=289262)



Please help!! - RcoN! - 10.10.2011

iam used crashdetect plugin

detect new warnings

Код:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
what is the error ?

my function in playerdeath

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    DeathCamera(playerid);
   
    Informacion[playerid][Deaths]++;
   
    GameTextForPlayer(killerid,KSMensajes[random(sizeof(KSMensajes))], 3000, 6);
   
    SendDeathMessage(killerid, playerid, reason);
   
    SetPlayerScore(killerid, GetPlayerScore(killerid) + 1);
   
    GivePlayerMoney(killerid,1000);
   

    if(EnZona[playerid] == 0)
    {
        OnWeaponDrop(playerid);
    }

    if(EnZona[killerid] == 0)
    {
        new ArmaCheck = GetPlayerWeapon(killerid);
        if(ArmaCheck == 35 || ArmaCheck == 36 || ArmaCheck == 37 || ArmaCheck == 38 || ArmaCheck == 39)
        {
        new string[300],wea[500];
        new PlayerName[MAX_PLAYER_NAME];
        GetPlayerName(killerid, PlayerName, MAX_PLAYER_NAME);
        new year,month,day; getdate(year, month, day);
        new hour,minute,second; gettime(hour,minute,second);
       
        format(string,sizeof(string),"* Admin NPC kickeo a %s (Armas prohibidas)", PlayerName);
        SendClientMessageToAll(naranja,string);
        print(string);
   
        format(wea,sizeof(wea),"{FFFFFF}Disculpa %s, tu has sido Kickeado del servidor!\
        \n\n{FFFFFF}Admin: NPC\
        \n{FFFFFF}Razon: Armas prohibidas.\
        \n{FFFFFF}Fecha: %i/%i/%i Hora: %i:%i :%i\
        \n\n{FFFFFF}* Intenta no ser un novato y vuelve sin cheats."
,PlayerName,day,month,year, hour, minute, second);
        ShowPlayerDialog(killerid, 8000, DIALOG_STYLE_MSGBOX, " *          ", wea, "OK", "");
   
        for(new p = 0; p < MAX_PLAYERS; p++) {
        if(IsPlayerConnected(p)) {
        PlayerPlaySound(p,1140,0.0,0.0,0.0);}}
        Kick(killerid);
        }
    }

    //Duelo
    new
        sString[428],
        pNamexd[MAX_PLAYER_NAME],
        zName[MAX_PLAYER_NAME],
        Float:Health,
        Float:Armor;

    if(g_IsPlayerDueling[playerid] == 1 && g_IsPlayerDueling[killerid] == 1)
    {
        GetPlayerHealth(killerid, Health);
        GetPlayerArmour(killerid, Armor);
        SetPlayerVirtualWorld(killerid, 0);
        SetPlayerVirtualWorld(playerid,0);
        SetPlayerInterior(killerid, 0);
        //SpawnPlayer(playerid);
        SpawnPlayer(killerid);

        GetPlayerName(playerid, pNamexd, MAX_PLAYER_NAME);
        GetPlayerName(killerid, zName, MAX_PLAYER_NAME);

        if(Health > 90.0 && Armor > 90.0)
        {
            format(sString, sizeof(sString),"{770CC9}* %s a ganado el duelo contra %s! y termino la batalla con %.2f de vida , y %.2f de blindaje!", zName,pNamexd,Health,Armor);
            SendClientMessageToAll(0xFF8040FF, sString);

            g_GotInvitedToDuel[playerid] = 0;g_HasInvitedToDuel[playerid] = 0;g_IsPlayerDueling[playerid]  = 0;
            g_GotInvitedToDuel[killerid] = 0;g_HasInvitedToDuel[killerid] = 0;g_IsPlayerDueling[killerid]  = 0;
            g_DuelInProgress = 0;

            EnZona[playerid] = 0;
            EnZona[killerid] = 0;
            return 1;
        }
        else
        {
            format(sString, sizeof(sString),"{770CC9}* %s a ganado el duelo contra %s! y termino la batalla con %.2f de vida , y %.2f de blindaje!", zName,pNamexd,Health,Armor);
            SendClientMessageToAll(0xFF8040FF, sString);

            g_GotInvitedToDuel[playerid] = 0;g_HasInvitedToDuel[playerid] = 0;g_IsPlayerDueling[playerid]  = 0;
            g_GotInvitedToDuel[killerid] = 0;g_HasInvitedToDuel[killerid] = 0;g_IsPlayerDueling[killerid]  = 0;
            g_DuelInProgress = 0;

            EnZona[playerid] = 0;
            EnZona[killerid] = 0;
            return 1;
       }
    }

    new Float:XD, Float:YD, Float:ZD;
    GetPlayerPos(killerid, XD, YD, ZD);
    if(IsPlayerInVehicle(killerid,GetPlayerVehicleID(killerid)))
    {
   
    if(reason == 49)//carkill
    {
            SetPlayerPos(killerid, XD, YD, ZD+50); GivePlayerWeapon(killerid, 46, 1);
            GameTextForPlayer(killerid, "~r~NO HAGAS CAR-KILL!", 4000, 4);

    }

    if(reason == 50)//helikill
    {
            SetPlayerPos(killerid, XD, YD, ZD+50); GivePlayerWeapon(killerid, 46, 1);
            GameTextForPlayer(killerid, "~r~NO HAGAS HELI-KILL!", 4000, 4);
    }
   
    if(Informacion[killerid][GodCar] == 1)
    {
    if(!IsPlayerInAnyVehicle(playerid) && GetPlayerState(killerid) == PLAYER_STATE_DRIVER && (reason == WEAPON_TEC9 || reason == WEAPON_UZI || reason == WEAPON_MP5) && GetDistanceBetweenPlayers(playerid,killerid) < 100)
    {
            SetPlayerPos(killerid, XD, YD, ZD+50); GivePlayerWeapon(killerid, 46, 1);
            GameTextForPlayer(killerid, "~g~~h~No hagas drive by!~n~~b~~h~autofix apagado!", 4000, 4);
            Informacion[killerid][GodCar] = 0;
        }
      }
    }
   
    if(Joined[playerid] == true)
    {
        JoinCount--;
        Joined[playerid] = false;
        DestroyVehicle(CreatedRaceVeh[playerid]);
        DisablePlayerRaceCheckpoint(playerid);
        CPProgess[playerid] = 0;
        KillTimer(InfoTimer[playerid]);
    }
   
    if(BuildRace[playerid] == 1)
    {
        BuildRace[playerid] = 0;
    }
   
    if(IsPlayerConnected(killerid) && killerid != INVALID_PLAYER_ID)
    {
        Informacion[killerid][Killsxd]++;
    }
   
    for(new x=0; x<MAX_PLAYERS; x++)
    if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Informacion[x][SpecID] == playerid)
    AdvanceSpectate(x);
    return 1;
}
please please helpme


Respuesta: Please help!! - matias1994 - 10.10.2011

if(EnZona[killerid] == 0)
{
new ArmaCheck = GetPlayerWeapon(killerid);
if(ArmaCheck == 35 || ArmaCheck == 36 || ArmaCheck == 37 || ArmaCheck == 38 || ArmaCheck == 39)
{
new string[300],wea[500];
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(killerid, PlayerName, MAX_PLAYER_NAME);
new year,month,day; getdate(year, month, day);
new hour,minute,second; gettime(hour,minute,second);

format(string,sizeof(string),"* Admin NPC kickeo a %s (Armas prohibidas)", PlayerName);
SendClientMessageToAll(naranja,string);
print(string);

format(wea,sizeof(wea),"{FFFFFF}Disculpa %s, tu has sido Kickeado del servidor!\
\n\n{FFFFFF}Admin: NPC\
\n{FFFFFF}Razon: Armas prohibidas.\
\n{FFFFFF}Fecha: %i/%i/%i Hora: %i:%i :%i\
\n\n{FFFFFF}* Intenta no ser un novato y vuelve sin cheats.",PlayerName,day,month,year, hour, minute, second);
ShowPlayerDialog(killerid, 8000, DIALOG_STYLE_MSGBOX, " * ", wea, "OK", "");

for(new p = 0; p < MAX_PLAYERS; p++)
{
if(IsPlayerConnected(p))
{
PlayerPlaySound(p,1140,0.0,0.0,0.0);
}
Kick(killerid);
}
}


Re: Please help!! - Dripac - 10.10.2011

Try to add at the end a bracket }


Re: Please help!! - grand.Theft.Otto - 10.10.2011

Matias, you can at least use [pawn] tags to make his code less confusing and sloppy.


Re: Please help!! - Joe Staff - 10.10.2011

The problem is that 'killerid' isn't always a playerid, sometimes it's INVALID_PLAYER_ID. You can't search an array for INVALID_PLAYER_ID without causing a script cease.

pawn Код:
if(killerid!=INVALID_PLAYER_ID)
{
    //Code containing killerid
}else{
    //player died of other causes
}



Respuesta: Please help!! - RcoN! - 10.10.2011

Quote:
Originally Posted by matias1994
Посмотреть сообщение
if(EnZona[killerid] == 0)
{
new ArmaCheck = GetPlayerWeapon(killerid);
if(ArmaCheck == 35 || ArmaCheck == 36 || ArmaCheck == 37 || ArmaCheck == 38 || ArmaCheck == 39)
{
new string[300],wea[500];
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(killerid, PlayerName, MAX_PLAYER_NAME);
new year,month,day; getdate(year, month, day);
new hour,minute,second; gettime(hour,minute,second);

format(string,sizeof(string),"* Admin NPC kickeo a %s (Armas prohibidas)", PlayerName);
SendClientMessageToAll(naranja,string);
print(string);

format(wea,sizeof(wea),"{FFFFFF}Disculpa %s, tu has sido Kickeado del servidor!\
\n\n{FFFFFF}Admin: NPC\
\n{FFFFFF}Razon: Armas prohibidas.\
\n{FFFFFF}Fecha: %i/%i/%i Hora: %i:%i :%i\
\n\n{FFFFFF}* Intenta no ser un novato y vuelve sin cheats.",PlayerName,day,month,year, hour, minute, second);
ShowPlayerDialog(killerid, 8000, DIALOG_STYLE_MSGBOX, " * ", wea, "OK", "");

for(new p = 0; p < MAX_PLAYERS; p++)
{
if(IsPlayerConnected(p))
{
PlayerPlaySound(p,1140,0.0,0.0,0.0);
}
Kick(killerid);
}
}
thanks


Re: Please help!! - GrimR - 10.10.2011

Out of bounds errors are usually due to you trying to access a non existant array index.

Often happens when you loop through or call access to an array index where you have forgotten to specify in the loop or call to the length of the array -1 (as the index starts from 0, not from 1).


Respuesta: Please help!! - RcoN! - 10.10.2011

The warning is ubicated in playerdeath

function:

pawn Код:
if(EnZona[killerid] == 0)
    {
        new ArmaCheck = GetPlayerWeapon(killerid);
        if(ArmaCheck == 35 || ArmaCheck == 36 || ArmaCheck == 37 || ArmaCheck == 38 || ArmaCheck == 39)
        {
            new string[300],wea[500];
            new PlayerName[MAX_PLAYER_NAME];
            GetPlayerName(killerid, PlayerName, MAX_PLAYER_NAME);
            new year,month,day; getdate(year, month, day);
            new hour,minute,second; gettime(hour,minute,second);
       
            format(string,sizeof(string),"* Admin NPC kickeo a %s (Armas prohibidas)", PlayerName);
            SendClientMessageToAll(naranja,string);
            print(string);
   
            format(wea,sizeof(wea),"{FFFFFF}Disculpa %s, tu has sido Kickeado del servidor!\
            \n\n{FFFFFF}Admin: NPC\
            \n{FFFFFF}Razon: Armas prohibidas.\
            \n{FFFFFF}Fecha: %i/%i/%i Hora: %i:%i :%i\
            \n\n{FFFFFF}* Intenta no ser un novato y vuelve sin cheats."
,PlayerName,day,month,year, hour, minute, second);
            ShowPlayerDialog(killerid, 8000, DIALOG_STYLE_MSGBOX, " *          ", wea, "OK", "");
   
            for(new p = 0; p < MAX_PLAYERS; p++)
            {
                if(IsPlayerConnected(p))
                {
                    PlayerPlaySound(p,1140,0.0,0.0,0.0);
                    Kick(killerid);
                }
            }
        }
    }
Warings in crashdetect.log
Код:
Plugin succesfully loaded (version 3.1.3)
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
gamemodes\FTS.amx: During execution of OnPlayerDeath:
gamemodes\FTS.amx: Run time error 4: "Array index out of bounds".
Plugin succesfully loaded (version 3.1.3)



Re: Please help!! - GrimR - 10.10.2011

The problem is with:

pawn Код:
for(new p = 0; p < MAX_PLAYERS; p++)
            {
                if(IsPlayerConnected(p))
                {
                    PlayerPlaySound(p,1140,0.0,0.0,0.0);
                    Kick(killerid);
                }
            }
If players start from 0 ID, I would assume your max players is set 1 too high, so you either need to lower max players by 1 or in loops put MAX_PLAYERS-1.


Respuesta: Re: Please help!! - RcoN! - 10.10.2011

Quote:
Originally Posted by GrimR
Посмотреть сообщение
The problem is with:

pawn Код:
for(new p = 0; p < MAX_PLAYERS; p++)
            {
                if(IsPlayerConnected(p))
                {
                    PlayerPlaySound(p,1140,0.0,0.0,0.0);
                    Kick(killerid);
                }
            }
If players start from 0 ID, I would assume your max players is set 1 too high, so you either need to lower max players by 1 or in loops put MAX_PLAYERS-1.
pawn Код:
for(new p = -1; p < MAX_PLAYERS; p++)
            {
                if(IsPlayerConnected(p))
                {
                    PlayerPlaySound(p,1140,0.0,0.0,0.0);
                    Kick(killerid);
                }
            }
?