Debug problems
#1

pawn Код:
[10:20:10] [debug] Run time error 4: "Array index out of bounds"
[10:20:10] [debug]  Accessing element at negative index -1
[10:20:10] [debug] AMX backtrace:
[10:20:10] [debug] #0 0011e110 in GetHouseMaxSleepHp (houseid=-1) at C:\AMD\rp.pwn:28831
[10:20:10] [debug] #1 00052314 in public GeneralListener () at C:\AMD\rp.pwn:6836
[10:20:12] [debug] Run time error 4: "Array index out of bounds"
pawn Код:
//28831

stock GetHouseMaxSleepHp(houseid)
{

    return (50 + (10 * HouseInfo[houseid][hUpgrades][HOUSE_UPGRADE_BED]));

}
pawn Код:
//6836
                               new Float:hp;
                GetPlayerHealth(playerid,hp);
                if(hp < GetHouseMaxSleepHp(in_house[playerid]))
                {

                    hp += 1.0;
                    SetPlayerHealth(playerid,hp);
                    new chance = random(100);
                    if(chance > 90) { SendEmote(playerid,"sforaie..."); }

                }
                else
                {

                    SendEmote(playerid,"se trezeste");
                    TogglePlayerControllable(playerid,1);
                    CallLocalFunction("cmd_stopanim","is",playerid,"1");
                    sleeping[playerid] = 0;

                }
Reply
#2

in_house[playerid] is -1 and then it passes the -1 as the houseid in GetHouseMaxSleepHp. After that, it accesses element at negative index -1 (in HouseInfo).

So:
pawn Код:
new Float:hp, _houseid = in_house[playerid];
GetPlayerHealth(playerid,hp);
if(_houseid != -1 && hp < GetHouseMaxSleepHp(_houseid))
{
    hp += 1.0;
    SetPlayerHealth(playerid,hp);
    new chance = random(100);
    if(chance > 90) { SendEmote(playerid,"sforaie..."); }
}
else
{
    SendEmote(playerid,"se trezeste");
    TogglePlayerControllable(playerid,1);
    CallLocalFunction("cmd_stopanim","is",playerid,"1");
    sleeping[playerid] = 0;
}
It will only execute the code if the houseid is valid.
Reply
#3

pawn Код:
[10:20:05] [debug] Run time error 4: "Array index out of bounds"
[10:20:05] [debug]  Accessing element at negative index -6658
[10:20:05] [debug] AMX backtrace:
[10:20:05] [debug] #0 000d01f8 in public GetCharacterName (playerid=-6658, formatme[]=@0x00e33224 "") at C:\AMD\rp.pwn:20634
[10:20:05] [debug] #1 0012e558 in public cmd_demask (playerid=2, params[]=@0x00e1fb84 "1311") at C:\AMD\rp.pwn:30943
[10:20:05] [debug] #2 00008078 in public OnPlayerCommandText (playerid=2, cmdtext[]=@0x00e1fb50 "/demask 1311") at C:\Users\Filip\Desktop\SERVER\pawno\include\zcmd.inc:110
pawn Код:
public GetCharacterName(playerid,formatme[])
{
    new name[MAX_PLAYER_NAME];
    new data[2][MAX_PLAYER_NAME];
    explode(data,CharacterInfo[playerid][active_character[playerid]][cName],"_");
    format(name,sizeof(name),"%s %s",data[0],data[1]);
    format(formatme,MAX_PLAYER_NAME,"%s",name);
}
pawn Код:
COMMAND:demask(playerid,params[])
{

    if(AccountInfo[playerid][aAdmin] >= ADMIN_LVL_TRAIN)
    {

        new idx = 0;
        new tmp[32];
        tmp = strtok(params,idx);
        if(!strlen(tmp)) { SendClientMessage(playerid,COLOR_LIGHTRED,"FOLOSESTE: /demask [mask id]"); return 1; }
        new other = (strval(tmp) - mask_salt);
        if(other < 0 || other > MAX_PLAYERS || !IsPlayerConnectedEx(other)) { SendClientMessage(playerid,COLOR_LIGHTRED,"Invalid mask id"); }
        new name[MAX_PLAYER_NAME];
        GetCharacterName(other,name);
        SendStrMsg(playerid,COLOR_YELLOW,"Masca (ID) folosita de %s",name);
        return 1;

    }
    else
    {

        SendClientMessage(playerid,COLOR_LIGHTRED,"Nu esti un admin.");
        return 1;

    }

}

