Jump to content

[HELP] Data Base returns nickname


Recommended Posts

Hi. I wanted to make timer on server side that will updating players money. Cause my money in the corner are based on custom dxText that download money status from getPlayerMoney.  And here i have a problem. When i want to  setPlayerMoney ,from database i still receive only playername. For sure i did something wrong. I checked PHP code in my SQL tab (XAMPP) and it worked as intended. Here is the code. Please Help. I'll be thankfull

local dbc = dbConnect("")

setTimer("onClientRender",function(nick)
    local pn = getPlayerName
    local dbq = dbQuery(dbc,"SELECT money FROM users WHERE nickname='pn'")
      setPlayerMoney(pn,dbq)1000,0)
    

in dbc is defined utf8, same as my sql database

Edit1 and variable coming from database should be INT

Edited by Prever77
Link to comment
I haven't tested it but it could be something like this you will need to call the loadPlayerMoney function
local db_name = "your db name" --fill your info
local db_host = "localhost"
local db_user = "your username" --fill your info
local db_pass = "your password" --fill your info
local DbConnection = dbConnect("mysql", "dbname="..db_name..";host="..db_host..";charset=utf8", db_user, db_pass, "share=1")

function loadPlayerMoney(player)
   local _player = player
   local playerNick = getPlayerName(_player)
   dbQuery(
   function(query, player)
   local result = dbPoll(query, 0)
   if(#result <= 0) then return end --if result table 0 dont go
      for _,data in pairs(result) do
   	     setPlayerMoney(player, data["money"]) --set money
         break
      end
   end,{_player}, DbConnection, "SELECT money FROM users WHERE nickname=? LIMIT 1", playerNick)
end
Edited by Burak5312
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...