Jump to content

Help


Recommended Posts

You can store the coordinates of the player's last location in a database of some sorts. When they join, query the coordinates for a row that matches their serial. If it exists, set it.

function saveMatrix() 
    local serial = getPlayerSerial(source) 
    local x, y, z, lx, ly, lz = getCameraMatrix(source) 
    dbExec(db, "UPDATE `saveMatrix` SET `x` = ?, `y` = ?, `z` = ?, `lx` = ?, `ly` = ?, `lz` = ? WHERE `serial` = ?", serial, x, y, z, lx, ly, lz) 
end 
addEventHandler("onPlayerQuit", root, saveMatrix) 
  
function loadMatrix() 
    -- db is not defined, use your own database here 
    local serial = getPlayerSerial(source) 
    local result = dbPoll(dbQuery(db, "SELECT `x`,` y`, `z`, `lx, `ly`, `lz` FROM `saveMatrix` WHERE `serial` = ? LIMIT 1", serial), -1) 
    if (#result >= 1) then 
        local x, y, z, lx, ly, lz = result[1].x, result[1].y, result[1].z, result[1].lx, result[1].ly, result[1].lz 
        setCameraMatrix(source, x, y, z, lx, ly, lz) 
    end 
end 
addEventHandler("onPlayerJoin", root, loadMatrix) 
  
  

Here's a basic rubric to go off.

Edited by Guest
Link to comment

Try this one :

-- db is not defined, use your own database here

function saveMatrix() 
    local serial = getPlayerSerial(source) 
    local x, y, z, lx, ly, lz = getCameraMatrix(source) 
    local camera = toJSON({x, y, z, lx, ly, lz}) 
    dbExec(db, "UPDATE `saveMatrix` SET `camera` = ? WHERE `serial` = ?", serial, camera) 
end 
addEventHandler("onPlayerQuit", root, saveMatrix) 
  
function loadMatrix() 
    local serial = getPlayerSerial(source) 
    local result = dbPoll(dbQuery(db, "SELECT * FROM `saveMatrix` WHERE `serial` = ?", serial), -1) 
    if (#result >= 1) then 
        local x, y, z, lx, ly, lz = unpack( fromJSON(result[1]["camera"])) 
        setCameraMatrix(source, x, y, z, lx, ly, lz) 
    end 
end 
addEventHandler("onPlayerJoin", root, loadMatrix) 

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...