#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;
}
new Rate, String[256];
Rate = stfuelcoords[gasid][fuelcost];
SetPlayerCheckpoint(playerid, stfuelcoords[gasid][stX], stfuelcoords[gasid][stY], stfuelcoords[gasid][stZ], 5.0);
stock refuel(playerid)
{
if(CloseToGas(playerid) != 999 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
gasprice[playerid] = gascost; // gascost amount should be filled in CloseToGas function.
if(GetPlayerMoney(playerid) >= gasprice[playerid])
{
SendClientMessage(playerid,COLOR_YELLOW,"Your vehicle is being tanking up...");
Filling[playerid] = 1;
gassing = SetTimer("TankUp", cSetting[tankingspeed], 1);
}
if(GetPlayerMoney(playerid) <= gasprice[playerid])
{
SendClientMessage(playerid,COLOR_BRIGHTRED,"You dont have enought money!");
Filling[playerid] = 0;
}
}
return 1;
}
stock ClosestGasSt(playerid)
{
new gasid, float:distance=99999.0, float:x, float:y, float:z;
GetPlayerPos(playerid, x, y, z)
for(new i=0; i<MAX_FUELSTATIONS; i++)
{
new float:tempdist = GetDistanceBetween(x, y, z, stfuelcoords[i][stX], stfuelcoords[i][stY], stfuelcoords[i][stZ]);
if(tempdist < distance)
{
distance = tempdist;
gasid = i;
}
return gasid;
}
stock GetDistanceBetween(x1, y1, z1, x2, y2, z2)
{
new float:dist;
dist = floatsqroot(floatpower(floatsub(x2, x1), 2) + floatpower(floatsub( y2, y1), 2) + floatpower(floatsub( z2, z1), 2));
return dist;
}
#define MAX_FUELSTATIONS 27 // Max fuelstations
enum FuelSTInfo
{
fuelstid,
ownerfuel[125],
Float:stX,
Float:stY,
Float:stZ,
fuelcost,
krtrue,
sttank
};
new stfuelcoords[MAX_FUELSTATIONS][FuelSTInfo];
stock LoadFuelStaions()
{
new SplitDiv[8][MAX_FUELSTATIONS];
new filestring[FILESTRING_SIZE];
new fueltext[55];
format(pfile, sizeof(pfile), "%s/%s/%s%s", CORE_FOLDER, SETTING_FOLDER, SUB_FILE_fuelstations, CORE_FOLDERS_FILESYSTEM);
new File: file = fopen(pfile, io_read);
for(new stid = 0; stid < MAX_FUELSTATIONS; stid++)
{
fread(file, filestring);
split(filestring, SplitDiv, ',');
stfuelcoords[stid][fuelstid] = strval(SplitDiv[0]);
stfuelcoords[stid][stX] = floatstr(SplitDiv[1]);
stfuelcoords[stid][stY] = floatstr(SplitDiv[2]);
stfuelcoords[stid][stZ] = floatstr(SplitDiv[3]);
stfuelcoords[stid][fuelcost] = strval(SplitDiv[4]);
strmid(stfuelcoords[stid][ownerfuel], SplitDiv[5], 0, strlen(SplitDiv[5]), 255);
stfuelcoords[stid][krtrue] = strval(SplitDiv[6]);
stfuelcoords[stid][sttank] = strval(SplitDiv[7]);
format(fueltext, sizeof(fueltext), "COST: %iЂ/Liter || 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);
stfuelcoords[stid][fuelstid] = CreateDynamic3DTextLabel(fueltext, FUELST_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 refuel(playerid)
{
if(CloseToGas(playerid) != 999 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
stfuelcoords[ClosestGasSt(playerid)][fuelcost] = gasprice[playerid];
if(GetPlayerMoney(playerid) >= gasprice[playerid])
{
SendClientMessage(playerid,COLOR_YELLOW,"...");
Filling[playerid] = 1;
tankkaus = SetTimer("Tankkaa", cSetting[tankkausnopeus], 1);
}
if(GetPlayerMoney(playerid) <= gasprice[playerid])
{
SendClientMessage(playerid,COLOR_BRIGHTRED,"....");
Filling[playerid] = 0;
}
}
return 1;
}
stock GetDistanceBetween(x1, y1, z1, x2, y2, z2)
{
new float:dist;
dist = floatsqroot(floatpower(floatsub(x2, x1), 2) + floatpower(floatsub( y2, y1), 2) + floatpower(floatsub( z2, z1), 2));
return dist;
}
stock ClosestGasSt(playerid)
{
new gasid, float:distance=99999.0, float:x, float:y, float:z;
GetPlayerPos(playerid, x, y, z);
for(new i=0; i<MAX_FUELSTATIONS; i++)
{
new float:tempdist = GetDistanceBetween(x, y, z, stfuelcoords[i][stX], stfuelcoords[i][stY], stfuelcoords[i][stZ]);
if(tempdist < distance)
{
distance = tempdist;
gasid = i;
}
}
return gasid;
}
public Tankkaa()
{
foreach(Player, i)
{
if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
{
if(Filling[i] == 1)
{
if(Gas[GetPlayerVehicleID(i)] < 100)
{
Gas[GetPlayerVehicleID(i)] = (Gas[GetPlayerVehicleID(i)]+1);
GivePlayerMoney(i, -gasprice[i]);
gascosted[i] = (gascosted[i] + gasprice[i]);
}
if(Gas[GetPlayerVehicleID(i)] > 99 && Filling[i] == 1)
{
format(carmess, sizeof(carmess), "%ssi is now full... and it cost for you %iЂ, ...!", VehicleInfo[GetPlayerVehicleID(i)][name2], gascosted[i]);
SendClientMessage(i, COLOR_GREEN, carmess);
Gas[GetPlayerVehicleID(i)] = MAX_GAS;
gasprice[i] = 0;
gascosted[i] = 0;
KillTimer(tankkaus);
Filling[i] = 0;
}
if(CloseToGas(i) == 999 && Filling[i] == 1)
{
format(carmess, sizeof(carmess), "it cost for you %iЂ.", gascosted[i]);
SendClientMessage(i, COLOR_BRIGHTRED, ".....");
SendClientMessage(i, COLOR_BRIGHTRED, carmess);
gasprice[i] = 0;
gascosted[i] = 0;
KillTimer(tankkaus);
Filling[i] = 0;
}
}
}
}
return 1;
}
Why are you using gasprice[i] instead of stfuelcoords[gasid][fuelcost]?
|