SA-MP Forums Archive
Forma de obtener direcciуn mбs optimizada? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Español/Spanish (https://sampforum.blast.hk/forumdisplay.php?fid=29)
+---- Thread: Forma de obtener direcciуn mбs optimizada? (/showthread.php?tid=610634)



Forma de obtener direcciуn mбs optimizada? - Fagrinht - 26.06.2016

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;
}



Respuesta: Forma de obtener direcciуn mбs optimizada? - wharlos - 26.06.2016

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


Respuesta: Forma de obtener direcciуn mбs optimizada? - Shiny_David - 27.06.2016

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.