golanu21 Posted August 8, 2013 Share Posted August 8, 2013 addEventHandler("onPlayerJoin", getRootElement(), function () zombie_db = connectToDB() x, y, z = getElementPosition(source) dbExec( zombie_db, "INSERT INTO characters (nume, model, health, posx, posy, posz) VALUES (?,?,?,?,?,?)", getPlayerName(source), getElementModel(source), getElementHealth(source), x, y, z ) end) why when i enter in game with same name a new row is appear ...with same name and same valors... Link to comment
xXMADEXx Posted August 8, 2013 Share Posted August 8, 2013 (Did you ever create the table?) Try this: ((Not Tested)) local zombie_db = connectToDB() addEventHandler("onPlayerJoin", getRootElement(), function () local x, y, z = getElementPosition(source) dbExec( zombie_db, "INSERT INTO characters (nume, model, health, posx, posy, posz) VALUES (?,?,?,?,?,?)", getPlayerName(source), getElementModel(source), getElementHealth(source), x, y, z ) end) Link to comment
golanu21 Posted August 8, 2013 Author Share Posted August 8, 2013 i show you the full script ? Link to comment
golanu21 Posted August 8, 2013 Author Share Posted August 8, 2013 (Did you ever create the table?)Try this: ((Not Tested)) local zombie_db = connectToDB() addEventHandler("onPlayerJoin", getRootElement(), function () local x, y, z = getElementPosition(source) dbExec( zombie_db, "INSERT INTO characters (nume, model, health, posx, posy, posz) VALUES (?,?,?,?,?,?)", getPlayerName(source), getElementModel(source), getElementHealth(source), x, y, z ) end) P.S: same error Link to comment
xXMADEXx Posted August 8, 2013 Share Posted August 8, 2013 Yea, post the whole script. Link to comment
golanu21 Posted August 8, 2013 Author Share Posted August 8, 2013 -- Exemplu de conectare la MySQL local host = "secret"; local dbname = "secret"; local username = "secret"; local password = "secret"; function connectToDB() zombie_db = dbConnect("mysql", "dbname="..dbname..";host="..host, username, password, "autoreconnect=1") return zombie_db end function creeazaTabel() zombie_db = connectToDB() local characters = dbExec( zombie_db, "CREATE TABLE IF NOT EXISTS characters (id INT NOT NULL AUTO_INCREMENT, nume VARCHAR(50) NOT NULL, model INT NOT NULL, health FLOAT NOT NULL, posx FLOAT NOT NULL, posy FLOAT NOT NULL, posz FLOAT NOT NULL, PRIMARY KEY (id))") end addEventHandler("onResourceStart", getRootElement(getThisResource()), creeazaTabel) local zombie_db = connectToDB() ip = 0 addEventHandler("onPlayerJoin", getRootElement(), function () if ip == 0 then local x, y, z = getElementPosition(source) dbExec( zombie_db, "INSERT INTO characters (nume, model, health, posx, posy, posz) VALUES (?,?,?,?,?,?)", getPlayerName(source), getElementModel(source), getElementHealth(source), x, y, z ) ip = 1 elseif ip == 1 then cancelEvent() end end) addEventHandler("onPlayerQuit", getRootElement(), function () zombie_db = connectToDB() dbExec( zombie_db, "UPDATE characters SET nume=?, health=?", getPlayerName(source), getElementHealth(source)) end ) function viataCandSpawneaza() zombie_db = connectToDB() local second = dbQuery( zombie_db, "SELECT * FROM characters WHERE nume=?", getPlayerName(source)) local result, numrows = dbPoll(second, -1) if (result and numrows > 0) then for index, row in pairs(result) do setElementHealth(source, row['health']) end end end addEventHandler ( "onPlayerLogin", getRootElement(), viataCandSpawneaza ) this is the full code, but i fixed it with a variabile 0, and when player join, set variabile 1, and when variabile is 1 cancelevent Link to comment
xXMADEXx Posted August 8, 2013 Share Posted August 8, 2013 What does debugscript say? Link to comment
golanu21 Posted August 8, 2013 Author Share Posted August 8, 2013 nothing.. is fixed work perfectly Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now