Problem with gas variables.
#1

Hi peoples.I need some help with me gas system,and player run with vehicle distance,i get that with this variable:

Код:
vehicleDB[vehicleid][prav]/10000);//Vehicle all distance.
Then OnPlayerStateChange:

Код:
if(newstate == PLAYER_STATE_DRIVER)
{
SetPVarFloat(vehicleid,"PravBefore",vehicleDB[vehicleid][prav]/10000);
SetTimerEx("Speed",60000,true,"i",playerid);
}
Код:
public Speed(playerid)
{
if(model != 481 && model != 510 && model != 509)//if not bikes
{
if(vehicleDB[vehicleid][gas] > 2)// if more than 2 gas
{
SetPVarFloat(vehicleid,"PravAfter",vehicleDB[vehicleid][prav]/10000);//Other pvar who i set after prav(vehicle distance).
if(GetPVarFloat(vehicleid,"PravBefore") + GetPVarFloat(playerid,"PravAfter") >= 0.1)
{
vehicleDB[vehicleid][gas] -=0.1;
return 1;
}
SendClientMessage(playerid,COLOR_GREEN,"Before prav has been set");
SetPVarFloat(vehicleid,"PravBefore",vehicleDB[vehicleid][prav]/10000); // Save the float into a player variable
}
}
return 1;
}
But when passed 60000(milli seconds(1 min)),i not lose 0.1 gas,but i only get this message:

Код:
SendClientMessage(playerid,COLOR_GREEN,"Before prav has been set");
But i run with vehicle a lot of time and it's more than 0.1 distance...And if you ask is this variable show vehicle distance i say yes because i set another taimer for 1 sec,and after them:


Код:
public Speed(playerid)
{
new String[64];
new vehicleid = GetPlayerVehicleID(playerid);
new Float:ST[4];
GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]);
ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 180.3;

vehicleDB[vehicleid][prav] += ST[3];

format(String, sizeof(String), "Vehicle distance: %.1f",vehicleDB[vehicleid][prav]/10000);
TextDrawSetString(VehicleDistance[playerid], String);
TextDrawShowForPlayer(playerid, VehicleDistance[playerid]);
}
And i get textdraw with vehicle distance and this is good.But how i say in the top,maybe some thing is bad with pvars
Reply
#2

I couldn't understand hardly anything you were saying. Anyway, the following code has a few (possible) errors:
pawn Код:
public Speed(playerid)
{
if(model != 481 && model != 510 && model != 509)//if not bikes
{
if(vehicleDB[vehicleid][gas] > 2)// if more than 2 gas
{
SetPVarFloat(vehicleid,"PravAfter",vehicleDB[vehicleid][prav]/10000);//Other pvar who i set after prav(vehicle distance).
if(GetPVarFloat(vehicleid,"PravBefore") + GetPVarFloat(playerid,"PravAfter") >= 0.1)
{
vehicleDB[vehicleid][gas] -=0.1;
return 1;
}
SendClientMessage(playerid,COLOR_GREEN,"Before prav has been set");
SetPVarFloat(vehicleid,"PravBefore",vehicleDB[vehicleid][prav]/10000); // Save the float into a player variable
}
}
return 1;
}
How does that code even compile? You never create a vehicleid variable, yet you use it. Another potential flaw is that you mean to, assumed by the comments, set the player's PVar value. However, you set it based on the vehicleid, which may cause a problem if the vehicle ID of the driver does not match the player's ID.

I cannot assist you any further as I just simply cannot understand what you're saying.
Reply
#3

I want do that system,who when player run with vehicle,he lost gas,but i say you what is wrong here:

Код:
if(GetPVarFloat(vehicleid,"PravBefore") + GetPVarFloat(playerid,"PravAfter") >= 0.1)
{
vehicleDB[vehicleid][gas] -=0.1;
Why i don't lose 0.1 gas?i have run with vehicle more than 0.1 kilometres,but nothing...I don't lose gas.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)