'OnPlayerDeath' - Array Index Out of Bounds

Započeo Plen Ki Mun, Mart 14, 2018, 19:03:55 POSLE PODNE

prethodna tema - sledeća tema

0 članova i 3 gostiju pregledaju ovu temu.

Problem(error/warning): Ma nešto zeza OnPlayerDeath callback baca nesto array index out of bounds
Dio skripte:


public OnPlayerDeath(playerid, killerid, reason)
{
Killstreak(playerid, killerid);

new string[128];
if(IsPlayerConnected(killerid) && killerid != INVALID_PLAYER_ID)
{
PlayerInfo[killerid][Kills]++;
    PlayerInfo[playerid][Deaths]++;
    if(OnHit[playerid] != 0)
{
GivePlayerMoneyEx(killerid, OnHit[playerid]);

new result[128];
format(result, sizeof(result), "{FFFF00}[HITMAN]: {FFFFFF}Ubio si %s i zaradio na njegovoj glavi $%d!", GetName(playerid), OnHit[playerid]);
SCM(playerid, -1, result);
format(result, sizeof(result), "{FFFF00}[HITMAN]: {FFFFFF}%s je ubio %d i zaradio $%d!", GetName(killerid), GetName(playerid), OnHit[playerid]);
SCMToAll(-1, result);
OnHit[playerid] = 0;
}
if(PlayerInfo[killerid][Vip] >= 1)
{
format(string, 150, "[KILL]: {FFFFFF}Ubio si %s.", GetName(playerid));
SCM(killerid, -1, string);
GivePlayerMoneyEx(killerid, 1000);
} SetPlayerScore(killerid, GetPlayerScore(killerid)+1);
}
else
{
format(string, 150, "[KILL]: {FFFFFF}ubio si %s.", GetName(playerid));
SCM(killerid, -1, string);
GivePlayerMoneyEx(killerid, 1000);
SetPlayerScore(killerid, GetPlayerScore(killerid)+1);
}
AntiFakekill[playerid]++;
SetTimerEx("AntiFakekillTimer", 1000,false,"i",playerid);
SendDeathMessage(killerid,playerid,reason);
SCM(playerid, TOMATO, "[DEATH]: {FFFFFF}Ubijen si nakazo, spremi kofer i pakuj prnje..");
format(string, 150, "~w~Ubijen si od ~r~%s", GetName(killerid));
GameTextForPlayer(playerid, string,2500,3);
return 1;
}



Debug iz server_log(ukoliko je u pitanju crashanje servera - crashdetect log):

[18:47:35] [debug] Run time error 4: "Array index out of bounds"
[18:47:35] [debug] AMX backtrace:
[18:47:35] [debug] #0 0009ae98 in ?? (0, 65535) from CNR.amx
[18:47:35] [debug] #1 00058d90 in public OnPlayerDeath (0, 65535, 255) from CNR.amx


Slika/video ingame problema(obavezno ako je ingame problem): //

INVALID_PLAYER_ID je definisano kao 65535.

Napraviš uslov pod OnPlayerDeath.

if(killerid != INVALID_PLAYER_ID) {
      funkcija;
}


Probaj sada, pozivao si funkciju Killstreak(playerid,killerid); prije provjere.

public OnPlayerDeath(playerid, killerid, reason)
{

new string[128];
if(IsPlayerConnected(killerid) && killerid != INVALID_PLAYER_ID)
{
            Killstreak(playerid, killerid);
    PlayerInfo[killerid][Kills]++;
    PlayerInfo[playerid][Deaths]++;
    if(OnHit[playerid] != 0)
{
GivePlayerMoneyEx(killerid, OnHit[playerid]);

new result[128];
format(result, sizeof(result), "{FFFF00}[HITMAN]: {FFFFFF}Ubio si %s i zaradio na njegovoj glavi $%d!", GetName(playerid), OnHit[playerid]);
SCM(playerid, -1, result);
format(result, sizeof(result), "{FFFF00}[HITMAN]: {FFFFFF}%s je ubio %d i zaradio $%d!", GetName(killerid), GetName(playerid), OnHit[playerid]);
SCMToAll(-1, result);
OnHit[playerid] = 0;
}
if(PlayerInfo[killerid][Vip] >= 1)
{
format(string, 150, "[KILL]: {FFFFFF}Ubio si %s.", GetName(playerid));
SCM(killerid, -1, string);
GivePlayerMoneyEx(killerid, 1000);
} SetPlayerScore(killerid, GetPlayerScore(killerid)+1);
}
else
{
format(string, 150, "[KILL]: {FFFFFF}ubio si %s.", GetName(playerid));
SCM(killerid, -1, string);
GivePlayerMoneyEx(killerid, 1000);
SetPlayerScore(killerid, GetPlayerScore(killerid)+1);
}
AntiFakekill[playerid]++;
SetTimerEx("AntiFakekillTimer", 1000,false,"i",playerid);
SendDeathMessage(killerid,playerid,reason);
SCM(playerid, TOMATO, "[DEATH]: {FFFFFF}Ubijen si nakazo, spremi kofer i pakuj prnje..");
format(string, 150, "~w~Ubijen si od ~r~%s", GetName(killerid));
GameTextForPlayer(playerid, string,2500,3);
return 1;
}



