Setting String Depending On Float (I think?) - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Setting String Depending On Float (I think?) (
/showthread.php?tid=80909)
Setting String Depending On Float (I think?) -
NeRoSiS - 07.06.2009
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.
Re: Setting String Depending On Float (I think?) -
Weirdosport - 07.06.2009
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.
Re: Setting String Depending On Float (I think?) -
yom - 07.06.2009
will be much faster than strcat
Re: Setting String Depending On Float (I think?) -
Weirdosport - 07.06.2009
Plus I don't think I was using strcat properly, thanks >.>
Re: Setting String Depending On Float (I think?) -
NeRoSiS - 07.06.2009
I'll give it a test, thanks a lot for the input it means a lot to me.
Re: Setting String Depending On Float (I think?) -
NeRoSiS - 07.06.2009
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!