RyanUSNS

ServerSide

Nov 23rd, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.67 KB | None | 0 0
  1. local drugDB = dbConnect("sqlite", "drugP.db") --dbConnect("mysql", "dbname=HERE;host=HERE;", "username", "password")
  2. local dLabs, fDrug, cd, dMarker, dProduced = {}, {}, {}, {}, {}
  3. local dWait = 24*60*60*1000 -- 1 Day
  4. local dCost = 100000 --$100,000
  5. local checkTimer = 3000
  6. local recipeReq = 3
  7. local drugAmounts = {["Crack"] = 180, ["Speed"] = 180, ["God"] = 240, ["Steroids"] = 200, ["LSD"] = 200, ["Weed"] = 240}
  8.  
  9. function createDrug(drug)
  10.     local accPlr = getPlayerAccount(client)
  11.     local acc = getAccountName(accPlr)
  12.     local recipes = tonumber(exports.CITaccounts:invGet(acc, "recipes"))
  13.     local x, y, z = getElementPosition(client)
  14.     if (getDistanceBetweenPoints3D(1628, -1471, 22, x, y, z) > 1500) then
  15.         outputChatBox("ERROR: You are too far away from Los Santos", client, 200, 0, 0)
  16.         return false
  17.     end
  18.     if (not exports.CITchecking:playerActionCheck(plr, {{"w", 0}, {"i", 0}, {"d", 0}, {"fn", "Place Hit"}, {"s", "noveh", "noarrest", "nojailed", "nodead", "nobc", "nofreeze", "noair", "nowater", "noguest", "nosexact", "nojetpack", "nosmoke", "nodrink", "noglued", "nohit", "nouav", "nohitarea"}})) then
  19.         return false
  20.     end]
  21.     if (getTeamFromName("Criminals") ~= getPlayerTeam(client)) then
  22.         outputChatBox("ERROR: Invalid team. You should be criminal!", client, 200, 0, 0)
  23.         return false
  24.     end
  25.     if (not recipes or recipes <= recipeReq or getPlayerMoney(client) <= dCost) then
  26.         outputChatBox("Making a drug lab costs $"..dCost.." and "..recipeReq.." recipes. Use '/recipes' for provide more informations!", client, 200, 0, 0)
  27.         return false
  28.     end
  29.     local tick = getTickCount()
  30.     local serial = getAccountSerial(accPlr)
  31.     if (cd[serial] and tick - cd[serial] < dWait) then
  32.         local timepassed = tick - cd[serial]
  33.         local seconds = math.ceil(timepassed / 1000)
  34.         local minutes = math.ceil(seconds / 60)
  35.         local hours = math.ceil(minutes / 60)
  36.         outputChatBox("Time Passed: "..hours.." hour(s), "..minutes.." minute(s) and "..seconds.." seconds.", client, 200, 0, 0)
  37.         return false
  38.     end
  39.     if (not dProduced[acc]) then
  40.         dProduced[acc] = {}
  41.     end
  42.     if (dProduced[acc][1] == drug or dProduced[acc][2] == drug or dProduced[acc][3] == drug) then
  43.         outputChatBox("ERROR: Need choose other type of drug. Your last 3 types of drugs, that you made matched with you requested.", client, 200, 0, 0)
  44.         return false
  45.     end
  46.     local marker = createMarker(x, y, z - 1, "cylinder", 5, 0, 100, 255, 0)
  47.     local object = createObject(1457, x, y, z)
  48.     dMarker[marker] = {client, drug}
  49.     dLabs[client] = {object, x, y, z, drug, marker}
  50.     triggerClientEvent(client, "CITdrugLab.addProgressBar", client)
  51.     cd[serial] = getTickCount()
  52.     setPlayerNametagShowing(client, false)
  53.     setElementData(client, "a", "DrugLab")
  54.     outputChatBox("You started to make "..drugAmounts[drug].." hits of "..drug, client, 0, 255, 0)
  55.     exports.CITmoney:TPM(client, dCost, "drug lab cost")
  56.     exports.CITaccounts:invSet(acc, "recipes", recipes - 3)
  57.     table.insert(dProduced[acc], drug)
  58.     dbExec(drugDB, "INSERT INTO `drugProduced` (`accname`, `drug`) VALUES(?, ?)", acc, drug)
  59.     limitDrug(acc)
  60.     addEventHandler("onMarkerHit", marker, giveDrugsToEnemy)
  61. end
  62. addEvent("CITdrugLab.createDrug", true)
  63. addEventHandler("CITdrugLab.createDrug", root, createDrug)
  64.  
  65. function giveDrugToCreator(drug)
  66.     if (not drug) then
  67.         return false
  68.     end
  69.     for i, plr in pairs(getPlayersInTeam(getTeamFromName("Police Service"))) do
  70.         fDrug[plr] = false
  71.         local x, y, z = getElementPosition(plr)
  72.         if (getDistanceBetweenPoints2D(dLabs[client][2], dLabs[client][3], x, y) <= 400 and not fDrug[plr] and getElementData(plr, "B") == "Detector") then
  73.             outputChatBox("You were too slow. Someone already did this drug!", plr, 200, 0, 0)
  74.         end
  75.     end
  76.     local x, y, z = getElementPosition(client)
  77.     if (getDistanceBetweenPoints2D(dLabs[client][2], dLabs[client][3], x, y) > 4) then
  78.         outputChatBox("Due some mismatch in relation about your last postion, we killed you. Do not try abuse it!", client, 0, 255, 0)
  79.         killPed(client)
  80.         removeDrugLab(client)
  81.         return true
  82.     end
  83.     exports.CIThelp:dm("You did "..drugAmounts[drug].." hits of "..drug, client, 0, 255, 0)
  84.     exports.CITdrug:giveDrug(plr, drug, drugAmounts[drug])
  85.     exports.CITlogs:logSomething(getPlayerName(client).." did "..drugAmounts[drug].." hits of "..drug, "drugsLab", client)
  86.     killLab(client)
  87. end
  88. addEvent("CITdrugLab.finishDrug", true)
  89. addEventHandler("CITdrugLab.finishDrug", resourceRoot, giveDrugToCreator)
  90.  
  91. function giveDrugsToEnemy(plr, mdim)
  92.     if (getElementType(plr) ~= "player" or not mdim or isPedInVehicle(plr) or getTeamFromName("Police Service") ~= getPlayerTeam(plr) or not dMarker[source] or getElementData(plr, "B") ~= "Detector") then
  93.         return false
  94.     end
  95.     local crim, drug = dMarker[source][1], dMarker[source][2]
  96.     if (crim == plr or not source or getElementData("g", plr) == getElementData("g", crim)) then
  97.         return false
  98.     end
  99.     local aDrug = math.ceil(drugAmounts[drug] / 10)
  100.     --Police
  101.     outputChatBox("You have destroyed a drug lab and got "..aDrug.. " hits of "..drug, plr, 0, 255, 0)
  102.     exports.CITdrug:giveDrug(plr, drug, aDrug)
  103.     exports.CIThelp:modTextBar(plr, "findDrugs", "")
  104.     exports.CITlogs:logSomething(getPlayerName(plr).." destroyed a drug lab belonging to "..getPlayerName(crim).. " and made "..aDrug.." of "..drug, "drugsLab", plr)
  105.     --Criminal
  106.     outputChatBox(getPlayerName(plr).. " has destroyed your drug lab", crim, 200, 0, 0)
  107.     exports.CITpoliceDatabase:recordCrime(crim, 8)
  108.     destroyElement(source)
  109.     dMarker[source] = nil
  110.     triggerClientEvent(crim, "CITdrugLab.killProgressBar", crim)
  111.     killLab(crim)
  112. end
  113.  
  114. function killLab(plr)
  115.     if (not plr) then
  116.         plr = client
  117.     end
  118.     if (dLabs[plr]) then
  119.         if (isElement(dLabs[plr][1])) then
  120.             destroyElement(dLabs[plr][1])
  121.         end
  122.         if (isElement(dLabs[plr][6])) then
  123.             destroyElement(dLabs[plr][6])
  124.         end
  125.         dLabs[plr] = nil
  126.         setElementData(plr, "a", "None")
  127.         setPlayerNametagShowing(plr, true)
  128.     end
  129.     if (fDrug[plr]) then
  130.         fDrug[plr] = nil
  131.     end
  132. end
  133. addEvent("CITdrugLab.killLab", true)
  134. addEventHandler("CITdrugLab.killLab", resourceRoot, killLab)
  135.  
  136. function finddLabs()
  137.     for i, plr in pairs(getPlayersInTeam(getTeamFromName("Police Service"))) do
  138.         fDrug[plr] = 0
  139.         if (next(dLabs)) then
  140.             local x, y, z = getElementPosition(plr)
  141.             for index, labs in pairs(dLabs) do
  142.                 if (getDistanceBetweenPoints2D(labs[2], labs[3], x, y) <= 200) then
  143.                     fDrug[plr] = fDrug[plr] + 1
  144.                 end
  145.             end
  146.             if (fDrug[plr] ~= 0) then
  147.                 exports.CIThelp:modTextBar(plr, "findDrugs", "You detected one drug: "..fDrug[plr], 0, 255, 0)
  148.             else
  149.                 exports.CIThelp:modTextBar(plr, "findDrugs", "")
  150.             end
  151.         else
  152.             exports.CIThelp:modTextBar(plr, "findDrugs", "")
  153.         end
  154.     end
  155. end
  156. setTimer(finddLabs, checkTimer, 0)
  157.  
  158. function remDrugByQuitted()
  159.     if (dLabs[source]) then
  160.         local crim, drug = dLabs[source][1], dLabs[source][2]
  161.         exports.CITpoliceDatabase:recordCrime(source, 8)
  162.         local x, y, z = getElementPosition(source)
  163.         for index, plr in pairs(getElementsByType("player")) do
  164.             local px, py, pz = getElementPosition(plr)
  165.             if (fDrug[plr]) then
  166.                 if (getDistanceBetweenPoints2D(x, y, px, py) <= 50) then
  167.                     local aDrug = math.ceil(drugAmounts[drug] / 10)
  168.                     exports.CITlogs:logSomething(getPlayerName(plr).. "got "..aDrug.." hits of "..drug.." because "..getPlayerName(source).." left the game", "drugsLab", plr)
  169.                     exports.CITdrug:givePlayerDrug(plr, drug, aDrug)
  170.                     outputChatBox("You got "..aDrug.." hits of "..drug.." because "..getPlayerName(source).." left the game", plr, 0, 255, 0)
  171.                     break
  172.                 end
  173.             end
  174.         end
  175.     end
  176.     killLab(source)
  177. end
  178.  
  179. function limitDrug(acc)
  180.     if (#dProduced[acc] <= 3) then
  181.         return false
  182.     end
  183.     local torun = #dProduced[acc] - 3
  184.     local n = 1
  185.     for n = 1, torun do
  186.         dbExec(drugDB, "DELETE FROM `drugProduced` WHERE `accname` = ? AND `drug` = ?", acc, dProduced[acc][n])
  187.         dProduced[acc][n] = nil
  188.         n = n + 1
  189.     end
  190. end
  191.  
  192. --Commands
  193. function checkRecipes(plr)
  194.     local serial = getPlayerSerial(plr)
  195.     local accPlr = getPlayerAccount(plr)
  196.     local recipes = tonumber(exports.CITaccounts:invGet(acc, "recipes"))
  197.     if (not recipes) then
  198.         outputChatBox("Currently you do not have any recipes fragment.", plr, 200, 0, 0)
  199.         return false
  200.     end
  201.     local tick = getTickCount()
  202.     if (cd[serial] and tick - cd[serial] < dWait) then
  203.         local timepassed = tick - cd[serial]
  204.         local seconds = math.ceil(timepassed / 1000)
  205.         local minutes = math.ceil(seconds / 60)
  206.         local hours = math.ceil(minutes / 60)
  207.         outputChatBox("Time passed:"..hours.." hour(s), "..minutes.." minute(s) and "..seconds.." seconds; Currently fragment recipes: "..recipes, plr, 200, 0, 0)
  208.         return false
  209.     end
  210.     outputChatBox("Currently you have "..recipes.." fragments of recipes.", plr, 0, 255, 0)
  211. end
  212. addCommandHandler("recipes", checkRecipes)
  213.  
  214. --[[function hackRecipes(plr, cmd, number) --Special command for test.
  215.     if (not tonumber(number)) then
  216.         number = 10
  217.     end
  218.     local acc = getPlayerAccount(plr)
  219.     setAccountData(acc, "recipes", number)
  220.     outputChatBox("Added "..number.." fragment of recipes.", plr, 0, 255, 0)
  221. end
  222. addCommandHandler("hackrecipe", hackRecipes)]]--
  223.  
  224. function resourceSOStarts()
  225.     dbExec(drugDB, [[CREATE TABLE IF NOT EXISTS `drugProduced` (
  226.                     `accname` VARCHAR(32) NULL,
  227.                     `drug` VARCHAR(10) NULL)]])
  228.     dbQuery(resourceSOQuery, drugDB, "SELECT * FROM drugProduced")
  229. end
  230. addEventHandler("onResourceStart", resourceRoot, resourceSOStarts)
  231.  
  232. function resourceSOQuery(qh)
  233.     local data = dbPoll(qh, 0)
  234.     if (not data or #data < 0) then
  235.         return false
  236.     end
  237.     dProduced = {}
  238.     for k, v in pairs(data) do
  239.         if (not dProduced[v.accname]) then
  240.             dProduced[v.accname] = {}
  241.         end
  242.         table.insert(dProduced[v.accname], v.drug)
  243.     end
  244. end
Add Comment
Please, Sign In to add comment