bilo je lijepo dok je trajalo.



[pawn]
public OnPlayerDeath(playerid, killerid, reason)
{
   if (playerid == INVALID_PLAYER_ID || killerid == INVALID_PLAYER_ID) {
      return 1;
   }

   Killstreak(playerid, killerid);
   
   new string[128];
   if(IsPlayerConnected(killerid) && killerid != INVALID_PLAYER_ID)
   {
      PlayerInfo[killerid][Kills]++;
       PlayerInfo[playerid][Deaths]++;
       if(OnHit[playerid] != 0)
      {
         GivePlayerMoneyEx(killerid, OnHit[playerid]);

         new result[128];
         format(result, sizeof(result), "{FFFF00}[HITMAN]: {FFFFFF}Ubio si %s i zaradio na njegovoj glavi $%d!", GetName(playerid), OnHit[playerid]);
         SCM(playerid, -1, result);
         format(result, sizeof(result), "{FFFF00}[HITMAN]: {FFFFFF}%s je ubio %d i zaradio $%d!", GetName(killerid), GetName(playerid), OnHit[playerid]);
         SCMToAll(-1, result);
         OnHit[playerid] = 0;
      }
      if(PlayerInfo[killerid][Vip] >= 1)
      {
         format(string, 150, "[KILL]: {FFFFFF}Ubio si %s.", GetName(playerid));
         SCM(killerid, -1, string);
         GivePlayerMoneyEx(killerid, 1000);
      }   SetPlayerScore(killerid, GetPlayerScore(killerid)+1);
   }
   else
   {
      format(string, 150, "[KILL]: {FFFFFF}ubio si %s.", GetName(playerid));
      SCM(killerid, -1, string);
      GivePlayerMoneyEx(killerid, 1000);
      SetPlayerScore(killerid, GetPlayerScore(killerid)+1);
   }
   AntiFakekill[playerid]++;
   SetTimerEx("AntiFakekillTimer", 1000,false,"i",playerid);
   SendDeathMessage(killerid,playerid,reason);
   SCM(playerid, TOMATO, "[DEATH]: {FFFFFF}Ubijen si nakazo, spremi kofer i pakuj prnje..");
   format(string, 150, "~w~Ubijen si od ~r~%s", GetName(killerid));
   GameTextForPlayer(playerid, string,2500,3);
   return 1;
}
[/pawn]

mozda ovako?

usput, da li je crasher dao vise linija loga, trebao bi prikazati broj linije gdje se poziva ta metoda
Software Developer

@Ino42O

Pokusat cu sada ovo za death, ali mi isto i ovo u log izbacuje jer sam prebacio na novi ServerSided money.

Log:

[10:22:47] [debug] #0 00092ccc in public GivePlayerCash (65535, 2500) from CNR.amx

Kod:


// Anti-Money Hack
forward GivePlayerCash(playerid, money);
public GivePlayerCash(playerid, money)
{
    CashC[playerid] += money;
    ResetMoneyBar(playerid);
    UpdateMoneyBar(playerid,CashC[playerid]);
    return CashC[playerid];
}
forward SetPlayerCash(playerid, money);
SetPlayerCash(playerid, money)
{
    CashC[playerid] = money;
    ResetMoneyBar(playerid);
    UpdateMoneyBar(playerid,CashC[playerid]);
    return CashC[playerid];
}
forward ResetPlayerCash(playerid);
ResetPlayerCash(playerid)
{
    CashC[playerid] = 0;
    ResetMoneyBar(playerid);
    UpdateMoneyBar(playerid,CashC[playerid]);
    return CashC[playerid];
}
forward GetPlayerCash(playerid);
GetPlayerCash(playerid)
{
    return CashC[playerid];
}

dodas provjere gdje pozivas te funkcije tipa:

[pawn]if (IsPlayerConnected(id)) {
   GivePlayerCash(id, money);
}[/pawn]


ili

[pawn]
forward GivePlayerCash(playerid, money);
public GivePlayerCash(playerid, money)
{
   if (!IsPlayerConnected(playerid)) {
      return 1;
   }

    CashC[playerid] += money;
    ResetMoneyBar(playerid);
    UpdateMoneyBar(playerid,CashC[playerid]);
    return CashC[playerid];
}[/pawn]
Software Developer