Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Problem with LUA scripts and DB

Junior Spellweaver
Joined
Nov 23, 2008
Messages
146
Reaction score
11
Hello guys.

Here is my problem. I've trying to write a script to save players coordinates (from GTA V) directly into the database. So then when we relog, we spawn exactly at the same place.

Here is what i wrote :

Code:
local function savePlayerCoords()
    SetTimeout(10000, function()
        TriggerEvent("es:getPlayers", function(users)
                for k,v in pairs(users)do
                    MySQL:executeQuery("UPDATE users SET `lastpos`='@value' WHERE identifier = '@identifier'",
                        {['@value'] = v.pos, ['@identifier'] = v.identifier})
                        end
                    end)
            
            savePlayerCoords()
        end)
    end



And here is a script that writes coordinates into a .txt file and save it in it.

client.lua
RegisterNetEvent("SaveCommand")
AddEventHandler("SaveCommand", function()
x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
local PlayerName = GetPlayerName()
TriggerServerEvent("SaveCoords", PlayerName , x , y , z)
end)

server.lua

Code:
RegisterServerEvent("SaveCoords")
AddEventHandler("SaveCoords", function( PlayerName , x , y , z )
 file = io.open( PlayerName .. "-Coords.txt", "a")
    if file then
        file:write("{" .. x .. "," .. y .. "," .. z .. "},")
        file:write("\n")
    end
    file:close()
end)

AddEventHandler("chatMessage", function(p, color, msg)
    if msg:sub(1, 1) == "/" then
        fullcmd = stringSplit(msg, " ")
        cmd = fullcmd[1]

        if cmd == "/pos" then
        	TriggerClientEvent("SaveCommand", p)
        	CancelEvent()
        end
    end
end)


function stringSplit(self, delimiter)
  local a = self:Split(delimiter)
  local t = {}

  for i = 0, #a - 1 do
     table.insert(t, a[i])
  end

  return t
end


So, i'm trying to save it in my DB that has a
table and in the
column.

I'm struggling with it and don't know how to do that...



Here are some pictures :

ihaki - Problem with LUA scripts and DB - RaGEZONE Forums


ihaki - Problem with LUA scripts and DB - RaGEZONE Forums


ihaki - Problem with LUA scripts and DB - RaGEZONE Forums
 
Last edited:
Back
Top