Jump to content

Help


Recommended Posts

Posted (edited)

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
Posted
-- db is not defined, use your own database here

You also need to insert it if it's not currently there, which I did not write.

Posted

You got an extra quotation in the last line of code after root here:

addEventHandler("onPlayerJoin", root", loadMatrix) 
 

You gone learn today.

I work my ass off, but I still can't pay tho.

Posted

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) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
You got an extra quotation in the last line of code after root here:
addEventHandler("onPlayerJoin", root", loadMatrix) 
  
 

Cheers. Edited it.

I don't have a DB script

Then you can just use account data.

Posted
I don't have a DB script

you can use sth like this:

local database = "dbName.db" 
local db = dbConnect("sqlite", database)  
dbExec(db, "CREATE TABLE IF NOT EXISTS saveMatrix (serial TEXT, camera TEXT)" ) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

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