Jump to content

SQL again! ( SOLVED: Ty IIYAMA )


Anubhav

Recommended Posts

  
addCommandHandler("gostaff",  
    function(plr) 
        local staffName = dbPoll(dbQuery(adminDB, "SELECT * FROM staffList WHERE staff=?", getAccountName(getPlayerAccount(plr))), -1) 
        if (not (#staffName == 0)) then 
            local staffNamer = dbPoll(dbQuery(adminDB, "SELECT * FROM adminSaver WHERE acc=?", getAccountName(getPlayerAccount(plr))), -1) 
            if #staffNamer ~= 0 then 
                dbExec(adminDB, "DELETE FROM adminSaver WHERE acc=?", getAccountName(getPlayerAccount(plr))) 
            end 
            local acc, x, y, z, skin, dim, inte = getAccountName(getPlayerAccount(plr)), getElementPosition(plr), getElementModel(plr), getElementDimension(plr), getElementInterior(plr) 
            local r, g, b = getTeamColor(getTeamFromName("Army")) 
            setPlayerNametagColor(plr, r, g, b) 
            setPlayerTeam(plr, getTeamFromName("Army")) 
            setElementModel(plr, 217) 
            setElementData(plr, "isPlayerStaff", true) 
            setElementData(plr, "Occupation", "Staff") 
            outputChatBox("You're now on duty!", plr, 225, 225, 225) 
            exports.killmessages:outputMessage(getPlayerName(plr).." is now on-staff-duty!", root, 0, 255, 0) 
             
            local t = getTeamName(getPlayerTeam(plr)) 
            dbExec(adminDB, "INSERT INTO adminSaver VALUES(?,?,?,?,?,?,?,?)", acc, x, y, z, skin, dim, inte, tostring(t)) 
         
        else 
            return 
        end 
    end 
) 
  

I used this no errors.

Now I select it again.

  
addCommandHandler("offduty", 
    function(plr) 
        if getElementData(plr, "isPlayerStaff") then 
            local answer = dbPoll(dbQuery(adminDB,"SELECT * FROM adminSaver WHERE acc=?", getAccountName(getPlayerAccount(plr))), -1) 
            if #answer ~= 0 then 
                fadeCamera( plr, false, 1.0, 0, 0, 0 ) 
                setTimer(fadeCamera, 5000, 1, plr, true ) 
                for k,v in ipairs(answer) do 
                    setTimer(spawnPlayer, 5000, 1, plr, v.x, v.y, v.z, 0, v.skin, 0, 0, getTeamFromName(v.teamName or nil) ) 
                end 
                outputChatBox("Now you are off-duty!", plr) 
                exports.killmessages:outputMessage(getPlayerName(plr).." is now off-staff-duty!", root, 0, 255, 0) 
                setElementData(plr, "isPlayerStaff", false) 
                dbExec(adminDB, "DELETE FROM adminSaver WHERE acc=?", getAccountName(getPlayerAccount(plr))) 
            end 
        end 
    end 
) 
  
  

No errors, keeps spawning me at same position even If I take another and use /gostaff!

Help! :(:oops:

Edited by Guest
Link to comment
  
      
    addCommandHandler("offduty", 
        function(plr) 
            if getElementData(plr, "isPlayerStaff") then 
                local answer = dbPoll(dbQuery(adminDB,"SELECT * FROM adminSaver WHERE acc=?", getAccountName(getPlayerAccount(plr))), -1) 
                if #answer ~= 0 then 
                    fadeCamera( plr, false, 1.0, 0, 0, 0 ) 
                    setTimer(fadeCamera, 5000, 1, plr, true ) 
                    for k,v in ipairs(answer) do 
                        setTimer(setElementPosition, 5000, 1, plr, tonumber(v.x), tonumber(v.y), tonumber(v.z) ) 
                        setElementModel(plr, tonumber(v.skin) ) 
                        setPlayerTeam(plr,getTeamFromName(tostring(v.teamName) or nil)) 
                    end 
                    outputChatBox("Now you are off-duty!", plr) 
                    exports.killmessages:outputMessage(getPlayerName(plr).." is now off-duty staff!", root, 0, 255, 0) 
                    setElementData(plr, "isPlayerStaff", false) 
                    dbExec(adminDB, "DELETE FROM adminSaver WHERE acc=?", getAccountName(getPlayerAccount(plr))) 
                end 
            end 
        end 
    ) 
      
      

Link to comment

You got the syntax wrong for inserting.

dbExec(adminDB, "INSERT INTO adminSaver VALUES(?,?,?,?,?,?,?,?)", acc, x, y, z, skin, dim, inte, tostring(t)) 

It should be something like this:

dbExec(adminDB, "INSERT INTO adminSaver (acc, x, y, z, skin, dim, inte, team) VALUES(?,?,?,?,?,?,?,?)", acc, x, y, z, skin, dim, inte, tostring(t)) 

(I don't know what your column names are so you'll probably need to rename them.)

And also make sure that adminDB is defined.

Link to comment
You got the syntax wrong for inserting.
dbExec(adminDB, "INSERT INTO adminSaver VALUES(?,?,?,?,?,?,?,?)", acc, x, y, z, skin, dim, inte, tostring(t)) 

It should be something like this:

dbExec(adminDB, "INSERT INTO adminSaver (acc, x, y, z, skin, dim, inte, team) VALUES(?,?,?,?,?,?,?,?)", acc, x, y, z, skin, dim, inte, tostring(t)) 

(I don't know what your column names are so you'll probably need to rename them.)

And also make sure that adminDB is defined.

I think you should actually use "UPDATE" instead of trying to "INSERT" it again...

Link to comment

I already delete it!

  
addCommandHandler("gostaff",  
    function(plr) 
        local staffName = dbPoll(dbQuery(adminDB, "SELECT * FROM staffList WHERE staff=?", getAccountName(getPlayerAccount(plr))), -1) 
        if (not (#staffName == 0)) then 
            local staffNamer = dbPoll(dbQuery(adminDB, "SELECT * FROM adminSaver WHERE acc=?", getAccountName(getPlayerAccount(plr))), -1) 
            if #staffNamer ~= 0 then 
                dbExec(adminDB, "DELETE FROM adminSaver WHERE acc=?", getAccountName(getPlayerAccount(plr))) 
            end 
            local acc, x, y, z, skin, dim, inte = getAccountName(getPlayerAccount(plr)), getElementPosition(plr), getElementModel(plr), getElementDimension(plr), getElementInterior(plr) 
            local r, g, b = getTeamColor(getTeamFromName("Army")) 
            setPlayerNametagColor(plr, r, g, b) 
            setPlayerTeam(plr, getTeamFromName("Army")) 
            setElementModel(plr, 217) 
            setElementData(plr, "isPlayerStaff", true) 
            setElementData(plr, "Occupation", "Staff") 
            outputChatBox("You're now on duty!", plr, 225, 225, 225) 
            exports.killmessages:outputMessage(getPlayerName(plr).." is now on-staff-duty!", root, 0, 255, 0) 
             
            local t = getTeamName(getPlayerTeam(plr)) 
            dbExec(adminDB, "INSERT INTO adminSaver (acc, x, y, z, skin, dimension, interior, teamName) VALUES(?,?,?,?,?,?,?,?)", tostring(acc), tonumber(x), tonumber(y), tonumber(z), tonumber(skin), tonumber(dim), tonumber(inte), tostring(t)) 
         
        else 
            return 
        end 
    end 
) 
  
  
      
    addCommandHandler("offduty", 
        function(plr) 
            if getElementData(plr, "isPlayerStaff") then 
                local answer = dbPoll(dbQuery(adminDB,"SELECT * FROM adminSaver WHERE acc=?", getAccountName(getPlayerAccount(plr))), -1) 
                if #answer ~= 0 then 
                    fadeCamera( plr, false, 1.0, 0, 0, 0 ) 
                    setTimer(fadeCamera, 5000, 1, plr, true ) 
                    for k,v in ipairs(answer) do 
                        setTimer(setElementPosition, 5000, 1, plr, tonumber(v.x), tonumber(v.y), tonumber(v.z) ) 
                        setElementModel(plr, tonumber(v.skin) ) 
                        setPlayerTeam(plr,getTeamFromName(tostring(v.teamName) or nil)) 
                    end 
                    outputChatBox("Now you are off-duty!", plr) 
                    exports.killmessages:outputMessage(getPlayerName(plr).." is now off-duty staff!", root, 0, 255, 0) 
                    setElementData(plr, "isPlayerStaff", false) 
                    dbExec(adminDB, "DELETE FROM adminSaver WHERE acc=?", getAccountName(getPlayerAccount(plr))) 
                end 
            end 
        end 
    ) 
      
  

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