array index out of bounds
#1

Hello. I need another help :P.
Heres my code.
PHP код:
new lootCount;
enum hospinfo
{
    
HospitalID,
    
Float:xHos,
    
Float:yHos,
    
Float:zHos,
    
HosSlot1 1,
    
HosSlot2 1,
    
HosSlot3 1,
    
HosSlot4 1,
    
HosSlot5 1,
    
HosSlot6 1
}
new 
Medikament[MAX_LOOTING][hospinfo]; 
PHP код:
    if(newkeys == 1024)
    {
        if(
IsPlayerInRangeOfPoint(playerid,3.5,Medikament[GetMedikID(playerid)][xHos],Medikament[GetMedikID(playerid)][yHos],Medikament[GetMedikID(playerid)][zHos]))
        {
            
HospitalBoxDispl(playerid);
        }
    } 
ERROR:
PHP код:
D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(8330) : error 032: array index out of bounds (variable "Medikament")
D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(26392) : error 032: array index out of bounds (variable "Medikament")
D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(26446) : error 032: array index out of bounds (variable "Medikament")
D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(26447) : error 032: array index out of bounds (variable "Medikament"
Thanks for help
Reply
#2

How does your GetMedikID(playerid) look like?
Reply
#3

Here is it
PHP код:
stock GetMedikID(playerid)
{
    for(new 
i=0i<MAX_LOOTINGi++)
     {
          if(
IsPlayerInRangeOfPoint(playerid,3.5Medikament[i][xHos],Medikament[i][yHos],Medikament[i][zHos]))
        {
             return 
i;
           }
    }
     return 
0;

Reply
#4

Replace:

Код:
stock GetMedikID(playerid)
{
    for(new i = 0; i < sizeof(Medikament); i++)
     {
        if(IsPlayerInRangeOfPoint(playerid,3.5, Medikament[i][xHos],Medikament[i][yHos],Medikament[i][zHos]))
        {
             return i;
        }
    }
    return 0;
}  

if(newkeys == 1024) 
{ 
	if(HospitalBoxDispl(playerid) != 0) return HospitalBoxDispl(playerid); 
}
Reply
#5

I have error again.
PHP код:
stock GetMedikID(playerid)
{
    for(new 
0sizeof(Medikament); i++)
       {
        if(
IsPlayerInRangeOfPoint(playerid,3.5Medikament[i][xHos],Medikament[i][yHos],Medikament[i][zHos])) // ERROR 1
        
{
             return 
i;
        }
    }
    return 
0;

PHP код:
forward HospitalCreate(Float:pXX,Float:pYX,Float:pZX);
public 
HospitalCreate(Float:pXX,Float:pYX,Float:pZX)
{
    new 
hospstrng[128];
    
lootCount += 1;
    
Medikament[lootCount][HosSlot1] = 1;
    
Medikament[lootCount][HosSlot2] = 1;
    
Medikament[lootCount][HosSlot3] = 1;
    
Medikament[lootCount][HosSlot4] = 1;
    
Medikament[lootCount][HosSlot5] = 1;
    
Medikament[lootCount][HosSlot6] = 1;
    
Medikament[lootCount][xHos] = pXX;
    
Medikament[lootCount][yHos] = pYX;//ERROR 2
    
Medikament[lootCount][zHos] = pZX;// ERROR 3
       
Medikament[lootCount][HospitalID] = CreateDynamicObject(1685,pXX+0.3,pYX+float(1),pZX-0.7,0.0,0.0,0.0,-1,-1,-1,1000.0);
    
format(hospstrng,sizeof(hospstrng),"{05FB0C}MEDBOX\n{8C8F90}Daachiret Marcxena ALT-s Rom Naxo Medikamentebis Yutis Inventari");
    
CreateDynamic3DTextLabel(hospstrng,-1,pXX+0.3,pYX+float(1),pZX-0.7,8.0,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,1,-1,-1,-18.0);
    return 
1;

ERRORS
PHP код:
D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(26389) : error 032: array index out of bounds (variable "Medikament")
D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(26443) : error 032: array index out of bounds (variable "Medikament")
D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(26444) : error 032: array index out of bounds (variable "Medikament")
Pawn compiler 3.2.3664              Copyright (c1997-2006ITB CompuPhase 
Reply
#6

Right I forgot this already about enums lel.

https://sampforum.blast.hk/showthread.php?tid=318307

I'm not sure if it's going to solve your problem but basically setting this:
Код:
    HosSlot1 = 1, 
    HosSlot2 = 1, 
    HosSlot3 = 1, 
    HosSlot4 = 1, 
    HosSlot5 = 1, 
    HosSlot6 = 1
Means that you are assigning them all to the first position (well second). Like I said, this might not actually solve the array out of bound but it's just generally a bad idea to assign values to enum variables because you're not actually assigning values. Enum's are constants and act as "holders" for numbers.
Reply
#7

Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
Right I forgot this already about enums lel.

https://sampforum.blast.hk/showthread.php?tid=318307

I'm not sure if it's going to solve your problem but basically setting this:
Код:
    HosSlot1 = 1, 
    HosSlot2 = 1, 
    HosSlot3 = 1, 
    HosSlot4 = 1, 
    HosSlot5 = 1, 
    HosSlot6 = 1
Means that you are assigning them all to the first position (well second). Like I said, this might not actually solve the array out of bound but it's just generally a bad idea to assign values to enum variables because you're not actually assigning values. Enum's are constants and act as "holders" for numbers.
Fixed Thanks for help . +REP
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)