Converting a string to an integer [I think]
#1

Well, I want to save a vehicles health when the player despawns it.
Here is my code, but it just sets the vehicle health to 0.

pawn Код:
CMD:despawn(playerid, params[])
{
    new string[128];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    {
          new veh = PlayerInfo[playerid][pVeh]; //This is their personal vehicles, vehicle ID
          new Float:health;
          GetVehicleHealth(veh, health);
          if(vspawned[playerid] == 0) return SendClientMessage(playerid, COLOR_GREY, "You don't have a spawned car.");
          if(health == 400) return SendClientMessage(playerid, COLOR_RED, "This vehicle is too damaged.");
          PlayerInfo[playerid][pVehHealth] = 0; //This stores the vehicles health, so I set it to 0 here and below..
          PlayerInfo[playerid][pVehHealth] += health; //I added on the whatever the current vehicle health was..
          if(PlayerInfo[playerid][vModel] == 0) return SendClientMessage(playerid, COLOR_GREY, "You dont have vehicle in this slot.");
          {
              if(PlayerInfo[playerid][vModel])
              {
                   DestroyVehicle(PlayerInfo[playerid][pVeh]);
              }
          }
          v1spawned[playerid] = 0;
          vspawned[playerid] = 0;
          format(string, sizeof(string), "You have despawned your %s.", RVN(PlayerInfo[playerid][vModel]));
          SendClientMessage(playerid, COLOR_YELLOW, string);
    }
    return 1;
}
If I'm trying to save the vehicles health completely wrong, could you show me how I might do it correctly?
Reply
#2

pawn Код:
if(health <= 400) return SendClientMessage(playerid, COLOR_RED, "This vehicle is too damaged.");
PlayerInfo[playerid][pVehHealth] = health;
Also make sure "pVehHealth" is defined as a float in your enum:
pawn Код:
Float:pVehHealth,
Reply
#3

Quote:
Originally Posted by Schneider
Посмотреть сообщение
pawn Код:
if(health <= 400) return SendClientMessage(playerid, COLOR_RED, "This vehicle is too damaged.");
PlayerInfo[playerid][pVehHealth] = health;
Also make sure "pVehHealth" is defined as a float in your enum:
pawn Код:
Float:pVehHealth,
Whenever I use this:
pawn Код:
enum pInfo
{
     Float:pVehHealth,
}
I'm getting tag mismatch errors on these lines of code:
pawn Код:
dini_IntSet(file, "VehicleHealth", PlayerInfo[playerid][pVehHealth]); // Tag Mismatch
new vhealth = PlayerInfo[playerid][pVehHealth]; // Tag Mismatch
The reason for "new vhealth" is so I can use it like this:

pawn Код:
new vhealth = PlayerInfo[playerid][pVehHealth];
new vid = PlayerInfo[playerid][pVeh];
SetVehicleHealth(vid, vhealth);
Reply
#4

Okay, I just fixed the problem, it was suppose to be:

pawn Код:
dini_FloatSet(file, "VehicleHealth", PlayerInfo[playerid][pVehHealth]); // Tag Mismatch
Instead of:

pawn Код:
dini_IntSet(file, "VehicleHealth", PlayerInfo[playerid][pVehHealth]); // Tag Mismatch
Reply
#5

be cause you are using a dini-integer function to save it, not a float one:
pawn Код:
dini_FloatSet(file, "VehicleHealth", PlayerInfo[playerid][pVehHealth]); // dini_FloatSet instead of dini_IntSet
new Float:vhealth = PlayerInfo[playerid][pVehHealth]; // pVehHealth is a float variable, so vhealth should be too.
P.S: recommended to use y_ini in saving functions, dini is too old and slow.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)