їMe ayudan a hacer esto? -
Alexander11 - 05.09.2014
Hola, quiero optimizar un comando, y necesito que me ayuden, miren es el siguiente:
pawn Код:
CMD:llenar(playerid, params[])
{
new vehicleid = GetPlayerVehicleID(playerid);
if(InGasStation(6.0,playerid,1004.0070,-939.3102,42.1797) || InGasStation(6.0,playerid,1944.3260,-1772.9254,13.3906))
{
GiveFuel(playerid,vehicleid);
}
else if(InGasStation(6.0,playerid,-90.5515,-1169.4578,2.4079) || InGasStation(6.0,playerid,-1609.7958,-2718.2048,48.5391))
{
GiveFuel(playerid,vehicleid);
}
else if(InGasStation(6.0,playerid,-2029.4968,156.4366,28.9498) || InGasStation(8.0,playerid,-2408.7590,976.0934,45.4175))
{
GiveFuel(playerid,vehicleid);
}
else if(InGasStation(5.0,playerid,-2243.9629,-2560.6477,31.8841) || InGasStation(8.0,playerid,-1676.6323,414.0262,6.9484))
{
GiveFuel(playerid,vehicleid);
}
else if(InGasStation(6.0,playerid,2202.2349,2474.3494,10.5258) || InGasStation(10.0,playerid,614.9333,1689.7418,6.6968))
{
GiveFuel(playerid,vehicleid);
}
else if(InGasStation(8.0,playerid,-1328.8250,2677.2173,49.7665) || InGasStation(6.0,playerid,70.3882,1218.6783,18.5165))
{
GiveFuel(playerid,vehicleid);
}
else if(InGasStation(8.0,playerid,2113.7390,920.1079,10.5255) || InGasStation(6.0,playerid,-1327.7218,2678.8723,50.0625))
{
GiveFuel(playerid,vehicleid);
}
else{
GameTextForPlayer(playerid,"~r~No estas en una estacion de gasolina",5000,5);
}
return 1;
}
public GiveFuel(playerid,vehicleid)
{
new lfuel,mon,string[256];
lfuel = 100 - Fuel[vehicleid];
mon = lfuel * 7;
if (mon <= GetPlayerMoney(playerid)){
Fuel[vehicleid] = 0;
format(string,255,"Vehiculo llenado por $%d.",mon);
SendClientMessage(playerid,-1,string);
}
else
{
SendClientMessage(playerid,-1,"No tienes dinero!.");
}
}
public InGasStation(Float:radi, playerid, Float:x, Float:y, Float:z)
{
if(IsPlayerConnected(playerid))
{
new Float:oldposx, Float:oldposy, Float:oldposz;
new Float:tempposx, Float:tempposy, Float:tempposz;
GetPlayerPos(playerid, oldposx, oldposy, oldposz);
tempposx = (oldposx -x);
tempposy = (oldposy -y);
tempposz = (oldposz -z);
if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
{
return 1;
}
}
return 0;
}
Me gustarнa que me ayudaran a crear un Stock que contenga las coordenadas, para asн achico mбs el comando y queda mбs optimizado.
Desde ya muchas gracias.
Respuesta: їMe ayudan a hacer esto? -
Swedky - 05.09.2014
Creando un stock no te va a optimizar el cуdigo.
Respuesta: їMe ayudan a hacer esto? -
YazukiAkira - 05.09.2014
pawn Код:
CMD:llenar(playerid, params[])
{
new vehicleid = GetPlayerVehicleID(playerid);
if (estacionGas(playerid)) GiveFuel(playerid, vehicleid);
else GameTextForPlayer(playerid, "~r~No estas en una estacion de gasolina", 5000, 5);
return 1;
}
public GiveFuel(playerid, vehicleid)
{
new lfuel,mon,string[256];
lfuel = 100 - Fuel[vehicleid];
mon = lfuel * 7;
if (mon <= GetPlayerMoney(playerid))
{
Fuel[vehicleid] = 0;
format(string, 255, "Vehiculo llenado por $%d.", mon);
SendClientMessage(playerid, -1, string);
}
else SendClientMessage(playerid, -1, "No tienes dinero!.");
}
stock estacionGas(playerid)
{
if (IsPlayerInRangeOfPoint(playerid, 6.0, 1087.91004.0070,-939.3102,42.1797) ||
IsPlayerInRangeOfPoint(playerid, 6.0, 1944.3260,-1772.9254,13.3906))
return 1;
else if (IsPlayerInRangeOfPoint(playerid, 6.0, -90.5515,-1169.4578,2.4079) ||
IsPlayerInRangeOfPoint(playerid, 6.0, -1609.7958,-2718.2048,48.5391))
return 1;
else if (IsPlayerInRangeOfPoint(playerid, 6.0, -2029.4968,156.4366,28.9498) ||
IsPlayerInRangeOfPoint(playerid, 8.0, -2408.7590,976.0934,45.4175))
return 1;
else if (IsPlayerInRangeOfPoint(playerid, 5.0, -2243.9629,-2560.6477,31.8841) ||
IsPlayerInRangeOfPoint(playerid, 8.0, -1676.6323,414.0262,6.9484))
return 1;
else if (IsPlayerInRangeOfPoint(playerid, 6.0, 2202.2349,2474.3494,10.5258) ||
IsPlayerInRangeOfPoint(playerid, 10.0, 614.9333,1689.7418,6.6968))
return 1;
else if (IsPlayerInRangeOfPoint(playerid, 8.0, -1328.8250,2677.2173,49.7665) ||
IsPlayerInRangeOfPoint(playerid, 6.0, 70.3882,1218.6783,18.5165))
return 1;
else if (IsPlayerInRangeOfPoint(playerid, 8.0, 2113.7390,920.1079,10.5255) ||
IsPlayerInRangeOfPoint(playerid, 6.0, -1327.7218,2678.8723,50.0625))
return 1;
return 0;
}
Respuesta: їMe ayudan a hacer esto? -
Alexander11 - 05.09.2014
Quote:
Originally Posted by EnzoMetlc
Creando un stock no te va a optimizar el cуdigo.
|
Ya lo se, pero de todas formas me referнa a que si me ayudaban a crear el stock para achicar el comando xD
Respuesta: їMe ayudan a hacer esto? -
Swedky - 05.09.2014
Lo mejor que puedes hacer es crear un array que almacene todas esas posiciones, luego con un bucle recorrer todas esas coordenadas y verificando si el jugador estб en йsas, y usar la funciуn
GiveFuel.
Respuesta: їMe ayudan a hacer esto? -
OTACON - 05.09.2014
pawn Код:
#define DISTANCIA_GAS 6.0
enum gas { Float:GasUbicacion[3] };
new AtodoGas[][gas] = {
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0}
/*ETC...*/
};
CMD:llenar(playerid, params[]){
new vehicleid = GetPlayerVehicleID(playerid);
if(InGasStation(playerid)){
GiveFuel(playerid,vehicleid);
}else{
GameTextForPlayer(playerid,"~r~No estas en una estacion de gasolina",5000,5);
}
return false;
}
stock InGasStation(playerid){
for(new idx=0; idx< sizeof(AtodoGas); idx++){
if(IsPlayerInRangeOfPoint(playerid, DISTANCIA_GAS, AtodoGas[idx][GasUbicacion][0], AtodoGas[idx][GasUbicacion][1], AtodoGas[idx][GasUbicacion][2])) return true;
}return false;
}
pawn Код:
enum gas { Float:GasUbicacion[4] };
new AtodoGas[][gas] = {
{/*posicion*/0.0, 0.0, 0.0, /*distancia*/0.0},
{/*posicion*/0.0, 0.0, 0.0, /*distancia*/0.0},
{/*posicion*/0.0, 0.0, 0.0, /*distancia*/0.0},
{/*posicion*/0.0, 0.0, 0.0, /*distancia*/0.0},
{/*posicion*/0.0, 0.0, 0.0, /*distancia*/0.0},
/*ETC...*/
};
CMD:llenar(playerid, params[]){
new vehicleid = GetPlayerVehicleID(playerid);
if(InGasStation(playerid)){
GiveFuel(playerid,vehicleid);
}else{
GameTextForPlayer(playerid,"~r~No estas en una estacion de gasolina",5000,5);
}
return false;
}
stock InGasStation(playerid){
for(new idx=0; idx< sizeof(AtodoGas); idx++){
if(IsPlayerInRangeOfPoint(playerid, AtodoGas[idx][GasUbicacion][3], AtodoGas[idx][GasUbicacion][0], AtodoGas[idx][GasUbicacion][1], AtodoGas[idx][GasUbicacion][2])) return true;
}return false;
}
PD: no tiene lуgica crear una funciуn 'InGasStation' con el mismo funcionamiento que la funciуn nativa de samp 'IsPlayerInRangeOfPoint'