Jump to content

Recommended Posts

Hallo, please help me!
 

Spoiler

db_name = "mta_save" 
host = "127.0.0.1" 
user = "root" 
password = "" 
  
database = dbConnect( "mysql", "dbname="..db_name..";host="..host, user, password ) 
if database then 
    outputDebugString ('Connect') 
else 
    outputDebugString ("Trouble") 
end 
  
function saveAccounts () 
    local serial = getPlayerSerial ( source )
    local x,y,z = getElementPosition( source )
    local i = getElementInterior( source )
    local d = getElementDimension( source )
    local skin = getPedSkin ( source )
    local money = getPlayerMoney ( source )
    local health = getElementHealth ( source )
    local armor = getPedArmor ( source )
    local wanted = getPlayerWantedLevel ( source )
    local team = getPlayerTeam ( source )
    local name = getPlayerName ( source )
    local q =  dbQuery(database,"SELECT * FROM accounts WHERE serial = ?", serial) 
    local poll, rows = dbPoll(q, -1) 
    if(rows == 0) then 
        dbExec( database, "INSERT INTO accounts ( serial , x, y, z, intterior, demension, skin, money, health, armor, wanted, team, name ) VALUES ( '" .. serial .. "', " .. x .. ", " .. y .. ", " .. z .. "," .. i .. ", " .. d .. "," .. skin .. "," .. money .. ", ".. health ..", ".. armor ..", " .. wanted .. ", " .. team .. ", " .. name .. " )" )
    else 
        dbExec ( database, "UPDATE accounts SET x = ".. x ..", y =  ".. y ..", z = ".. z ..", intterior = ".. i ..", demension = ".. d ..", skin = ".. skin ..", money = ".. money ..", health = ".. health ..", armor = ".. armor ..", wanted = ".. wanted ..", team = ".. team ..", name = ".. name .." WHERE `serial` = '"..serial.."'")
    end 
end 
  
function loadAccounts ()
local row = dbPoll(result)
    setElementPosition ( source, row.x, row.y, row.z)
    setElementInterior ( source, row.intterior )
    setElementDimension ( source, row.demension )
    setPedSkin ( source, row.skin )
    setPlayerMoney ( source, row.money )
    setElementHealth ( source, row.health)
    setPedArmor ( source, row.armor )
    setPlayerWantedLevel ( source, row.wanted )
    setPlayerTeam ( source, row.team )
    local result = dbQuery ( database ,"SELECT * FROM accounts WHERE serial = ?", serial) 
    local poll, rows = dbPoll(result, -1) 
    if rows == 1 then 
        setPlayerMoney ( source, poll[1]["money"] ) 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), loadAccounts ) 
addEventHandler ( "onPlayerQuit", getRootElement(), saveAccounts ) 

 

Edited by DarkxD
Link to comment
function loadAccounts()
if source then
local serial = getPlayerSerial(source)
local result = dbQuery(database, "SELECT * FROM accounts WHERE serial = ?", serial)
if result then
local row = dbPoll(result)
setElementPosition(source, row.x, row.y, row.z)
setElementInterior(source, row.intterior)
setElementDimension(source, row.demension)
setElementModel(source, row.skin)
setElementHealth(source, row.health)
setPedArmor(source, row.armor)
setPlayerWantedLevel(source, row.wanted)
setPlayerTeam(source, row.team)
local poll, rows = dbPoll(result, -1) 
if rows == 1 then
setPlayerMoney(source, poll[1]["money"])
end
end
end
end
addEventHandler("onPlayerJoin", getRootElement(), loadAccounts) 
addEventHandler("onPlayerQuit", getRootElement(), saveAccounts)  


Try this.

Link to comment
2 hours ago, SARSRPG said:

function loadAccounts()
if source then
local serial = getPlayerSerial(source)
local result = dbQuery(database, "SELECT * FROM accounts WHERE serial = ?", serial)
if result then
local row = dbPoll(result)
setElementPosition(source, row.x, row.y, row.z)
setElementInterior(source, row.intterior)
setElementDimension(source, row.demension)
setElementModel(source, row.skin)
setElementHealth(source, row.health)
setPedArmor(source, row.armor)
setPlayerWantedLevel(source, row.wanted)
setPlayerTeam(source, row.team)
local poll, rows = dbPoll(result, -1) 
if rows == 1 then
setPlayerMoney(source, poll[1]["money"])
end
end
end
end
addEventHandler("onPlayerJoin", getRootElement(), loadAccounts) 
addEventHandler("onPlayerQuit", getRootElement(), saveAccounts)  


Try this.

 

Also, I noticed something. Do you have a separate spawning system? Because if you do, I would understand. But upon player joining the game, if they aren't being spawned from another script, then it should be doing it from this one.

Let me know

Link to comment
  • 2 weeks later...
function loadAccounts()
if source then
local serial = getPlayerSerial(source)
local result = dbQuery(database, "SELECT * FROM accounts WHERE serial = ?", serial)
if result then
local row = dbPoll(result,-1)
setElementPosition(source, row.x, row.y, row.z)
setElementInterior(source, row.intterior)
setElementDimension(source, row.demension)
setElementModel(source, row.skin)
setElementHealth(source, row.health)
setPedArmor(source, row.armor)
setPlayerWantedLevel(source, row.wanted)
setPlayerTeam(source, row.team)
if #row > 0 then
setPlayerMoney(source, poll[1]["money"])
end
end
end
end
addEventHandler("onPlayerJoin", getRootElement(), loadAccounts) 

try this it will work

error is : you haven't read function returning values and calling same function two times

Read this : https://wiki.multitheftauto.com/wiki/DbPoll

Edited by Ayush Rathore
Well i havent used the lua insert function for reply
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...