now i got this..
Reply
#4

pawn Код:
GetCharacterName (playerid=-6658, ..
The playerid was passed was negative -6658.
pawn Код:
GetCharacterName(other,name);
so the other is negative. I assume the message about "Invalid mask id" was appeared but you never returned an error or so.

pawn Код:
COMMAND:demask(playerid,params[])
{
    if(AccountInfo[playerid][aAdmin] >= ADMIN_LVL_TRAIN)
    {
        new idx = 0;, tmp[32];
        tmp = strtok(params,idx);
        if(!strlen(tmp)) return SendClientMessage(playerid,COLOR_LIGHTRED,"FOLOSESTE: /demask [mask id]");
        new other = (strval(tmp) - mask_salt);
        if(other < 0 || other > MAX_PLAYERS || !IsPlayerConnectedEx(other)) return SendClientMessage(playerid,COLOR_LIGHTRED,"Invalid mask id");
        new name[MAX_PLAYER_NAME];
        GetCharacterName(other,name);
        SendStrMsg(playerid,COLOR_YELLOW,"Masca (ID) folosita de %s",name);
    }
    else SendClientMessage(playerid,COLOR_LIGHTRED,"Nu esti un admin.");
    return 1;
   
}
I'd strongly recommend you to use sscanf instead of that silly strtok.
Reply
#5

More , and more ..

pawn Код:
[14:21:29] [debug] Run time error 4: "Array index out of bounds"
[14:21:29] [debug]  Accessing element at negative index -1
[14:21:29] [debug] AMX backtrace:
[14:21:29] [debug] #0 0014b4d8 in public cmd_hotwire (playerid=34, params[]=@0x00e1fb74 "") at C:\AMD\rp.pwn:34594
[14:21:29] [debug] #1 00007f18 in public OnPlayerCommandText (playerid=34, cmdtext[]=@0x00e1fb50 "/hotwire") at C:\Users\Filip\Desktop\SERVER\pawno\include\zcmd.inc:104
pawn Код:
COMMAND:hotwire(playerid,params[])
{

    if(HasCooldown(playerid,COOLDOWN_HOTWIRE))
    {
        SendMsg(playerid,COLOR_LIGHTRED,"Te rog asteapta %d secunde pana sa refolosesti aceasta comanda.",GetCooldownLevel(playerid,COOLDOWN_HOTWIRE));
        return 1;
    }
    if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {

        new param[7];
        new veh = GetPlayerVehicleID(playerid);
        GetVehicleParamsEx(veh,param[0],param[1],param[2],param[3],param[4],param[5],param[6]);
        if(!param[0])
        {

            new slot = GetVehicleSlot(veh);
            new success_chance = 50;
            new chance = random(100);
            if(VehicleInfo[slot][vImmob] == 1) { success_chance = 60; }
            if(VehicleInfo[slot][vImmob] == 2) { success_chance = 70; }
            if(VehicleInfo[slot][vImmob] == 3) { success_chance = 80; }
            if(VehicleInfo[slot][vImmob] == 4) { success_chance = 90; }
            if(slot > -1)
            {

                if(chance >= success_chance)
                {

                    if(VehicleInfo[slot][vFuel] > 0)
                    {

                        StartEngine(veh);
                        SendEmote(playerid,"a reusit sa porneasca motorul.");
                        return 1;

                    }
                    else
                    {

                        SendClientMessage(playerid,COLOR_GREY,"Acest vehicul nu are benzina. Nu ai reusit sa pornesti motorul.");
                        return 1;

                    }

                }
                else
                {

                    SendEmote(playerid,"nu a reusit sa porneasca motorul.");
                    SetCooldown(playerid,COOLDOWN_HOTWIRE,10);
                    return 1;

                }

            }
            else
            {

                return 1;

            }

        }
        else
        {

            SendClientMessage(playerid,COLOR_GREY,"Motorul este deja pornit.");
            return 1;

        }

    }
    else
    {

        SendClientMessage(playerid,COLOR_GREY,"Nu esti intr-un vehicul.");
        return 1;

    }

}
Reply
#6

It's full of runtime errors.

Assuming line 34594 is
pawn Код:
if(VehicleInfo[slot][vImmob] == 1) { success_chance = 60; }
and slot is -1. You check if slot is equal or greater than 0 but you forgot to check for those too:
pawn Код:
if(VehicleInfo[slot][vImmob] == 1) { success_chance = 60; }
            if(VehicleInfo[slot][vImmob] == 2) { success_chance = 70; }
            if(VehicleInfo[slot][vImmob] == 3) { success_chance = 80; }
            if(VehicleInfo[slot][vImmob] == 4) { success_chance = 90; }
pawn Код:
COMMAND:hotwire(playerid,params[])
{
    if(HasCooldown(playerid,COOLDOWN_HOTWIRE)) return SendMsg(playerid,COLOR_LIGHTRED,"Te rog asteapta %d secunde pana sa refolosesti aceasta comanda.",GetCooldownLevel(playerid,COOLDOWN_HOTWIRE));
    if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new param[7], veh = GetPlayerVehicleID(playerid);
        GetVehicleParamsEx(veh,param[0],param[1],param[2],param[3],param[4],param[5],param[6]);
        if(!param[0])
        {
            new slot = GetVehicleSlot(veh), success_chance = 50, chance = random(100);
            if(slot < 0) return 1;
            if(VehicleInfo[slot][vImmob] == 1) success_chance = 60;
            else if(VehicleInfo[slot][vImmob] == 2) success_chance = 70;
            else if(VehicleInfo[slot][vImmob] == 3) success_chance = 80;
            else if(VehicleInfo[slot][vImmob] == 4) success_chance = 90;
           
            if(chance >= success_chance)
            {
                if(VehicleInfo[slot][vFuel] > 0)
                {
                    StartEngine(veh);
                    SendEmote(playerid,"a reusit sa porneasca motorul.");
                    return 1;
                   
                }
                else return SendClientMessage(playerid,COLOR_GREY,"Acest vehicul nu are benzina. Nu ai reusit sa pornesti motorul.");
            }
            else
            {
                SendEmote(playerid,"nu a reusit sa porneasca motorul.");
                SetCooldown(playerid,COOLDOWN_HOTWIRE,10);
                return 1;
            }
        }
        else return SendClientMessage(playerid,COLOR_GREY,"Motorul este deja pornit.");
    }
    else SendClientMessage(playerid,COLOR_GREY,"Nu esti intr-un vehicul.");
    return 1;
}
Reply
#7

