Setting String Depending On Float (I think?)
#1

Okay, firstly thanks for even looking at his to help.

Okay I could do it like this

pawn Код:
new Float:Health;
    GetPlayerHealth(playerid,Health);
    if(Health == 99)
    {
        TextDrawSetString(HealthBar[playerid],"...................................................................................................");
      return 1;
    }
But that means I need to do that 100 times, which would kind of blag to write out, so could I create a string, then the amount of health = the amount of dots.

pawn Код:
new Float:Health, string[128];
    GetPlayerHealth(playerid,Health);
    //format the string to health = dots
    TextDrawSetString(HealthBar[playerid],string);
Thanks in advance.
Reply
#2

You could convert the float to an integer, then loop strcat to add a dot each time, and then send the string this makes.

eg:

pawn Код:
new Float:Health, iHealth, LString[105];
    GetPlayerHealth(playerid,Health);
    iHealth = floatround(Health, floatround_ceil);
    for(new i; i < iHealth; i++)
    {
        strcat(LString, ".");
    }
Very Untested.
Reply
#3

pawn Код:
LString[i] = '.';
will be much faster than strcat
Reply
#4

Plus I don't think I was using strcat properly, thanks >.>
Reply
#5

I'll give it a test, thanks a lot for the input it means a lot to me.
Reply
#6

Now that is really something, thanks a lot, I just learnt an amazing function and saved 1000 lines of code.

Thanks a lot Orb and Weirdo!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)