Jump to content

SQLite Problem


Recommended Posts

So, I made this script and I'm not sure if it works or not as this is my first time with SQLite.

addEventHandler("onResourceStart", resourceRoot, 
function() 
exports.scoreboard:addScoreboardColumn("VIP", 3) 
executeSQLCreateTable("VIP", "account TEXT") 
end 
) 
  
addCommandHandler("addVIP", 
function(player, cmd, account) 
if (getElementData(player, "thePlayerStaffLevel") == 5) then 
local targetaccount = getAccountName(account) 
executeSQLInsert("VIP", targetaccount) 
exports.DxChat:sayServerMessage(player, "You have succefully added "..account.." as VIP", 0, 255, 0) 
else 
exports.DxChat:sayServerMessage(player, "You don't have sufficient rights", 0, 255, 0) 
end 
end 
) 
  
addCommandHandler("delVIP", 
function(player, cmd, account) 
if (getElementData(player, "thePlayerStaffLevel") == 5) then 
local targetaccount = getAccountName(account) 
executeSQLDelete("VIP", targetaccount) 
exports.DxChat:sayServerMessage(player, "You have succefully deleted "..account.." and he is no longer a VIP", 0, 255, 0) 
else 
exports.DxChat:sayServerMessage(player, "You don't have sufficient rights", 0, 255, 0) 
end 
end 
) 
  
addEventHandler("onPlayerLogin", root, 
function() 
local result = executeSQLSelect( "VIP", "account") 
if (type(result) == "table" and #result == 1) then 
local thePlayer = getAccountPlayer(result) 
setElementData(thePlayer, "VIP", "Yes") 
else 
setElementData(thePlayer, "VIP", "No") 
end 
end 
) 

P.S:Before saying "why don't you test it yourself?" I don't have MTA, thanks.

Link to comment

No, that won't work, because of the following problems:

1: You are trying to get an account name from a string, not an account element.

2: Your SQL functions are all wrongly used.

addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        exports.scoreboard:addScoreboardColumn ( "VIP", 3 ) 
        executeSQLCreateTable ( "VIP", "account TEXT" ) 
    end 
) 
  
addCommandHandler ( "addVIP", 
    function ( player, cmd, account ) 
        if ( getElementData ( player, "thePlayerStaffLevel" ) == 5 ) then 
            executeSQLInsert ( "VIP", "'".. account .."'" ) 
            exports.DxChat:sayServerMessage ( player, "You have succefully added ".. account .." as VIP", 0, 255, 0 ) 
        else 
            exports.DxChat:sayServerMessage ( player, "You don't have sufficient rights", 0, 255, 0 ) 
        end 
    end 
) 
  
addCommandHandler ( "delVIP", 
    function ( player, cmd, account ) 
        if ( getElementData ( player, "thePlayerStaffLevel" ) == 5 ) then 
            executeSQLDelete ( "VIP", "account = '".. account .."'" ) 
            exports.DxChat:sayServerMessage ( player, "You have succefully deleted ".. account .." and he is no longer a VIP", 0, 255, 0 ) 
        else 
            exports.DxChat:sayServerMessage ( player, "You don't have sufficient rights", 0, 255, 0 ) 
        end 
    end 
) 
  
addEventHandler ( "onPlayerLogin", root, 
    function ( _, account ) 
        local result = executeSQLSelect ( "VIP", "account", "account = '".. getAccountName ( account ) .."'" ) 
        if ( type ( result ) == "table" and #result == 1 ) then 
            setElementData ( source, "VIP", "Yes" ) 
        else 
            setElementData ( source, "VIP", "No" ) 
        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...