pawn Код:
C:\AMD\rp.pwn(30969) : error 029: invalid expression, assumed zero
C:\AMD\rp.pwn(30969) : error 017: undefined symbol "tmp"
C:\AMD\rp.pwn(30969) : warning 215: expression has no effect
C:\AMD\rp.pwn(30969) : error 001: expected token: ";", but found "]"
C:\AMD\rp.pwn(30969) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
from demask , because of -> new idx = 0; , tmp[32]; ...


new debugs =)) wtf f****ng GM

pawn Код:
[14:29:17] [debug] Run time error 4: "Array index out of bounds"
[14:29:17] [debug]  Accessing element at negative index -1
[14:29:17] [debug] AMX backtrace:
[14:29:17] [debug] #0 0010bd70 in SetVehicleDamage (vehicleid=544) at C:\AMD\rp.pwn:26526
[14:29:17] [debug] #1 00143b60 in public cmd_vehicle (playerid=15, params[]=@0x00e1fb70 "park") at C:\AMD\rp.pwn:33501
[14:29:17] [debug] #2 0013b5e8 in public cmd_v (playerid=15, params[]=@0x00e1fb70 "park") at C:\AMD\rp.pwn:32489
[14:29:17] [debug] #3 00008078 in public OnPlayerCommandText (playerid=15, cmdtext[]=@0x00e1fb50 "/v park") at C:\Users\Filip\Desktop\SERVER\pawno\include\zcmd.inc:110
pawn Код:
stock SetVehicleDamage(vehicleid)
{

    new slot = GetVehicleSlot(vehicleid);
    UpdateVehicleDamageStatus(vehicleid,VehicleInfo[slot][vDamage][0],VehicleInfo[slot][vDamage][1],VehicleInfo[slot][vDamage][2],VehicleInfo[slot][vDamage][3]);
    if(VehicleInfo[slot][vHealth] > 310) { SetVehicleHealth(vehicleid,VehicleInfo[slot][vHealth]); } else { SetVehicleHealth(vehicleid,310); }

}

