· 8 years ago · Aug 02, 2018, 08:14 PM
1local con = dbConnect("sqlite", ":/registry.db")
2dbExec(con, "CREATE TABLE IF NOT EXISTS goLawAccess ('accountName', 'access')")
3dbExec(con, "CREATE INDEX IF NOT EXISTS idx_goLawAccess_accountName ON goLawAccess(accountName)")
4
5local authorized = {["AFODusty"] = true,
6["Kreature"] = true,
7["JosefMTD"] = true,
8["Gonzalomanya"] = true,
9["bossnico"] = true
10}
11
12local validAccess = {["AF"] = true,
13["SWAT"] = true,
14["FBI"] = true,
15["SAPD"] = true
16}
17
18function addGoLaw(player, commandName, accountName, access)
19 if ((authorized[getAccountName(getPlayerAccount(player))] or exports.CITadmin:getPlayerAdminLevel(player) == 5) and (accountName and getAccount(accountName)) and validAccess[access]) then
20 dbQuery(addGoLaw2, {player, access, accountName}, con, "SELECT accountName FROM goLawAccess WHERE accountName = ?", accountName)
21 else
22 outputChatBox("Unsuccessful: invalid arguments", player)
23 end
24end
25addCommandHandler("addgolaw", addGoLaw)
26
27function addGoLaw2(query, player, access, accountName)
28 local result = dbPoll(query, 0)[1]
29 if (not result and isElement(player)) then
30 dbExec(con, "INSERT INTO goLawAccess VALUES (?, ?)", accountName, access)
31 outputChatBox("Succesful", player)
32 else
33 outputChatBox("Unsuccesful: player already added", player)
34 end
35end
36
37function removeGoLaw(player, commandName, accountName)
38 if (authorized[getAccountName(getPlayerAccount(player))] and accountName) then
39 dbExec(con, "DELETE FROM goLawAccess WHERE accountName = ?", accountName)
40 end
41end
42addCommandHandler("removegolaw", removeGoLaw)
43
44function goLaw(player)
45 if (getPlayerWantedLevel(player) == 0) then
46 dbQuery(goLaw2, {player}, con, "SELECT access FROM goLawAccess WHERE accountName = ?", getAccountName(getPlayerAccount(player)))
47 else
48 outputChatBox("You cannot use this command when wanted", player)
49 end
50end
51addCommandHandler("golaw", goLaw)
52
53function goLaw2(query, player)
54 local result = dbPoll(query, 0)[1]
55 if (result and isElement(player)) then
56 if (result['access'] == "AF") then
57 exports.CITbusiness:setPlayerJob(player, "Armed Forces")
58 elseif (result['access'] == "SWAT") then
59 exports.CITbusiness:setPlayerJob(player, "SWAT Team")
60 elseif (result['access'] == "FBI") then
61 exports.CITbusiness:setPlayerJob(player, "Federal Agent")
62 elseif (result['access'] == "SAPD") then
63 exports.CITbusiness:setPlayerJob(player, "SAPD Officer")
64 end
65 end
66end