Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local drugDB = dbConnect("sqlite", "drugP.db") --dbConnect("mysql", "dbname=HERE;host=HERE;", "username", "password")
- local dLabs, fDrug, cd, dMarker, dProduced = {}, {}, {}, {}, {}
- local dWait = 24*60*60*1000 -- 1 Day
- local dCost = 100000 --$100,000
- local checkTimer = 3000
- local recipeReq = 3
- local drugAmounts = {["Crack"] = 180, ["Speed"] = 180, ["God"] = 240, ["Steroids"] = 200, ["LSD"] = 200, ["Weed"] = 240}
- function createDrug(drug)
- local accPlr = getPlayerAccount(client)
- local acc = getAccountName(accPlr)
- local recipes = tonumber(exports.CITaccounts:invGet(acc, "recipes"))
- local x, y, z = getElementPosition(client)
- if (getDistanceBetweenPoints3D(1628, -1471, 22, x, y, z) > 1500) then
- outputChatBox("ERROR: You are too far away from Los Santos", client, 200, 0, 0)
- return false
- end
- 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
- return false
- end]
- if (getTeamFromName("Criminals") ~= getPlayerTeam(client)) then
- outputChatBox("ERROR: Invalid team. You should be criminal!", client, 200, 0, 0)
- return false
- end
- if (not recipes or recipes <= recipeReq or getPlayerMoney(client) <= dCost) then
- outputChatBox("Making a drug lab costs $"..dCost.." and "..recipeReq.." recipes. Use '/recipes' for provide more informations!", client, 200, 0, 0)
- return false
- end
- local tick = getTickCount()
- local serial = getAccountSerial(accPlr)
- if (cd[serial] and tick - cd[serial] < dWait) then
- local timepassed = tick - cd[serial]
- local seconds = math.ceil(timepassed / 1000)
- local minutes = math.ceil(seconds / 60)
- local hours = math.ceil(minutes / 60)
- outputChatBox("Time Passed: "..hours.." hour(s), "..minutes.." minute(s) and "..seconds.." seconds.", client, 200, 0, 0)
- return false
- end
- if (not dProduced[acc]) then
- dProduced[acc] = {}
- end
- if (dProduced[acc][1] == drug or dProduced[acc][2] == drug or dProduced[acc][3] == drug) then
- 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)
- return false
- end
- local marker = createMarker(x, y, z - 1, "cylinder", 5, 0, 100, 255, 0)
- local object = createObject(1457, x, y, z)
- dMarker[marker] = {client, drug}
- dLabs[client] = {object, x, y, z, drug, marker}
- triggerClientEvent(client, "CITdrugLab.addProgressBar", client)
- cd[serial] = getTickCount()
- setPlayerNametagShowing(client, false)
- setElementData(client, "a", "DrugLab")
- outputChatBox("You started to make "..drugAmounts[drug].." hits of "..drug, client, 0, 255, 0)
- exports.CITmoney:TPM(client, dCost, "drug lab cost")
- exports.CITaccounts:invSet(acc, "recipes", recipes - 3)
- table.insert(dProduced[acc], drug)
- dbExec(drugDB, "INSERT INTO `drugProduced` (`accname`, `drug`) VALUES(?, ?)", acc, drug)
- limitDrug(acc)
- addEventHandler("onMarkerHit", marker, giveDrugsToEnemy)
- end
- addEvent("CITdrugLab.createDrug", true)
- addEventHandler("CITdrugLab.createDrug", root, createDrug)
- function giveDrugToCreator(drug)
- if (not drug) then
- return false
- end
- for i, plr in pairs(getPlayersInTeam(getTeamFromName("Police Service"))) do
- fDrug[plr] = false
- local x, y, z = getElementPosition(plr)
- if (getDistanceBetweenPoints2D(dLabs[client][2], dLabs[client][3], x, y) <= 400 and not fDrug[plr] and getElementData(plr, "B") == "Detector") then
- outputChatBox("You were too slow. Someone already did this drug!", plr, 200, 0, 0)
- end
- end
- local x, y, z = getElementPosition(client)
- if (getDistanceBetweenPoints2D(dLabs[client][2], dLabs[client][3], x, y) > 4) then
- outputChatBox("Due some mismatch in relation about your last postion, we killed you. Do not try abuse it!", client, 0, 255, 0)
- killPed(client)
- removeDrugLab(client)
- return true
- end
- exports.CIThelp:dm("You did "..drugAmounts[drug].." hits of "..drug, client, 0, 255, 0)
- exports.CITdrug:giveDrug(plr, drug, drugAmounts[drug])
- exports.CITlogs:logSomething(getPlayerName(client).." did "..drugAmounts[drug].." hits of "..drug, "drugsLab", client)
- killLab(client)
- end
- addEvent("CITdrugLab.finishDrug", true)
- addEventHandler("CITdrugLab.finishDrug", resourceRoot, giveDrugToCreator)
- function giveDrugsToEnemy(plr, mdim)
- 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
- return false
- end
- local crim, drug = dMarker[source][1], dMarker[source][2]
- if (crim == plr or not source or getElementData("g", plr) == getElementData("g", crim)) then
- return false
- end
- local aDrug = math.ceil(drugAmounts[drug] / 10)
- --Police
- outputChatBox("You have destroyed a drug lab and got "..aDrug.. " hits of "..drug, plr, 0, 255, 0)
- exports.CITdrug:giveDrug(plr, drug, aDrug)
- exports.CIThelp:modTextBar(plr, "findDrugs", "")
- exports.CITlogs:logSomething(getPlayerName(plr).." destroyed a drug lab belonging to "..getPlayerName(crim).. " and made "..aDrug.." of "..drug, "drugsLab", plr)
- --Criminal
- outputChatBox(getPlayerName(plr).. " has destroyed your drug lab", crim, 200, 0, 0)
- exports.CITpoliceDatabase:recordCrime(crim, 8)
- destroyElement(source)
- dMarker[source] = nil
- triggerClientEvent(crim, "CITdrugLab.killProgressBar", crim)
- killLab(crim)
- end
- function killLab(plr)
- if (not plr) then
- plr = client
- end
- if (dLabs[plr]) then
- if (isElement(dLabs[plr][1])) then
- destroyElement(dLabs[plr][1])
- end
- if (isElement(dLabs[plr][6])) then
- destroyElement(dLabs[plr][6])
- end
- dLabs[plr] = nil
- setElementData(plr, "a", "None")
- setPlayerNametagShowing(plr, true)
- end
- if (fDrug[plr]) then
- fDrug[plr] = nil
- end
- end
- addEvent("CITdrugLab.killLab", true)
- addEventHandler("CITdrugLab.killLab", resourceRoot, killLab)
- function finddLabs()
- for i, plr in pairs(getPlayersInTeam(getTeamFromName("Police Service"))) do
- fDrug[plr] = 0
- if (next(dLabs)) then
- local x, y, z = getElementPosition(plr)
- for index, labs in pairs(dLabs) do
- if (getDistanceBetweenPoints2D(labs[2], labs[3], x, y) <= 200) then
- fDrug[plr] = fDrug[plr] + 1
- end
- end
- if (fDrug[plr] ~= 0) then
- exports.CIThelp:modTextBar(plr, "findDrugs", "You detected one drug: "..fDrug[plr], 0, 255, 0)
- else
- exports.CIThelp:modTextBar(plr, "findDrugs", "")
- end
- else
- exports.CIThelp:modTextBar(plr, "findDrugs", "")
- end
- end
- end
- setTimer(finddLabs, checkTimer, 0)
- function remDrugByQuitted()
- if (dLabs[source]) then
- local crim, drug = dLabs[source][1], dLabs[source][2]
- exports.CITpoliceDatabase:recordCrime(source, 8)
- local x, y, z = getElementPosition(source)
- for index, plr in pairs(getElementsByType("player")) do
- local px, py, pz = getElementPosition(plr)
- if (fDrug[plr]) then
- if (getDistanceBetweenPoints2D(x, y, px, py) <= 50) then
- local aDrug = math.ceil(drugAmounts[drug] / 10)
- exports.CITlogs:logSomething(getPlayerName(plr).. "got "..aDrug.." hits of "..drug.." because "..getPlayerName(source).." left the game", "drugsLab", plr)
- exports.CITdrug:givePlayerDrug(plr, drug, aDrug)
- outputChatBox("You got "..aDrug.." hits of "..drug.." because "..getPlayerName(source).." left the game", plr, 0, 255, 0)
- break
- end
- end
- end
- end
- killLab(source)
- end
- function limitDrug(acc)
- if (#dProduced[acc] <= 3) then
- return false
- end
- local torun = #dProduced[acc] - 3
- local n = 1
- for n = 1, torun do
- dbExec(drugDB, "DELETE FROM `drugProduced` WHERE `accname` = ? AND `drug` = ?", acc, dProduced[acc][n])
- dProduced[acc][n] = nil
- n = n + 1
- end
- end
- --Commands
- function checkRecipes(plr)
- local serial = getPlayerSerial(plr)
- local accPlr = getPlayerAccount(plr)
- local recipes = tonumber(exports.CITaccounts:invGet(acc, "recipes"))
- if (not recipes) then
- outputChatBox("Currently you do not have any recipes fragment.", plr, 200, 0, 0)
- return false
- end
- local tick = getTickCount()
- if (cd[serial] and tick - cd[serial] < dWait) then
- local timepassed = tick - cd[serial]
- local seconds = math.ceil(timepassed / 1000)
- local minutes = math.ceil(seconds / 60)
- local hours = math.ceil(minutes / 60)
- outputChatBox("Time passed:"..hours.." hour(s), "..minutes.." minute(s) and "..seconds.." seconds; Currently fragment recipes: "..recipes, plr, 200, 0, 0)
- return false
- end
- outputChatBox("Currently you have "..recipes.." fragments of recipes.", plr, 0, 255, 0)
- end
- addCommandHandler("recipes", checkRecipes)
- --[[function hackRecipes(plr, cmd, number) --Special command for test.
- if (not tonumber(number)) then
- number = 10
- end
- local acc = getPlayerAccount(plr)
- setAccountData(acc, "recipes", number)
- outputChatBox("Added "..number.." fragment of recipes.", plr, 0, 255, 0)
- end
- addCommandHandler("hackrecipe", hackRecipes)]]--
- function resourceSOStarts()
- dbExec(drugDB, [[CREATE TABLE IF NOT EXISTS `drugProduced` (
- `accname` VARCHAR(32) NULL,
- `drug` VARCHAR(10) NULL)]])
- dbQuery(resourceSOQuery, drugDB, "SELECT * FROM drugProduced")
- end
- addEventHandler("onResourceStart", resourceRoot, resourceSOStarts)
- function resourceSOQuery(qh)
- local data = dbPoll(qh, 0)
- if (not data or #data < 0) then
- return false
- end
- dProduced = {}
- for k, v in pairs(data) do
- if (not dProduced[v.accname]) then
- dProduced[v.accname] = {}
- end
- table.insert(dProduced[v.accname], v.drug)
- end
- end
Add Comment
Please, Sign In to add comment