stock ResetVehicleDamage(vehicleid)
{

    new slot = GetVehicleSlot(vehicleid);
    if(slot > -1)
    {

        VehicleInfo[slot][vDamage][0] = 0;
        VehicleInfo[slot][vDamage][1] = 0;
        VehicleInfo[slot][vDamage][2] = 0;
        VehicleInfo[slot][vDamage][3] = 0;
        VehicleInfo[slot][vHealth] = 1000.0;

    }

}
Reply
#8

A typing mistake:
pawn Код:
new idx = 0, tmp[32];
You should consider of changing gamemode!

pawn Код:
stock SetVehicleDamage(vehicleid)
{
    new slot = GetVehicleSlot(vehicleid);
    if(slot > -1)
    {
        UpdateVehicleDamageStatus(vehicleid,VehicleInfo[slot][vDamage][0],VehicleInfo[slot][vDamage][1],VehicleInfo[slot][vDamage][2],VehicleInfo[slot][vDamage][3]);
        if(VehicleInfo[slot][vHealth] > 310) SetVehicleHealth(vehicleid,VehicleInfo[slot][vHealth]);
        else SetVehicleHealth(vehicleid,310);
    }
}
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
A typing mistake:
pawn Код:
new idx = 0, tmp[32];
You should consider of changing gamemode!

pawn Код:
stock SetVehicleDamage(vehicleid)
{
    new slot = GetVehicleSlot(vehicleid);
    if(slot > -1)
    {
        UpdateVehicleDamageStatus(vehicleid,VehicleInfo[slot][vDamage][0],VehicleInfo[slot][vDamage][1],VehicleInfo[slot][vDamage][2],VehicleInfo[slot][vDamage][3]);
        if(VehicleInfo[slot][vHealth] > 310) SetVehicleHealth(vehicleid,VehicleInfo[slot][vHealth]);
        else SetVehicleHealth(vehicleid,310);
    }
}
why ?


pawn Код:
C:\AMD\rp.pwn(34568) : warning 209: function "SendMsg" should return a value
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase

Header size:          21824 bytes
Code size:          1950604 bytes
Data size:         14809936 bytes
Stack/heap size:      80000 bytes; estimated max. usage: unknown, due to recursion
Total requirements:16862364 bytes

1 Warning.
on hotwire
pawn Код:
COMMAND:hotwire(playerid,params[])
{
//here    if(HasCooldown(playerid,COOLDOWN_HOTWIRE)) return SendMsg(playerid,COLOR_LIGHTRED,"Te rog asteapta %d secunde pana sa refolosesti aceasta comanda.",GetCooldownLevel(playerid,COOLDOWN_HOTWIRE));
    if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new param[7], veh = GetPlayerVehicleID(playerid);
        GetVehicleParamsEx(veh,param[0],param[1],param[2],param[3],param[4],param[5],param[6]);
        if(!param[0])
        {
            new slot = GetVehicleSlot(veh), success_chance = 50, chance = random(100);
            if(slot < 0) return 1;
            if(VehicleInfo[slot][vImmob] == 1) success_chance = 60;
            else if(VehicleInfo[slot][vImmob] == 2) success_chance = 70;
            else if(VehicleInfo[slot][vImmob] == 3) success_chance = 80;
            else if(VehicleInfo[slot][vImmob] == 4) success_chance = 90;

            if(chance >= success_chance)
            {
                if(VehicleInfo[slot][vFuel] > 0)
                {
                    StartEngine(veh);
                    SendEmote(playerid,"a reusit sa porneasca motorul.");
                    return 1;

                }
                else return SendClientMessage(playerid,COLOR_GREY,"Acest vehicul nu are benzina. Nu ai reusit sa pornesti motorul.");
            }
            else
            {
                SendEmote(playerid,"nu a reusit sa porneasca motorul.");
                SetCooldown(playerid,COOLDOWN_HOTWIRE,10);
                return 1;
            }
        }
        else return SendClientMessage(playerid,COLOR_GREY,"Motorul este deja pornit.");
    }
    else SendClientMessage(playerid,COLOR_GREY,"Nu esti intr-un vehicul.");
    return 1;
}
Reply
#10

I believe it's self-explanatory. That gamemode is full of runtime errors (Index out of bounds) and they can cause server crashes in the future.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)