24.05.2011, 10:35
I'll have following code, that should be tuned also for that it gets that nearest gas station gas price. Gas price for each station is defined in file in this format:
-2244.1365,-2560.6294,31.6276,28,City
(X,Y,Z,PRICE,OWNER)
However I don't know how to do it, so plz help with that.
-2244.1365,-2560.6294,31.6276,28,City
(X,Y,Z,PRICE,OWNER)
However I don't know how to do it, so plz help with that.
pawn Код:
#define MAX_FUELSTATIONS 50 // Max fuelstations
//----------------------------------------------------------
// Fuelstaions
//----------------------------------------------------------
enum FuelSTInfo
{
nblank,
ownerfuel[45],
Float:stX,
Float:stY,
Float:stZ,
fuelcost
};
new stfuelcoords[MAX_FUELSTATIONS][FuelSTInfo];
stock LoadFuelStaions()
{
new SplitDiv[5][MAX_FUELSTATIONS];
new filestring[256];
new fueltext[55];
new File: file = fopen(FUEL_FILE, io_read);
for(new stid = 0; stid < MAX_FUELSTATIONS; stid++)
{
fread(file, filestring);
split(filestring, SplitDiv, ',');
stfuelcoords[stid][stX] = floatstr(SplitDiv[0]);
stfuelcoords[stid][stY] = floatstr(SplitDiv[1]);
stfuelcoords[stid][stZ] = floatstr(SplitDiv[2]);
stfuelcoords[stid][fuelcost] = strval(SplitDiv[3]);
strmid(stfuelcoords[stid][ownerfuel], SplitDiv[4], 0, strlen(SplitDiv[4]), 255);
format(fueltext, sizeof(fueltext), "PRICE: %iЂ/L || OWNER: %s", stfuelcoords[stid][fuelcost], stfuelcoords[stid][ownerfuel]);
CreateDynamicMapIcon(stfuelcoords[stid][stX], stfuelcoords[stid][stY], stfuelcoords[stid][stZ], 51, 0, -1, -1, -1, 100.0);
CreateDynamic3DTextLabel(fueltext, ADS_COLOR, stfuelcoords[stid][stX], stfuelcoords[stid][stY], stfuelcoords[stid][stZ], DRAW_DISRANCE_3DTEXT, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, TEST_LOS, -1, -1, -1, 100.0);
}
fclose(file);
}
stock CloseToGas(playerid)
{
new Float:maxdis = 15.0;
new Float:ppos[3];
GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
for(new i = 0;i<MAX_FUELSTATIONS;i++)
{
if (ppos[0] >= floatsub(stfuelcoords[i][stX], maxdis) && ppos[0] <= floatadd(stfuelcoords[i][stX], maxdis)
&& ppos[1] >= floatsub(stfuelcoords[i][stY], maxdis) && ppos[1] <= floatadd(stfuelcoords[i][stY], maxdis)
&& ppos[2] >= floatsub(stfuelcoords[i][stZ], maxdis) && ppos[2] <= floatadd(stfuelcoords[i][stZ], maxdis))
{
return i;
}
}
maxdis = 20.0;
for(new i = 16;i<MAX_FUELSTATIONS;i++)
{
if (ppos[0] >= floatsub(stfuelcoords[i][stX], maxdis) && ppos[0] <= floatadd(stfuelcoords[i][stX], maxdis)
&& ppos[1] >= floatsub(stfuelcoords[i][stY], maxdis) && ppos[1] <= floatadd(stfuelcoords[i][stY], maxdis)
&& ppos[2] >= floatsub(stfuelcoords[i][stZ], maxdis) && ppos[2] <= floatadd(stfuelcoords[i][stZ], maxdis))
{
return i;
}
}
return 999;
}