- 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 :
And here is a script that writes coordinates into a .txt file and save it in it.
client.lua
server.lua
So, i'm trying to save it in my DB that has a
I'm struggling with it and don't know how to do that...
Here are some pictures :
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 theUSERS
column.LASTPOS
I'm struggling with it and don't know how to do that...
Here are some pictures :
Last edited: