Game crashing - 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: Game crashing (
/showthread.php?tid=636720)
Game crashing -
aoky - 03.07.2017
This seems to be the reason as to why we are crashing when we die script wise.
PHP код:
[debug] Run time error 4: "Array index out of bounds"
[03:21:53] [debug] Attempted to read/write array element at index 65535 in array of size 1000
[03:21:53] [debug] AMX backtrace:
[03:21:53] [debug] #0 00061370 in public WC_OnPlayerWeaponShot (0, 24, 0, 65535, 1157821223, -991127359, 1095100765) from SCRP-R39.amx
[03:21:53] [debug] #1 0003d8d0 in public OnPlayerWeaponShot (0, 24, 0, 65535, 1157821223, -991127359, 1095100765) from SCRP-R39.amx
[03:22:09] [part] Kamal_Rivers has left the server (1:0)
[03:22:12] [part] LingLing_Tofu has left the server (0:0)
Any ideas why?
Re: Game crashing -
jlalt - 03.07.2017
You are doing something with hitid without checking if its valid.
So before using hitid directly do some checks for it:
PHP код:
if(hitid != INVALID_PLAYER_ID && IsPlayerConnected(hitid))
{
}
Re: Game crashing -
aoky - 03.07.2017
I did that but I'm getting the same issue. I'm using a timer for some stuff.
PHP код:
if (PlayerHealth <= 25 && Character[hitid][BrutalM] == 0 && hitid != INVALID_PLAYER_ID && IsPlayerConnected(hitid))
{
if(Character[hitid][BrutalM] == 0 && weaponid > 15)
{
GetPlayerPos(hitid, BMPos[hitid][0], BMPos[hitid][1], BMPos[hitid][2]);
Character[hitid][BrutalM] = 1;
Character[hitid][CanAccept] = 0;
LegHit[hitid] = 0;
ApplyAnim(hitid);
format(DTextS, sizeof(DTextS), "(( %s is currently injured, type /damages %i for more info. ))", GetName(hitid), hitid);
label[hitid] = Create3DTextLabel(DTextS, COLOR_RED, BMPos[hitid][0], BMPos[hitid][1], BMPos[hitid][2], 10.0, 0);
Attach3DTextLabelToPlayer(label[hitid], hitid, 0, 0, 0.7);
ClearPlayerWeapons(hitid);
SetTimerEx("AllowDamage", 3000, false, "i", hitid);
format(str, sizeof(str),"%s was brutally wounded by %s.",GetRoleplayName(hitid),GetRoleplayName(playerid));
SendAdminsMessage(1, COLOR_RED, str);
PHP код:
forward AllowDamage(playerid);
public AllowDamage(playerid)
{
AllowDamageMode[playerid] = 1;
return 1;
}
It happens when the player is in AllowDamageMode and takes damage. Here is OnPlayerDamage
PHP код:
public OnPlayerDamage(&playerid, &Float:amount, &issuerid, &weapon, &bodypart)
{
new Float:PlayerHealth;
new str[256];
if(issuerid != INVALID_PLAYER_ID)
{
if(Character[playerid][BrutalM] == 0 && Character[playerid][Dead] == 0 && issuerid != INVALID_PLAYER_ID)
{
GetPlayerHealth(playerid, PlayerHealth);
if(amount > PlayerHealth) {
SetPlayerHealth(playerid, 20);
return 0;
}
}
if(Character[playerid][BrutalM] == 1 && issuerid != INVALID_PLAYER_ID)
{
GetPlayerHealth(playerid, PlayerHealth);
if(amount > PlayerHealth) {
SetPlayerHealth(playerid, 999);
return 1;
}
}
if(Character[playerid][BrutalM] == 1 && AllowDamageMode[playerid] == 1)
{
Delete3DTextLabel(label[playerid]);
label2[playerid] = Create3DTextLabel("(( THIS PLAYER IS DEAD ))", COLOR_RED, Character[playerid][DPosX], Character[playerid][DPosY], Character[playerid][DPosZ], 10.0, 0);
Attach3DTextLabelToPlayer(label2[playerid], playerid, 0, 0, 0.7);
Character[playerid][Dead] = 1;
Character[playerid][BrutalM] = 0;
AllowDamageMode[playerid] = 0;
ApplyAnim(playerid);
SCM(playerid, COLOR_YELLOW, ">> You are now dead. You can use /respawnme after 60 seconds to respawn.");
Character[playerid][CanSpawn] = 0;
RespawnT = 60;
RespawnEx = SetTimer("RespawnTimer", 999, true);
SetTimerEx("RespawnTimer2", 60000, false, "i", playerid);
format(str, sizeof(str),"%s was finished off by %s.",GetRoleplayName(playerid),GetRoleplayName(issuerid));
SendAdminsMessage(1, COLOR_LIGHTRED, str);
}
Re: Game crashing -
jlalt - 03.07.2017
Puts the checks first:
PHP код:
if (PlayerHealth <= 25 && hitid != INVALID_PLAYER_ID && IsPlayerConnected(hitid) && Character[hitid][BrutalM] == 0)