What is the problem?
#1

PHP код:
if(Team[playerid] == Zombies && User[playerid][USER_MINIJUE]==&& User[playerid][USER_Evento] == && User[playerid][USER_TipoD]==&& 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"60004);
    new 
FloatHealth;
    
GetPlayerHealth(victimidHealth);
    switch(
User[playerid][USER_Mutacion]) {
    case 
0,2: {
    if(
Health <= 10 && User[victimid][USER_Muerto]== )SendDeathMessage(playerid,victimid,WEAPON_DROWN),User[playerid][USER_KILLS]++,User[victimid][USER_Muerto]=1;
    
code.
    .
    .
    . }
    case 
1: {
    if(
Health <= 20 && User[victimid][USER_Muerto]== )SendDeathMessage(playerid,victimid,WEAPON_DROWN),User[playerid][USER_KILLS]++,User[victimid][USER_Muerto]=1;
    
code .
    .
    .
    . }
    }
    
SetPlayerScore(playerid,User[playerid][USER_SCORE]);
    }
    }
    return 
1;
    } 
PHP код:
[debugRun time error 4"Array index out of bounds"
[debugAMX backtrace:
[
debug#0 0009625c in public OnPlayerKeyStateChange (0, 136, 8) from EZ.amx
[debugRun time error 4"Array index out of bounds"
[debugAMX backtrace:
[
debug#0 0009625c in public OnPlayerKeyStateChange (0, 136, 8) from EZ.amx
[debugRun time error 4"Array index out of bounds"
[debugAMX backtrace
Reply
#2

This might help you https://sampforum.blast.hk/showthread.php?tid=321919
Reply
#3

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 Код:
if(victimid >= sizeof(Users) || victimid < 0) return 1;
Adding this to the after the new victimid = GetClosestPlayer(playerid,2.0) part of this code might help. I am also assuming this code is under OnPlayerKeyStateChange so playerid is not out of bound.

Making the final code look something like this:
pawn Код:
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;
    }
Reply
#4

Quote:
Originally Posted by HoNEYKISS
Посмотреть сообщение
I had already seen that post but I still do not see the problem
Reply
#5

Quote:
Originally Posted by Cell_
Посмотреть сообщение
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 Код:
if(victimid >= sizeof(Users) || victimid < 0) return 1;
Adding this to the after the new victimid = GetClosestPlayer(playerid,2.0) part of this code might help. I am also assuming this code is under OnPlayerKeyStateChange so playerid is not out of bound.

Making the final code look something like this:
pawn Код:
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;
    }
PHP код:
stock Float:GetDistanceBetweenPoints(Float:rx1,Float:ry1,Float:rz1,Float:rx2,Float:ry2,Float:rz2)
{
    return 
floatadd(floatadd(floatsqroot(floatpower(floatsub(rx1rx2), 2)), floatsqroot(floatpower(floatsub(ry1ry2), 2))), floatsqroot(floatpower(floatsub(rz1rz2), 2)));
}
stock GetClosestPlayer(playeridFloat:limit)
{
    new 
Float:x1Float:y1Float:z1Float:x2Float:y2Float:z2Float:Distid INVALID_PLAYER_ID;
    
GetPlayerPos(playerid,x1,y1,z1);
    for(new 
0MAX_PLAYERSi++)
    {
        if(!
IsPlayerConnected(i)) continue;
        if(
== playerid) continue;
        
GetPlayerPos(ix2y2z2);
        
Dist GetDistanceBetweenPoints(x1y1z1x2y2z2);
        if(
Dist limit || id == INVALID_PLAYER_ID)
        {
            
limit Dist;
            
id i;
        }
    }
    return 
id;

It's the function
Reply
#6

Quote:
Originally Posted by Daynox12
Посмотреть сообщение
PHP код:
stock Float:GetDistanceBetweenPoints(Float:rx1,Float:ry1,Float:rz1,Float:rx2,Float:ry2,Float:rz2)
{
    return 
floatadd(floatadd(floatsqroot(floatpower(floatsub(rx1rx2), 2)), floatsqroot(floatpower(floatsub(ry1ry2), 2))), floatsqroot(floatpower(floatsub(rz1rz2), 2)));
}
stock GetClosestPlayer(playeridFloat:limit)
{
    new 
Float:x1Float:y1Float:z1Float:x2Float:y2Float:z2Float:Distid INVALID_PLAYER_ID;
    
GetPlayerPos(playerid,x1,y1,z1);
    for(new 
0MAX_PLAYERSi++)
    {
        if(!
IsPlayerConnected(i)) continue;
        if(
== playerid) continue;
        
GetPlayerPos(ix2y2z2);
        
Dist GetDistanceBetweenPoints(x1y1z1x2y2z2);
        if(
Dist limit || id == INVALID_PLAYER_ID)
        {
            
limit Dist;
            
id i;
        }
    }
    return 
id;

It's the function
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 Код:
if(victimid == INVALID_PLAYER_ID)  return 1;
Should fix that.
Reply
#7

Quote:
Originally Posted by Cell_
Посмотреть сообщение
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 Код:
if(victimid == INVALID_PLAYER_ID)  return 1;
Should fix that.
Thanks, I'll try it and let you know what happened
Reply
#8

The error is at a.

I realized that these are not the functions I use.
These are :
PHP код:
stock GetClosestPlayer(playeridFloat:dis)
{
    new 
xFloat:dis2player;
    
player = -1;
    for (
0MAX_PLAYERSx++)
    {
        if(
IsPlayerConnected(x) && GetPlayerState(x) != PLAYER_STATE_SPECTATING)
        {
            if(
!= 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));

Reply
#9

pawn Код:
if(victimid == INVALID_PLAYER_ID || victimid < 0)  return 1;
This should cover both.
Reply
#10

Your indentation is also bad. Try to fix it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)