RyanUSNS

IllegalTruck v2 - Server Side

Jan 29th, 2018
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.61 KB | None | 0 0
  1. ------------------------------------------------------------------------------------
  2. --  COMMUNITY CONTRIBUTION FOR CIT2.NET
  3. --  PURPOSE:    Illegal Trucker version 2.0 - Server Side
  4. --  DEVELOPERS: Ryan#USNS (IRC: Ryan1)
  5. ------------------------------------------------------------------------------------
  6. local t = function(...) return exports.CITt:t(...) or arg[2] end
  7. local trailers, illegalStart, caughtCrim, missionsAble, copSearching, missionPlayer, vehInfo, trailBlip = {}, {}, {}, {}, {}, {}, {}, {}
  8. local trucksAllowed = {[403]=true, [515]=true, [514]=true}
  9. local crimTeam = {["Criminal"] = true, ["Gangster"] = true}
  10. local illegalMissions = {
  11.     {"Stolen woods", 1, "currency",
  12.         {
  13.             {-1671.9651, -2238.5376, 34.6840, 2509.6804, -2397.6389, 13.4531},
  14.             {-510.5513, -184.0313, 77.5739, 2509.6804, -2397.6389, 13.4531},
  15.             {1431.6707, 53.5757, 31.0861, 2509.6804, -2397.6389, 13.4531},
  16.             {-602.7764, -2379.2439, 27.4724, 2509.6804, -2397.6389, 13.4531},
  17.             {-1728.1807, -1004.1956, 75.3903, 2509.6804, -2397.6389, 13.4531},
  18.         },
  19.     },
  20.     {"Stolen military weapons", 3, "explosive",
  21.         {
  22.             {-67.1604, 1849.6941, 17.2266, 1338.4467, 333.1886, 19.6567},
  23.             {-67.1604, 1849.6941, 17.2266, 2736.7161, -1999.3199, 13.3314},
  24.             {-67.1604, 1849.6941, 17.2266, 65.2693, -273.1205, 1.5781},
  25.             {-67.1604, 1849.6941, 17.2266, -494.6841, -526.1557, 25.5178},
  26.         },
  27.     },
  28.     {"Stolen weed", 3, "drug",
  29.         {
  30.             {-1084.0078, -1647.5510, 76.3672, 869.2811, -33.9733, 63.1953},
  31.             {-1049.5341, -1260.6897, 128.3069, 869.2811, -33.9733, 63.1953},
  32.             {-104.4346, -131.0314, 3.1172, 869.2811, -33.9733, 63.1953},
  33.             {-377.4979, -1425.2390, 25.7266, 869.2811, -33.9733, 63.1953},
  34.             {-1398.3806, -1473.2067, 101.7125, 869.2811, -33.9733, 63.1953},
  35.             {-3273.8613, 881.2361, 3.0082, 869.2811, -33.9733, 63.1953}, --City Island
  36.         },
  37.     },
  38.     {"Stolen resource market", 1, "drug",
  39.         {
  40.             {987.6440, -927.7278, 42.1797, 2476.3892, -2432.6646, 13.6250},
  41.             {1475.9570, -1130.9758, 24.0781, 2476.3892, -2432.6646, 13.6250},
  42.             {1815.0590, -1841.7106, 13.5781, 2476.3892, -2432.6646, 13.6250},
  43.             {507.1934, -1362.7794, 16.1252, 2476.3892, -2432.6646, 13.6250},
  44.         },
  45.     },
  46.     {"Stolen special cars", 1, "currency",
  47.         {
  48.             {2123.0535, -1116.6073, 25.3297, 2476.3892, -2432.6646, 13.6250},
  49.             {523.8887, -1273.7391, 16.0930, 2476.3892, -2432.6646, 13.6250},
  50.             {-1631.6243, 1202.3541, 7.1797, 2476.3892, -2432.6646, 13.6250},
  51.             {-2110.8545, -2253.4629, 30.4688, 2476.3892, -2432.6646, 13.6250},
  52.             {1261.0795, 171.6992, 19.5692, 2476.3892, -2432.6646, 13.6250},
  53.             {-3298.0298, 620.1749, 2.9982, 2476.3892, -2432.6646, 13.6250}, --City Island
  54.         },
  55.     },
  56.     {"Illegal immigrants", 1, "currency",
  57.         {
  58.             {834.0153, -2045.3047, 12.8672, 2604.9885, -953.1558, 80.6604},
  59.             {834.0153, -2045.3047, 12.8672, 771.5433, 310.2221, 20.6317},
  60.             {834.0153, -2045.3047, 12.8672, 348.2115, 90.5939, 4.3677},
  61.             {834.0153, -2045.3047, 12.8672, 1464.0338, 382.6462, 19.4622},
  62.             {834.0153, -2045.3047, 12.8672, -76.0696, 983.9888, 19.7815},
  63.         },
  64.     },
  65.     {"Drug Trafficking", 2, "drug",
  66.         {
  67.             {2506.0276, -1274.3027, 34.8569, 2460.5017, -1937.3405, 13.5391},
  68.             {2506.0276, -1274.3027, 34.8569, 692.2917, -1169.7361, 15.4038},
  69.             {2506.0276, -1274.3027, 34.8569, 2273.5767, 86.4542, 26.4844},
  70.         },
  71.     },
  72.     {"Money Trafficking", 3, "currency",
  73.         {
  74.             {-14.6364, -285.3926, 5.4297, 1509.5836, -1155.6906, 24.0781},
  75.             {-14.6364, -285.3926, 5.4297, 2329.5215, -23.3170, 26.3346},
  76.             {-14.6364, -285.3926, 5.4297, -1873.0447, 723.7877, 45.4453},
  77.         },
  78.     },
  79.     {"Stolen radioactive materials", 3, "explosive",
  80.         {
  81.             {-1821.5568, 3.2573, 15.1172, 1335.5579, 333.5837, 19.5547},
  82.             {2460.8257, -2089.0498, 13.5469, 1335.5579, 333.5837, 19.5547},
  83.         },
  84.     },
  85.     {"Stolen Precious material", 3, "explosive",
  86.         {
  87.             {-337.6020, 1193.7675, 19.7422 , 1335.5579, 333.5837, 19.5547},
  88.             {-2372.1145, -2172.9739, 33.4450, 1335.5579, 333.5837, 19.5547},
  89.             {832.4146, 853.0563, 12.2773, 1335.5579, 333.5837, 19.5547},
  90.         },
  91.     },
  92.     {"Animals Trafficking", 2, "currency",
  93.         {
  94.             {-1084.0078, -1647.5510, 76.3672, 2681.6831, -2532.0396, 13.3757},
  95.             {-1049.5341, -1260.6897, 128.3069, 2681.6831, -2532.0396, 13.3757},
  96.             {-104.4346, -131.0314, 3.1172, 2681.6831, -2532.0396, 13.3757},
  97.             {-377.4979, -1425.2390, 25.7266, 2681.6831, -2532.0396, 13.3757},
  98.             {-1398.3806, -1473.2067, 101.7125, 2681.6831, -2532.0396, 13.3757},
  99.             {-3273.8613, 881.2361, 3.0082, 2681.6831, -2532.0396, 13.3757}, --City Island
  100.         },
  101.     },
  102.     {"Weapon Trafficking", 2, "explosive",
  103.         {
  104.             {-2440.3691, 490.4811, 30.0861, 1363.4043, -1313.7269, 13.5469},
  105.             {-2440.3691, 490.4811, 30.0861, 2392.6135, -1977.6481, 13.5469},
  106.             {-2440.3691, 490.4811, 30.0861, 2338.6655, 53.7166, 26.4844},
  107.             {-2440.3691, 490.4811, 30.0861, 246.2604, -194.5964, 1.5781},
  108.         },
  109.     },
  110.     {"Human trafficking", 2, "currency",
  111.         {
  112.             {834.0153, -2045.3047, 12.8672, 867.9329, -33.3535, 63.1953},
  113.             {834.0153, -2045.3047, 12.8672, -1668.4901, -2238.7463, 34.3476},
  114.             {834.0153, -2045.3047, 12.8672, -2778.6094, -1539.8674, 139.9183},
  115.         },
  116.     },
  117.     {"Transportation of escaped prisoners", 2, "currency",
  118.         {
  119.             {1904.0194, -1530.7120, 3.3538, 834.0153, -2045.3047, 12.8672},
  120.             {1904.0194, -1530.7120, 3.3538, 2597.1680, -2445.1038, 13.6252},
  121.             {1904.0194, -1530.7120, 3.3538, 2857.2747, -272.7637, 9.2056},
  122.         },
  123.     },
  124.     {"Felony Aiding Illegal Aliens", 2, "currency",
  125.         {
  126.             {-1618.2531, 1777.9023, 10.3289, 2740.5879, -1999.2815, 13.3157},
  127.             {-1618.2531, 1777.9023, 10.3289, 1754.5313, -2631.9651, 13.5469},
  128.             {-1618.2531, 1777.9023, 10.3289, 64.0848, -265.2267, 1.5781},
  129.         },
  130.     },
  131.     {"Counterfeit Goods Transport", 1, "drug",
  132.         {
  133.             {52.2017, -274.7493, 1.6974, 987.6440, -927.7278, 42.1797},
  134.             {52.2017, -274.7493, 1.6974, 1475.9570, -1130.9758, 24.0781},
  135.             {52.2017, -274.7493, 1.6974, 1815.0590, -1841.7106, 13.5781},
  136.             {52.2017, -274.7493, 1.6974, 507.1934, -1362.7794, 16.1252},
  137.         },
  138.     },
  139. }
  140.  
  141. function assignedMission(mission)
  142.     local veh = getPedOccupiedVehicle(client)
  143.     missionsAble[mission][3] = missionsAble[mission][3] - 1
  144.     vehInfo[client] = veh
  145.     removeEventHandler("onPlayerQuit", client, onPlrQuit)
  146.     addEventHandler("onPlayerQuit", client, onPlrQuit)
  147.     if (missionsAble[mission][3] == 0) then
  148.         missionsAble[mission] = nil
  149.         return true
  150.     end
  151.     updatePlrTable(false)
  152. end
  153. addEvent("CITcrimTruck.assignedMission", true)
  154. addEventHandler("CITcrimTruck.assignedMission", resourceRoot, assignedMission)
  155.  
  156. function pickCargo(mission)
  157.     local veh = getPedOccupiedVehicle(client)
  158.     if (not trucksAllowed[getElementModel(veh)] or illegalStart[client]) then
  159.         return false
  160.     end
  161.     local x, y, z = getElementPosition(veh)
  162.     local rx, ry, rz = getElementRotation(veh)
  163.     trailers[veh] = createVehicle(435, x, y, z, rx, ry, rz)
  164.     attachTrailerToVehicle(veh, trailers[vehInfo[client]])
  165.     removeEventHandler("onElementDestroy", trailers[veh], onVehDestroy)
  166.     removeEventHandler("onVehicleExplode", trailers[veh], onVehDestroy)
  167.     addEventHandler("onElementDestroy", trailers[veh], onVehDestroy)
  168.     addEventHandler("onVehicleExplode", trailers[veh], onVehDestroy)
  169.     if (not illegalStart[client]) then
  170.         illegalStart[client] = nil
  171.     end
  172.     illegalStart[client] = true
  173.     for i, pol in pairs(exports.CITbusiness:getPlayersByJob("Police Service")) do
  174.         triggerClientEvent(pol, "CITcrimTruck.updateCrimTable", pol, illegalStart)
  175.     end
  176. end
  177. addEvent("CITcrimTruck.pickCargo", true)
  178. addEventHandler("CITcrimTruck.pickCargo", resourceRoot, pickCargo)
  179.  
  180. function removeMarkers(mission)
  181.     if (trailers[vehInfo[client]]) then
  182.         destroyElement(trailers[vehInfo[client]])
  183.         trailers[vehInfo[client]] = nil
  184.     end
  185.     removeEventHandler("onPlayerQuit", client, onPlrQuit)
  186.     updatePlrTable(false)
  187.     missionPlayer[client] = nil
  188.     vehInfo[client] = nil
  189.     if (not illegalStart[client]) then
  190.         return false
  191.     end
  192.     illegalStart[client] = false
  193.     caughtCrim[client] = false
  194. end
  195. addEvent("CITcrimTruck.removeMarkers", true)
  196. addEventHandler("CITcrimTruck.removeMarkers", resourceRoot, removeMarkers)
  197.  
  198. function paymentIllegal(paymentTable, hp)
  199.     local mission, risk, distance, typePay = paymentTable[1], paymentTable[2], paymentTable[3], paymentTable[4]
  200.     if (caughtCrim[client]) then
  201.         risk = 0
  202.     end
  203.     local payment = math.ceil((1000 * ((risk * 0.2) + (distance / 100 * 0.6) + (hp / 100 * 0.2))), 0)
  204.     exports.CITaccounts:invSet(getPlayerAccount(client), "illegalTrucking", (exports.CITaccounts:invGet(getPlayerAccount(client), "illegalTrucking") or 0) + 1)
  205.     exports.CITcrimExp:modifyPlayerCriminalRep(client, 500)
  206.     if (typePay == "drug") then
  207.         local amountDrugs = math.ceil((payment / 1500), 0)
  208.         if (not exports.CITmoney:checkMoneyIncome(client, amountDrugs * 1500)) then
  209.             return false
  210.         end
  211.         exports.CITdrug:giveDrug(client, "all", amountDrugs)
  212.         amountDrugs = exports.CITmisc:comVal(amountDrugs)
  213.         exports.CITlogs:logSomething(getPlayerName(client).." got "..amountDrugs.." of each drugs from illegal mission:"..mission, "crimTruck2", client)
  214.         exports.CIThelp:dm("You delivered the goods successfully and you got %s of each drugs.", client, 150, 0, 0, true, amountDrugs)
  215.         return true
  216.     end
  217.     if (typePay == "explosive") then
  218.         local amountExplo = math.ceil((payment / 300), 0)
  219.         if (not exports.CITmoney:checkMoneyIncome(client, amountExplo * 300)) then
  220.             return false
  221.         end
  222.         exports.CITcrafting:modifyPlayerItem(client, "Explosive", amountExplo)
  223.         amountExplo = exports.CITmisc:comVal(amountExplo)
  224.         exports.CITlogs:logSomething(getPlayerName(client).." got "..amountExplo.." explosives from illegal mission:"..mission, "crimTruck2", client)
  225.         exports.CIThelp:dm("You delivered the goods successfully and you got %s grams of explosives.", client, 150, 0, 0, true, amountExplo)
  226.         return true
  227.     end
  228.     exports.CITmoney:GPM(client, payment, "Accomplished crimTruck mission: "..mission, true)
  229.     payment = exports.CITmisc:comVal(payment)
  230.     exports.CIThelp:dm("You delivered the goods successfully and you got $%s", client, 150, 0, 0, true, exports.CITmisc:comVal(payment))
  231. end
  232. addEvent("CITcrimTruck.paymentIllegal", true)
  233. addEventHandler("CITcrimTruck.paymentIllegal", resourceRoot, paymentIllegal)
  234.  
  235. function caughtByPolice(police)
  236.     local gCrim, gPolice = getElementData(client, "g"), getElementData(police, "g")
  237.     local sCrim, sPolice = getElementData(client, "s"), getElementData(police, "s")
  238.     local uCrim, uPolice = getElementData(client, "n"), getElementData(police, "n")
  239.     if ((gCrim and gPolice and gCrim == gPolice) or (sCrim and sPolice and sCrim == sPolice) or (uCrim and uPolice and uCrim == uPolice) or caughtCrim[client]) then
  240.         return false
  241.     end
  242.     caughtCrim[client] = true
  243.     exports.CIThelp:dm("You have been located by a police officer. Finish the mission before they catch you!", client, 150, 0, 0, true)
  244.     exports.CIThelp:dm("You are near of a criminal! You have been rewarded with $5,000.", police, 0, 0, 200, true)
  245.     exports.CITpoliceDatabase:recordCrime(client, 12)
  246.     local x, y, z = getElementPosition(police)
  247.     for i, copsNear in pairs(exports.CITbusiness:getPlayersByJob("Police Service")) do
  248.         local x1, y1, z1 = getElementPosition(copsNear)
  249.         if (getDistanceBetweenPoints2D(x, y, x1, y1) <= 25 and copsNear ~= police) then
  250.             exports.CITmoney:GPM(copsNear, 1000, "Finding an illegal trucker.", true)
  251.             exports.CIThelp:dm("You got $1,000 for assisting the police!", copsNear, 0, 0, 200, true)
  252.         end
  253.     end
  254.     exports.CITmoney:GPM(police, 5000, "Finding an illegal trucker.", true)
  255.     exports.CIThelp:opc("Dispatcher: "..getPlayerName(police).." has found a criminal that is transporting an illegal cargo. Stop the criminal!", exports.CITbusiness:getPlayersByJob("Police Service"), 0, 0, 200)
  256. end
  257. addEvent("CITcrimTruck.caughtByPolice", true)
  258. addEventHandler("CITcrimTruck.caughtByPolice", resourceRoot, caughtByPolice)
  259.  
  260. function pickTrailer()
  261.     trailBlip[client] = createBlipAttachedTo(trailers[vehInfo[client]], 17, 2, 255, 255, 255, 255, 0, 3000, client)
  262.     removeEventHandler("onTrailerAttach", trailers[vehInfo[client]], onAttachTrailerIllegal)
  263.     removeEventHandler("onElementDestroy", vehInfo[client], onVehDestroy)
  264.     addEventHandler("onTrailerAttach", trailers[vehInfo[client]], onAttachTrailerIllegal)
  265.     addEventHandler("onElementDestroy", vehInfo[client], onVehDestroy)
  266.    
  267. end
  268. addEvent("CITcrimTruck.pickTrailer", true)
  269. addEventHandler("CITcrimTruck.pickTrailer", resourceRoot, pickTrailer)
  270.  
  271. function onAttachTrailerIllegal(theTruck)
  272.     local driver = getVehicleController(theTruck)
  273.     if (trailBlip[driver]) then
  274.         destroyElement(trailBlip[driver])
  275.         trailBlip[driver] = nil
  276.         exports.CIThelp:dm("You already got the trailer. Now delivery it!", driver, 0, 255, 0, true)
  277.         removeEventHandler("onTrailerAttach", trailers[vehInfo[driver]], onAttachTrailerIllegal)
  278.         removeEventHandler("onElementDestroy", vehInfo[driver], onVehDestroy)
  279.     end
  280. end
  281.  
  282. function recoverTrail(plr, cmd)
  283.     if (not getPedOccupiedVehicle(plr) or not vehInfo[plr] or not trailers[vehInfo[plr]]) then
  284.         return false
  285.     end
  286.     local x, y, z = getElementPosition(plr)
  287.     local x1, y1, z1 = getElementPosition(trailers[vehInfo[plr]])
  288.     if (getDistanceBetweenPoints2D(x, y, x1, y1) > 100) then
  289.         exports.CIThelp:dm("You are away from your trailer!", plr, 0, 255, 0, true)
  290.         return false
  291.     end
  292.     attachTrailerToVehicle(vehInfo[plr], trailers[vehInfo[plr]])
  293.     fixVehicle(trailers[vehInfo[plr]])
  294. end
  295. addCommandHandler("rtrailer", recoverTrail)
  296.  
  297. function onPlrQuit()
  298.     if (not crimTeam[getElementData(source, "o")]) then
  299.         return false
  300.     end
  301.     if (getPedOccupiedVehicleSeat(source) ~= 0) then
  302.         return false
  303.     end
  304.     --triggerClientEvent(source, "CITcrimTruck.stopMission", source)
  305.     removeMarkers(missionPlayer[source], source)
  306. end
  307.  
  308. function onVehDestroy()
  309.     if (getElementType(source) ~= "vehicle" or not trucksAllowed[getElementModel(source)] or getElementModel(source) ~= 435) then
  310.         return false
  311.     end
  312.     if (getElementModel(source) == 435) then
  313.         for plr, trail in pairs(trailers) do
  314.             if (trail == source) then
  315.                 triggerClientEvent(plr, "CITcrimTruck.stopMission", plr)
  316.                 break
  317.             end
  318.         end
  319.     end
  320.     local driver = getVehicleController(source)
  321.     if (not driver or not trailBlip[driver]) then
  322.         return false
  323.     end
  324.     destroyElement(trailBlip[driver])
  325.     trailBlip[driver] = nil
  326.     exports.CIThelp:dm("Removed blip as you destroyed the vehicle.", driver, 0, 255, 0, true)
  327.     removeEventHandler("onTrailerAttach", trailers[vehInfo[driver]], onAttachTrailerIllegal)
  328.     removeEventHandler("onElementDestroy", vehInfo[driver], onVehDestroy)
  329. end
  330.  
  331. function newMission()
  332.     local count = 0
  333.     for mission, value in pairs(missionsAble) do
  334.         if (type(value) == "table") then
  335.             count = count + 1
  336.         end
  337.     end
  338.     if (count == 10) then
  339.         return false
  340.     end
  341.     local missionR = math.random(#illegalMissions)
  342.     if (type(missionsAble[illegalMissions[missionR][1]]) == "table") then
  343.         newMission()
  344.         return false
  345.     end
  346.     if (type(missionsAble[illegalMissions[missionR][1]]) ~= "table") then
  347.         missionsAble[illegalMissions[missionR][1]] = {}
  348.     end
  349.     missionsAble[illegalMissions[missionR][1]] = {illegalMissions[missionR][2], illegalMissions[missionR][3], math.random(1, 5), illegalMissions[missionR][4]}
  350. end
  351. setTimer(newMission, 5000, 0)
  352.  
  353. function updatePlrTable(bool, bCrim)
  354.     if (bool) then
  355.         triggerClientEvent(client, "CITcrimTruck.updateTables", client, missionsAble)
  356.         return bool
  357.     end
  358.     if (bCrim) then
  359.         triggerClientEvent(client, "CITcrimTruck.updateCrimTable", client, illegalStart)
  360.         return bCrim
  361.     end
  362.     for i, plr in pairs(getElementsByType("player")) do
  363.         if (crimTeam[getElementData(plr, "o")] and getPedOccupiedVehicle(plr) and trucksAllowed[getElementModel(getPedOccupiedVehicle(plr))]) then
  364.             triggerClientEvent(plr, "CITcrimTruck.updateTables", plr, missionsAble)
  365.         end
  366.     end
  367. end
  368. addEvent("CITcrimTruck.updateTableToPlrs", true)
  369. addEventHandler("CITcrimTruck.updateTableToPlrs", resourceRoot, updatePlrTable)
Advertisement
Add Comment
Please, Sign In to add comment