Forma de obtener direcciуn mбs optimizada?
#1

Buenas, hay alguna forma mбs optimizada sea cuanto cуdigo o memoria de obtener la direcciуn del negocio? veo esto un poco largo y siento que se puede hacer mejor.

Код:
stock ActualizarTextoNegocio(id)
{
	new
	    string[280];

	static
	    count_direction[sizeof ZoneNames],
		Neg_ID_Direccion[MAX_NEGOCIOS];

	new
		name_zone[28],
		str_direction[28+8],
		id_zone;

	id_zone = GetZoneNameAtCoord(NegocioInfo[id][nPosX], NegocioInfo[id][nPosY], name_zone);

    for(new i = 0; i < sizeof(ZoneNames); i++)
    {
	    if(id_zone == i) continue;

	    new
			str[28];
	    strunpack(str, ZoneNames[id][zoneName]);
	    if(!strcmp(str, name_zone))
	    {
	    	id_zone = i;
	    	break;
		}
	}
	
    count_direction[id_zone] ++;
    Neg_ID_Direccion[id] = count_direction[id_zone];


	format(str_direction, sizeof(str_direction), "%s %d", name_zone, Neg_ID_Direccion[id]);

	if(NegocioInfo[id][nEstado] == 0)
	{
		format(string, sizeof(string), "Negocio en Venta\n"#CBLANCO"Nъmero: "#CGRIS"LS-%d"#CBLANCO"\nPrecio: "#CVERDE"%d$\n"#CBLANCO"Direcciуn: "#CAMARILLO"%s"#CBLANCO"\n\nPara ingresar al establecimiento usa "#CAMARILLO"/ingresar", NegocioInfo[id][nSQLID], NegocioInfo[id][nPrecio], str_direction);
	}
	else if(NegocioInfo[id][nEstado] == 1)
	{
		format(string, sizeof(string), "%s\n"#CBLANCO"Nъmero: "#CGRIS"LS-%d"#CBLANCO"\n"#CBLANCO"Dueсo: "#CGRIS"%s\n"#CBLANCO"Entrada: "#CVERDE"$%d\n"#CBLANCO"Direcciуn: "#CAMARILLO"%s"#CBLANCO"\n\nPara ingresar al establecimiento usa "#CAMARILLO"/ingresar", NegocioInfo[id][nNombre], NegocioInfo[id][nSQLID], NegocioInfo[id][nPropietario], NegocioInfo[id][nPrecioEntrada], str_direction);
	}
	UpdateDynamic3DTextLabelText(NegocioInfo[id][nTexto], COLOR_AZUL, string);
}
GetZoneNameAtCoord

Код:
stock GetZoneNameAtCoord(Float:x, Float:y, zone[], len = sizeof(zone))
{
 	for (new i = 0; i != sizeof (ZoneNames); ++i)
 	{
		if (x >= ZoneNames[i][zoneArea][0] && x <= ZoneNames[i][zoneArea][3] && y >= ZoneNames[i][zoneArea][1] && y <= ZoneNames[i][zoneArea][4])
		{
		    strunpack (zone, ZoneNames[i][zoneName], len);
			return i;
		}
	}
	return -1;
}
Reply
#2

Usa el include a_zones con esta funciуn

Quote:

stock GetZona(playerid)
{
new direccion[MAX_ZONE_NAME], Float:Pos[3];
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
Get2DZone(direccion, sizeof(direccion), Pos[0], Pos[1]);
return direccion;
}

Puedes hacer el stock dentro del callback que quieras igual usando la coordenada del negocio, solo guiate de los parбmetros del include
Reply
#3

Los cуdigos largos no siempre son los menos optimizados, un cуdigo bien optimizado no depende de si tiene mas lineas o no, depende de que tan veloz sea al momento de ejecutarse.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)