[Pawn] Help with sqlite floats - Printable Version + open.mp forum (https://forum.open.mp) -- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3) --- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10) --- Thread: [Pawn] Help with sqlite floats (/showthread.php?tid=1859) |
Help with sqlite floats - Turk54721 - 2021-04-11 Hello for some reason floats are being loaded normaly (Armour and health is 1 and cordinates are like 5169131981403219871320) Code: enum PlayerStats{ Code: GetPlayerPos(playerid, Player[playerid][X], Player[playerid][Y], Player[playerid][Z]); Code: format(Query, sizeof(Query), "SELECT * FROM `USERS` WHERE `NAME` = '%s' COLLATE NOCASE AND `PASSWORD` = '%s'", DB_Escape(name), DB_Escape(inputtext)); Code: format(Query, sizeof(Query), "INSERT INTO `USERS` (`NAME`, `PASSWORD`, `IP`, `TEAM`, `SKIN`, `MONEY`, `SCORE`, `HEALTH`, `ARMOUR`, `X`, `Y`, `Z`) VALUES('%s','%s','%s', '0', '0', '0', '0', '%f', '%f', '%f', '%f', '%f')", DB_Escape(name), DB_Escape(inputtext), DB_Escape(ip)); Let me know if you need more code to understand, thank you RE: Help with sqlite floats - DandoRYx - 2021-04-11 How about changing %d to %f ? Code: HEALTH = '%d', ARMOUR = '%d', X = '%d', Y = '%d', Z = '%d' and same in here: Code: format(Query, sizeof(Query), "INSERT INTO `USERS` (`NAME`, `PASSWORD`, `IP`, `TEAM`, `SKIN`, `MONEY`, `SCORE`, `HEALTH`, `ARMOUR`, `X`, `Y`, `Z`) VALUES('%s','%s','%s', '0', '0', '0', '0', '%d', '%d', '%d', '%d', '%d')", DB_Escape(name), DB_Escape(inputtext), DB_Escape(ip)); RE: Help with sqlite floats - Turk54721 - 2021-04-11 (2021-04-11, 01:52 PM)DandoRYx Wrote: How about changing %d to %f ? I think I tried that, will try again when I will get home, thanks for answer. RE: Help with sqlite floats - DandoRYx - 2021-04-11 Now when I looked at it, from string to float you shouldn't be using strval, because that converts to integer. You should use floatstr(string) instead. But then the variables Player[playerid][Health] etc.. should be float. RE: Help with sqlite floats - Turk54721 - 2021-04-11 (2021-04-11, 03:43 PM)DandoRYx Wrote: Now when I looked at it, from string to float you shouldn't be using strval, because that converts to integer. You should use floatstr(string) instead. How would line like this look??[code]Player[playerid][Health] = floatstr(string);[/code] I'm new to scripting I've tryied smth like??[code]floatstr(Player[playerid][Health]);[/code] BTW Health armour and x y z was already float. RE: Help with sqlite floats - DandoRYx - 2021-04-11 Oh my bad :D, I read bad line... You have it right then, but you still need to change those %d to %f RE: Help with sqlite floats - Turk54721 - 2021-04-11 What ever I do I get no values in DB: https://gyazo.com/dd6fb875c00e5f0afd06579087f4427e RE: Help with sqlite floats - DandoRYx - 2021-04-11 oh, you have to put the variables itself into the query so you do: Code: GetPlayerPos(playerid, Player[playerid][X], Player[playerid][Y], Player[playerid][Z]); RE: Help with sqlite floats - Turk54721 - 2021-04-11 I don't know man, I keep getting the same result as in that photo, this is how the code look like now: https://pastebin.com/iVr4BHaj RE: Help with sqlite floats - Turk54721 - 2021-04-12 When I change from %d to %f, I get no values at all (In DB) RE: Help with sqlite floats - DandoRYx - 2021-04-12 I don't see any problem in there, your last chance might be changing every %f back to %d, and convert every float (for example Player[playerid][Health]) to integer: Code: Player[playerid][Health] but I would keep the floatstr(Field) as it is. https://open.mp/docs/scripting/functions/floatround RE: Help with sqlite floats - Turk54721 - 2021-04-12 I changed it to %d and did floatround when saving (Everything works fine), but now when loading I get 0 values on health armour x y z RE: Help with sqlite floats - DandoRYx - 2021-04-14 Then try to change it to this: Code: db_get_field_assoc(Result, "X"); RE: Help with sqlite floats - Turk54721 - 2021-04-16 Thank you, had to change some other things too and it worked |