PDA

View Full Version : [HELP]Creating a Three-Dimensional Array


JR_Junior
01/03/2018, 10:22 PM
Hello, I'm trying to create the following array, but it's giving error: warning 213: tag mismatch

new Mapa_PostosLS[][][] =
{
{Float:1942.3726,Float:-1772.8423,Float:13.6406,"Terrestre"}// posto 1 ls
};


To be read in:

IsPlayerInRangeOfPoint(playerid, 10.0, Mapa_PostosLS[0][0], Mapa_PostosLS[0][1], Mapa_PostosLS[0][2])

format(DialogString, sizeof(DialogString), "Categoria: %s",Mapa_PostosLV[0][3]);


Based in: http://forum.sa-mp.com/showthread.php?t=318212


EDIT
Fixed

enum Pos_Postos {Float:PX,Float:PY,Float:PZ,PS[20]}
new Mapa_PostosLS[][Pos_Postos] =
{
{1942.3726,-1772.8423,13.6406,"Terrestre"}// posto 1 ls
};


To be read in:

IsPlayerInRangeOfPoint(playerid, 10.0, Mapa_PostosLS[0][PX], Mapa_PostosLS[0][PY], Mapa_PostosLS[0][PZ])

format(DialogString, sizeof(DialogString), "Categoria: %s",Mapa_PostosLV[0][PS]);

WORKING FINE

kingmk
01/03/2018, 10:29 PM
You can do something like this, instead using array.



#DEFINE MAX_MAPS 1

enum E_MAP
{
Float: pMapX,
Float: pMapY,
Float: pMapZ,
pMapName[35]
};
new MapInfo[MAX_MAPS][E_MAP];

hook OnGameModeInit()
{
MapInfo[0][pMapX] = 1942.3726;
MapInfo[0][pMapY] = -1772.8423;
MapInfo[0][pMapZ] = 13.6406;
sizeof(MapInfo[0][pMapName], 35, "Terrestre");
return 1;
}


Or try this.


new Mapa_PostosLS[2][4] =
{
{Float:1942.3726, Float:-1772.8423, Float:13.6406, "Terrestre"},
{Float:1942.3726, Float:-1772.8423, Float:13.6406, "Terrestre2"}
};

JR_Junior
01/03/2018, 10:41 PM
I will need it to be just in an array, as it will be too large to use in OnGameModeInit.
You can do something like this, instead using array.



#DEFINE MAX_MAPS 1

enum E_MAP
{
Float: pMapX,
Float: pMapY,
Float: pMapZ,
pMapName[35]
};
new MapInfo[MAX_MAPS][E_MAP];

hook OnGameModeInit()
{
MapInfo[0][pMapX] = 1942.3726;
MapInfo[0][pMapY] = -1772.8423;
MapInfo[0][pMapZ] = 13.6406;
sizeof(MapInfo[0][pMapName], 35, "Terrestre");
return 1;
}




Don't work:

Or try this.

new Mapa_PostosLS[2][4] =
{
{Float:1942.3726, Float:-1772.8423, Float:13.6406, "Terrestre"},
{Float:1942.3726, Float:-1772.8423, Float:13.6406, "Terrestre2"}
};

PepsiCola23
01/03/2018, 10:49 PM
this is what you`re looking for,really good explained,hope it helps you

http://forum.sa-mp.com/showthread.php?t=318212

JR_Junior
02/03/2018, 12:20 AM
this is what you`re looking for,really good explained,hope it helps you

http://forum.sa-mp.com/showthread.php?t=318212
But I'm trying this way and get error...

AroseKhanNiazi
02/03/2018, 12:53 AM
enum Mapa_enum {
Float:Mapa_PosX,
Float:Mapa_PosY,
Float:Mapa_PosZ,
Mapa_Name[30]
};

new const Mapa_PostosLS[][Mapa_enum] =
{
{Float:1942.3726,Float:-1772.8423,Float:13.6406,"Terrestre"}// posto 1 ls
};


if(IsPlayerInRangeOfPoint(playerid, 10.0, Mapa_PostosLS[0][Mapa_PosX], Mapa_PostosLS[0][Mapa_PosY], Mapa_PostosLS[0][Mapa_PosZ]))
format(DialogString, sizeof(DialogString), "Categoria: %s",Mapa_PostosLV[0][Mapa_Name]);


if you are gonna use the same code for a lot of things use this.

for(new i,j=sizeof(Mapa_PostosLS); i<j; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 10.0, Mapa_PostosLS[i][Mapa_PosX], Mapa_PostosLS[i][Mapa_PosY], Mapa_PostosLS[i][Mapa_PosZ]))
{
format(DialogString, sizeof(DialogString), "Categoria: %s",Mapa_PostosLV[i][Mapa_Name]);
//.. code here after this and before break.
break;
}
}

JR_Junior
02/03/2018, 01:46 AM
enum Mapa_enum {
Float:Mapa_PosX,
Float:Mapa_PosY,
Float:Mapa_PosZ,
Mapa_Name[30]
};

new const Mapa_PostosLS[][Mapa_enum] =
{
{Float:1942.3726,Float:-1772.8423,Float:13.6406,"Terrestre"}// posto 1 ls
};


if(IsPlayerInRangeOfPoint(playerid, 10.0, Mapa_PostosLS[0][Mapa_PosX], Mapa_PostosLS[0][Mapa_PosY], Mapa_PostosLS[0][Mapa_PosZ]))
format(DialogString, sizeof(DialogString), "Categoria: %s",Mapa_PostosLV[0][Mapa_Name]);


if you are gonna use the same code for a lot of things use this.

for(new i,j=sizeof(Mapa_PostosLS); i<j; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 10.0, Mapa_PostosLS[i][Mapa_PosX], Mapa_PostosLS[i][Mapa_PosY], Mapa_PostosLS[i][Mapa_PosZ]))
{
format(DialogString, sizeof(DialogString), "Categoria: %s",Mapa_PostosLV[i][Mapa_Name]);
//.. code here after this and before break.
break;
}
}

Yeah, fixed before you post, but thank you! hahahahah