if(Team[playerid] == Zombies && User[playerid][USER_MINIJUE]==0 && User[playerid][USER_Evento] == 0 && User[playerid][USER_TipoD]==0 && newkeys & Morder)
{
if(GetPlayerWeapon(playerid) == 0)
{
new victimid = GetClosestPlayer(playerid,2.0);
if(Team[victimid] != Zombies )
{
if(IsPlayerPaused (victimid)) return GameTextForPlayer(playerid, "~G~El jugador se encuentra~N~ pausado", 6000, 4);
new Float: Health;
GetPlayerHealth(victimid, Health);
switch(User[playerid][USER_Mutacion]) {
case 0,2: {
if(Health <= 10 && User[victimid][USER_Muerto]== 0 )SendDeathMessage(playerid,victimid,WEAPON_DROWN),User[playerid][USER_KILLS]++,User[victimid][USER_Muerto]=1;
code.
.
.
. }
case 1: {
if(Health <= 20 && User[victimid][USER_Muerto]== 0 )SendDeathMessage(playerid,victimid,WEAPON_DROWN),User[playerid][USER_KILLS]++,User[victimid][USER_Muerto]=1;
code .
.
.
. }
}
SetPlayerScore(playerid,User[playerid][USER_SCORE]);
}
}
return 1;
}
[debug] Run time error 4: "Array index out of bounds"
[debug] AMX backtrace:
[debug] #0 0009625c in public OnPlayerKeyStateChange (0, 136, 8) from EZ.amx
[debug] Run time error 4: "Array index out of bounds"
[debug] AMX backtrace:
[debug] #0 0009625c in public OnPlayerKeyStateChange (0, 136, 8) from EZ.amx
[debug] Run time error 4: "Array index out of bounds"
[debug] AMX backtrace:
if(victimid >= sizeof(Users) || victimid < 0) return 1;
if(Team[playerid] == Zombies && User[playerid][USER_MINIJUE]==0 && User[playerid][USER_Evento] == 0 && User[playerid][USER_TipoD]==0 && newkeys & Morder)
{
if(GetPlayerWeapon(playerid) == 0)
{
new victimid = GetClosestPlayer(playerid,2.0);
if(victimid >= sizeof(Users) || victimid < 0) return 1; // can also replace sizeof(Users) with MAX_PLAYERS but you can only do this if your Users variable looks something like this Users[MAX_PLAYERS][someEnum]
if(Team[victimid] != Zombies )
{
if(IsPlayerPaused (victimid)) return GameTextForPlayer(playerid, "~G~El jugador se encuentra~N~ pausado", 6000, 4);
new Float: Health;
GetPlayerHealth(victimid, Health);
switch(User[playerid][USER_Mutacion]) {
case 0,2: {
if(Health <= 10 && User[victimid][USER_Muerto]== 0 )SendDeathMessage(playerid,victimid,WEAPON_DROWN),User[playerid][USER_KILLS]++,User[victimid][USER_Muerto]=1;
code.
.
.
. }
case 1: {
if(Health <= 20 && User[victimid][USER_Muerto]== 0 )SendDeathMessage(playerid,victimid,WEAPON_DROWN),User[playerid][USER_KILLS]++,User[victimid][USER_Muerto]=1;
code .
.
.
. }
}
SetPlayerScore(playerid,User[playerid][USER_SCORE]);
}
}
return 1;
}
This might help you https://sampforum.blast.hk/showthread.php?tid=321919
|
From the data you have provided, I am guessing victimid is out of bounds, i.e, < 0 or > MAX_PLAYERS, assuming the User array is sized MAX_PLAYERS. Will have to see the GetClosestPlayer function to make sure that's the case.
On the assumption that that is the case, perhaps you should have some sort of a check on victimid before implementing the rest of the code. Something like: pawn Код:
Making the final code look something like this: pawn Код:
|
stock Float:GetDistanceBetweenPoints(Float:rx1,Float:ry1,Float:rz1,Float:rx2,Float:ry2,Float:rz2)
{
return floatadd(floatadd(floatsqroot(floatpower(floatsub(rx1, rx2), 2)), floatsqroot(floatpower(floatsub(ry1, ry2), 2))), floatsqroot(floatpower(floatsub(rz1, rz2), 2)));
}
stock GetClosestPlayer(playerid, Float:limit)
{
new Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, Float:Dist, id = INVALID_PLAYER_ID;
GetPlayerPos(playerid,x1,y1,z1);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
if(i == playerid) continue;
GetPlayerPos(i, x2, y2, z2);
Dist = GetDistanceBetweenPoints(x1, y1, z1, x2, y2, z2);
if(Dist < limit || id == INVALID_PLAYER_ID)
{
limit = Dist;
id = i;
}
}
return id;
}
PHP код:
|
if(victimid == INVALID_PLAYER_ID) return 1;
As expected when the code doesn't find a player in range of your limit, it will return INVALID_PLAYER_ID, so basically add this code after the new victimid = GetClosestPlayer(playerid, 2.0);:
pawn Код:
|
stock GetClosestPlayer(playerid, Float:dis)
{
new x, Float:dis2, player;
player = -1;
for (x = 0; x < MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x) && GetPlayerState(x) != PLAYER_STATE_SPECTATING)
{
if(x != playerid)
{
dis2 = GetDistanceBetweenPlayers(x,playerid);
if(dis2 < dis && dis2 != -1.00)
{
dis = dis2;
player = x;
}
}
}
}
return player;
}
public Float:GetDistanceBetweenPlayers(p1,p2)
{
new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
if(!IsPlayerConnected(p1) || !IsPlayerConnected(p2))
{
return -1.00;
}
GetPlayerPos(p1,x1,y1,z1);
GetPlayerPos(p2,x2,y2,z2);
return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
if(victimid == INVALID_PLAYER_ID || victimid < 0) return 1;