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