• Set Health with sql
    4 replies, posted
I want to be able to set the player's health to a number saved in sql [code]printhp = sql.QueryValue("SELECT hp from playerpokemon")[/code] [code] concommand.Add("test61", function(ply) ply:SetHealth(printhp) end) [/code] How would I send printhp from shared/client to init?
Well there are a few things wrong with this... #1 what are you using just sqlite? If so then you might be able to just do this not sure if the query is prepared or not... #2 Your SQL would need to be "SELECT hp FROM playerpokemon" that FROM needs to be cap! you might also need to have a bit more in the query like a WHERE statement... I would look into it some more
What's the structure of `playerpokemon`? Also, why do you need to network it? [QUOTE=XxLMM13xXx;52068957] #1 what are you using just sqlite? If so then you might be able to just do this not sure if the query is prepared or not...[/quote] What does prepared queries have to do with this? [quote]#2 Your SQL would need to be "SELECT hp FROM playerpokemon" that FROM needs to be cap! you might also need to have a bit more in the query like a WHERE statement... I would look into it some more[/QUOTE] SQL keywords are case-insensitive, also, doesn't need to have a where clause, though we'd need to know the structure of the database to know.
[QUOTE=bigdogmat;52068991]What's the structure of `playerpokemon`? Also, why do you need to network it? What does prepared queries have to do with this? SQL keywords are case-insensitive, also, doesn't need to have a where clause, though we'd need to know the structure of the database to know.[/QUOTE] Well if lets say he is using mysqloo (well now i can tell he is not but did not really look into it) he may have to do a onsuccess function because you may not get a result instantly.. if that makes any sense... ignore the prepared part he does not need it in this case
I'm not sure what you mean by structure. When I print the sql table into the console it looks like this: [code] EXP = 0 atk = 11 def = 13 hp = 20 level = 5 model = models/rtbmodels/pokemon/squirtle.mdl move1 = tackle move2 = tail whip move3 = move3 move4 = move4 spatk = 11 spd = 10 spdef = 12 steamid = STEAM_0:0:34118778 [/code] [editline]7th April 2017[/editline] when I do this in shared.lua it works: [code]concommand.Add("test62", function(ply) ply:ChatPrint(sql.QueryValue("SELECT hp FROM playerpokemon WHERE steamid = '"..ply:SteamID().."'")) end)[/code] in init it return nothing though
Sorry, you need to Log In to post a reply to this thread.