Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------------------------------------
- -- COMMUNITY CONTRIBUTION FOR CIT2.NET
- -- PURPOSE: Illegal Trucker version 2.0 - Client Side
- -- DEVELOPERS: Ryan#USNS (IRC: Ryan1)
- ------------------------------------------------------------------------------------
- local t = function(...) return exports.CITt:t(...) or arg[1] or "error" end
- local allowedVehs = {[403] = true, [514] = true, [515] = true}
- local pMarker, pBlip, dMarker, dBlip, inTask, curMission, countLoad, distanceRisk, radarTimer, infoMissions, checkDistance, timerLoad, distanceLeaving, countLeave, crimIllegal, copTimer
- local paymentInfo = {}
- local crimTeam = {["Criminal"] = true, ["Gangster"] = true}
- function updateTable(mTable)
- infoMissions = mTable
- end
- addEvent("CITcrimTruck.updateTables", true)
- addEventHandler("CITcrimTruck.updateTables", localPlayer, updateTable)
- function createIllegalGUI()
- local sx, sh = guiGetScreenSize()
- illegalWindow = guiCreateWindow((sx / 2) - (433 / 2), (sh / 2) - (334 / 2), 433, 334, "Illegal Trucker", false)
- guiWindowSetSizable(illegalWindow, false)
- guiSetAlpha(illegalWindow, 1.00)
- guiSetVisible(illegalWindow, false)
- missionsList = guiCreateGridList(9, 22, 414, 200, false, illegalWindow)
- guiGridListAddColumn(missionsList, t("Mission"), 0.4)
- guiGridListAddColumn(missionsList, t("Risk"), 0.1)
- guiGridListAddColumn(missionsList, t("Payment"), 0.2)
- guiGridListAddColumn(missionsList, t("Deliveries miss"), 0.2)
- guiGridListSetSortingEnabled(missionsList, false)
- getMissionButton = guiCreateButton(10, 292, 96, 32, t("Get Mission"), false, illegalWindow)
- closeButton = guiCreateButton(328, 292, 95, 32, t("Close"), false, illegalWindow)
- riskScrollbar = guiCreateScrollBar(9, 250, 414, 26, true, false, illegalWindow)
- lowRiskLabel = guiCreateLabel(15, 225, 91, 20, t("Low Risk"), false, illegalWindow)
- guiLabelSetVerticalAlign(lowRiskLabel, "center")
- highRiskLabel = guiCreateLabel(332, 225, 91, 20, t("High Risk"), false, illegalWindow)
- guiLabelSetHorizontalAlign(highRiskLabel, "right", false)
- guiLabelSetVerticalAlign(highRiskLabel, "center")
- infoLabel = guiCreateLabel(134, 286, 170, 18, t("Current Risk: "), false, illegalWindow)
- guiLabelSetHorizontalAlign(infoLabel, "center", false)
- guiLabelSetVerticalAlign(infoLabel, "center")
- --Event Handler
- addEventHandler("onClientGUIClick", closeButton, toggleIllegalWindow, false)
- addEventHandler("onClientGUIClick", getMissionButton, getMission, false)
- addEventHandler("onClientGUIDoubleClick", missionsList, getMission, false)
- addEventHandler("onClientGUIScroll", riskScrollbar, selectRisk, false)
- end
- function toggleIllegalWindow()
- if (not crimTeam[getElementData(localPlayer, "o")] and not illegalWindow) then
- return false
- end
- triggerServerEvent("CITcrimTruck.updateTableToPlrs", resourceRoot, true)
- local veh = getPedOccupiedVehicle(localPlayer)
- if (not infoMissions) then
- exports.CIThelp:dm(t("Refreshing the panel. Wait a minute."), 255, 0, 0)
- return false
- end
- local countM = 0
- for i, v in pairs(infoMissions) do
- countM = countM + 1
- end
- if (not countM or countM ~= 10) then
- exports.CIThelp:dm(t("Refreshing the panel. Wait a minute."), 255, 0, 0)
- return false
- end
- if (inTask) then
- if (not illegalWindow or not guiGetVisible(illegalWindow)) then
- return false
- end
- guiSetVisible(illegalWindow, false)
- showCursor(false)
- return false
- end
- if (getPedOccupiedVehicleSeat(localPlayer) ~= 0) then
- return false
- end
- if (getElementSpeed(veh, 2) > 4) then
- exports.CIThelp:dm(t("Stop your vehicle to be assigned to a mission!"), 255, 0, 0)
- return false
- end
- if (not illegalWindow) then
- createIllegalGUI()
- end
- if (not veh or not allowedVehs[getElementModel(veh)]) then
- if (not illegalWindow or not guiGetVisible(illegalWindow)) then
- return false
- end
- guiSetVisible(illegalWindow, false)
- showCursor(false)
- setElementHealth(localPlayer, 0)
- exports.CIThelp:dm(t("You have been killed because you were trying to cheat"), 255, 0, 0)
- return false
- end
- local state = not guiGetVisible(illegalWindow)
- guiSetVisible(illegalWindow, state)
- showCursor(state)
- --setElementFrozen(veh, state)
- if (not state) then
- setElementData(localPlayer, "lccrim", nil, false)
- return true
- end
- refreshGridList()
- setElementData(localPlayer, "lccrim", 1, false)
- end
- function selectRisk()
- local number = guiScrollBarGetScrollPosition(riskScrollbar)
- local risk = math.ceil((number / 20), 0)
- if (risk == 0) then
- risk = 1
- end
- guiSetText(infoLabel, t("Current Risk: %s", tostring(risk)))
- end
- function getMission()
- --Check Police
- local count = 0
- local x, y, z = getElementPosition(localPlayer)
- for i, pol in pairs(exports.CITbusiness:getPlayersByJob("Police Service")) do
- if (pol == localPlayer) then
- guiSetVisible(illegalWindow, false)
- showCursor(false)
- --setElementFrozen(veh, false)
- setElementData(localPlayer, "lccrim", nil, false)
- end
- local x2, y2, z2 = getElementPosition(pol)
- if (getDistanceBetweenPoints2D(x, y, x2, y2) < 50) then
- count = count + 1
- end
- end
- if (count ~= 0) then
- exports.CIThelp:dm(t("You are near the police. Stay away to start the mission!"), 255, 0, 0)
- return false
- end
- --
- local veh = getPedOccupiedVehicle(localPlayer)
- if (not veh or not allowedVehs[getElementModel(veh)]) then
- if (not illegalWindow or not guiGetVisible(illegalWindow)) then
- return false
- end
- guiSetVisible(illegalWindow, false)
- showCursor(false)
- setElementHealth(localPlayer, 0)
- exports.CIThelp:dm(t("You have been killed because you were trying to cheat"), 255, 0, 0)
- return false
- end
- --Send the mission to server Side.
- local r, c = guiGridListGetSelectedItem(missionsList)
- if (r < 0) then
- return false
- end
- local mission = guiGridListGetItemText(missionsList, r, 1)
- if (not infoMissions[mission] or infoMissions[mission][3] <= 0) then
- exports.CIThelp:dm("Refreshing the panel. Wait a minute.", 255, 0, 0)
- refreshGridList()
- return false
- end
- local scrollPos = guiScrollBarGetScrollPosition(riskScrollbar)
- local riskPlr = math.ceil((scrollPos / 20), 0)
- if (riskPlr == 0) then
- riskPlr = 1
- end
- toggleIllegalWindow()
- triggerServerEvent("CITcrimTruck.assignedMission", resourceRoot, mission)
- --Start the currently mission for client
- local totalRisk = riskPlr * infoMissions[mission][1]
- distanceRisk = 10 * totalRisk
- if (distanceRisk <= 29) then
- distanceRisk = 30
- end
- curMission = mission
- local coords = infoMissions[mission][4][math.random(#infoMissions[mission][4])]
- local px, py, pz, dx, dy, dz = coords[1], coords[2], coords[3], coords[4], coords[5], coords[6]
- pMarker = createMarker(px, py, pz - 1, "cylinder", 4, 100, 0, 0, 255)
- pBlip = createBlipAttachedTo(pMarker, 32)
- dMarker = createMarker(dx, dy, dz - 1, "cylinder", 4, 100, 0, 0, 0)
- removeEventHandler("onClientMarkerHit", pMarker, pickStuff)
- removeEventHandler("onClientMarkerHit", dMarker, deliveryStuff)
- addEventHandler("onClientMarkerHit", pMarker, pickStuff)
- addEventHandler("onClientMarkerHit", dMarker, deliveryStuff)
- local city = exports.CITmapMisc:getZoneName2(px, py, pz, false)
- local zone = exports.CITmapMisc:getZoneName2(px, py, pz, true)
- local distance = getDistanceBetweenPoints2D(px, py, dx, dy)
- exports.CIThelp:modTextBar("illegalTruckMission", t("Company: %s.Destination: %s (%s)", mission, city, zone), 100, 0, 0, 255)
- paymentInfo[localPlayer] = {mission, totalRisk, distance, infoMissions[mission][2]}
- inTask = true
- removeEventHandler("onClientPlayerWasted", localPlayer, onPlrWasted)
- removeEventHandler("didKillCommand", localPlayer, onPlrWasted)
- addEventHandler("onClientPlayerWasted", localPlayer, onPlrWasted)
- addEventHandler("didKillCommand", localPlayer, onPlrWasted)
- end
- function pickStuff(plr, mDim)
- if (localPlayer ~= plr) then
- return false
- end
- if (not plr or not mDim or getElementAlpha(pMarker) == 0) then
- return false
- end
- local veh = getPedOccupiedVehicle(plr)
- if (getElementModel(veh) == 435) then
- return false
- end
- if (not veh or not allowedVehs[getElementModel(veh)]) then
- exports.CIThelp:dm(t("You don't have a vehicle or you are using a wrong vehicle."), 255, 0, 0)
- return false
- end
- if (getElementSpeed(veh, 2) > 40) then
- exports.CIThelp:dm(t("You are driving too fast. Slow down to under 64 kph (40 mph)."), 255, 0, 0)
- return false
- end
- setElementFrozen(veh, true)
- setTimer(setElementFrozen, 1000, 1, veh, false)
- countLoad = 0
- timerLoad = setTimer(cargoLoad, 2000, 4, veh)
- exports.CIThelp:modTextBar("cargoType", "Load cargo: "..countLoad.."%", 100, 0, 0, 255)
- setElementAlpha(pMarker, 0)
- if (pBlip) then
- destroyElement(pBlip)
- pBlip = nil
- end
- radarTimer = setTimer(searchCops, 2000, 0)
- triggerServerEvent("CITcrimTruck.pickCargo", resourceRoot)
- setElementData(localPlayer, "lccrim", 1, false)
- end
- function cargoLoad(veh)
- countLoad = countLoad + 25
- exports.CIThelp:modTextBar("cargoType", "Load cargo: "..countLoad.."%", 100, 0, 0, 255)
- if (countLoad == 100) then
- --setElementFrozen(veh, false)
- setElementData(localPlayer, "lccrim", nil, false)
- countLoad = nil
- timerLoad = nil
- exports.CIThelp:modTextBar("cargoType", "")
- local x, y, z = getElementPosition(dMarker)
- local city = exports.CITmapMisc:getZoneName2(x, y, z, false)
- local zone = exports.CITmapMisc:getZoneName2(x, y, z, true)
- exports.CIThelp:modTextBar("illegalTruckMission", "Company: "..curMission..".Destination: "..city.."("..zone..").", 100, 0, 0, 255)
- setElementAlpha(dMarker, 255)
- dBlip = createBlipAttachedTo(dMarker, 51)
- setElementDimension(dBlip, 0)
- end
- end
- function deliveryStuff(plr, mDim)
- if (localPlayer ~= plr) then
- return false
- end
- if (not plr or not mDim or getElementAlpha(source) == 0) then
- return false
- end
- local veh = getPedOccupiedVehicle(plr)
- if (getElementModel(veh) == 435) then
- return false
- end
- if (not veh or not allowedVehs[getElementModel(veh)]) then
- exports.CIThelp:dm(t("You don't have a vehicle or you are using a wrong vehicle."), 255, 0, 0)
- return false
- end
- if (getElementSpeed(veh, 2) > 40) then
- exports.CIThelp:dm(t("You are driving too fast. Slow down to under 64 kph (40 mph)."), 255, 0, 0)
- return false
- end
- if (not getVehicleTowedByVehicle(veh)) then
- exports.CIThelp:dm(t("You need pick the trailer before delivery it. Marked with Diner blip!"), 255, 0, 0)
- exports.CIThelp:dm(t("You may use '/rtrailer' to recover your trailer. For use this command, the requirement is being nearby of your trailer"), 255, 0, 0)
- triggerServerEvent("CITcrimTruck.pickTrailer", localPlayer)
- return false
- end
- local hp = getElementHealth(veh)
- triggerServerEvent("CITcrimTruck.paymentIllegal", resourceRoot, paymentInfo[plr], hp)
- stopMission()
- onPlrVehEnter(veh)
- end
- function stopMission()
- if (isTimer(distanceLeaving)) then
- killTimer(distanceLeaving)
- distanceLeaving = nil
- end
- if (pMarker) then
- destroyElement(pMarker)
- pMarker = nil
- end
- if (pBlip) then
- destroyElement(pBlip)
- pBlip = nil
- end
- if (dMarker) then
- destroyElement(dMarker)
- dMarker = nil
- end
- if (dBlip) then
- destroyElement(dBlip)
- dBlip = nil
- end
- if (isTimer(radarTimer)) then
- killTimer(radarTimer)
- radarTimer = nil
- end
- if (isTimer(timerLoad)) then
- killTimer(timerLoad)
- timerLoad = nil
- end
- removeEventHandler("onClientPlayerWasted", localPlayer, onPlrWasted)
- removeEventHandler("didKillCommand", localPlayer, onPlrWasted)
- setElementData(localPlayer, "lccrim", nil, false)
- triggerServerEvent("CITcrimTruck.removeMarkers", resourceRoot, curMission)
- exports.CIThelp:modTextBar("copSearching", "")
- exports.CIThelp:modTextBar("illegalTruckMission", "")
- exports.CIThelp:modTextBar("cargoType", "")
- inTask = false
- curMission = nil
- distance = nil
- paymentInfo = {}
- end
- addEvent("CITcrimTruck.stopMission", true)
- addEventHandler("CITcrimTruck.stopMission", localPlayer, stopMission)
- function searchCops()
- local copSearch = {}
- local x, y, z = getElementPosition(localPlayer)
- if (crimTeam[getElementData(localPlayer, "o")] and inTask and getElementDimension(localPlayer) == 0) then
- for i, pol in pairs(exports.CITbusiness:getPlayersByJob("Police Service")) do
- local mX, mY, mZ = getElementPosition(pol)
- local distance = getDistanceBetweenPoints2D(x, y, mX, mY)
- local gCrim, gPolice = getElementData(localPlayer, "g"), getElementData(pol, "g")
- local sCrim, sPolice = getElementData(localPlayer, "s"), getElementData(pol, "s")
- local uCrim, uPolice = getElementData(localPlayer, "n"), getElementData(pol, "n")
- if (distance <= 400 and gCrim ~= gPolice and sCrim ~= sPolice and uCrim ~= uPolice) then
- copSearch[#copSearch + 1] = {distance, pol}
- end
- end
- if (not copSearch[1]) then
- exports.CIThelp:modTextBar("copSearching", "")
- return false
- end
- table.sort(copSearch, sortMyTable)
- if (copSearch[1] ~= 0) then
- exports.CIThelp:modTextBar("copSearching", t("Stay away from the police to not get caught! Distance: %s m", math.ceil(copSearch[1][1], 0)), 100, 0, 0)
- if (copSearch[1][1] < distanceRisk) then
- triggerServerEvent("CITcrimTruck.caughtByPolice", resourceRoot, copSearch[1][2])
- killTimer(radarTimer)
- end
- else
- exports.CIThelp:modTextBar("copSearching", "")
- end
- else
- exports.CIThelp:modTextBar("copSearching", "")
- end
- end
- function sortMyTable(a, b)
- return a[1] < b[1]
- end
- function onPlrVehEnter(veh, seat)
- if (not allowedVehs[getElementModel(veh)] or not crimTeam[getElementData(localPlayer, "o")] or seat ~= 0 or getElementDimension(localPlayer) ~= 0) then
- return false
- end
- if (inTask and isTimer(distanceLeaving)) then
- killTimer(distanceLeaving)
- distanceLeaving = nil
- return true
- end
- unbindKey("n", "down", toggleIllegalWindow)
- bindKey("n", "down", toggleIllegalWindow)
- exports.CIThelp:modTextBar("illegalTruckMission", t("Press 'N' to start the illegal truck."), 100, 0, 0, 255, 30000)
- removeEventHandler("onClientElementDestroy", veh, vehDestroy)
- addEventHandler("onClientElementDestroy", veh, vehDestroy)
- end
- function onPlrVehExit(veh, seat)
- if (not allowedVehs[getElementModel(veh)] or not crimTeam[getElementData(localPlayer, "o")] or seat ~= 0 or getElementDimension(localPlayer) ~= 0) then
- return false
- end
- if (inTask) then
- distanceLeaving = setTimer(checkDistancePlrVeh, 5000, 6, veh)
- countLeave = 0
- --[[if (isElementFrozen(veh)) then
- setElementFrozen(veh, false)
- end]]--
- setElementData(localPlayer, "lccrim", nil, false)
- return true
- end
- exports.CIThelp:modTextBar("illegalTruckMission", "")
- --setElementFrozen(veh, false)
- setElementData(localPlayer, "lccrim", nil, false)
- end
- function checkDistancePlrVeh(veh)
- countLeave = countLeave + 1
- if (not veh or (getPedOccupiedVehicle(localPlayer) and getPedOccupiedVehicle(localPlayer) ~= veh)) then
- if (isTimer(distanceLeaving)) then
- killTimer(distanceLeaving)
- distanceLeaving = nil
- end
- stopMission()
- exports.CIThelp:dm(t("The event has been canceled as your vehicle had been destroyed or changed."), 255, 0, 0)
- return false
- end
- if (not crimTeam[getElementData(localPlayer, "o")]) then
- if (isTimer(distanceLeaving)) then
- killTimer(distanceLeaving)
- distanceLeaving = nil
- end
- stopMission()
- exports.CIThelp:dm(t("The event has been canceled as you changed the job!"), 255, 0, 0)
- return false
- end
- local x, y, z = getElementPosition(localPlayer)
- local x1, y1, z1 = getElementPosition(veh)
- if (getDistanceBetweenPoints2D(x, y, x1, y1) > 5 or countLeave == 6) then
- if (isTimer(distanceLeaving)) then
- killTimer(distanceLeaving)
- distanceLeaving = nil
- end
- --[[if (veh and isElementFrozen(veh)) then
- setElementFrozen(veh, false)
- end]]--
- stopMission()
- exports.CIThelp:dm(t("The event has been canceled as you got away from your vehicle!"), 255, 0, 0)
- end
- end
- function vehDestroy()
- removeEventHandler("onClientElementDestroy", source, vehDestroy)
- stopMission()
- end
- function onPlrWasted()
- if (illegalWindow and guiGetVisible(illegalWindow)) then
- guiSetVisible(illegalWindow, false)
- showCursor(false)
- end
- stopMission()
- end
- function refreshGridList()
- guiGridListClear(missionsList)
- for mission, value in pairs(infoMissions) do
- local row = guiGridListAddRow(missionsList)
- guiGridListSetItemText(missionsList, row, 1, mission, false, false)
- guiGridListSetItemText(missionsList, row, 2, tostring(value[1]), false, false)
- guiGridListSetItemText(missionsList, row, 3, value[2], false, false)
- guiGridListSetItemText(missionsList, row, 4, tostring(value[3]), false, false)
- end
- end
- --Cop side
- function updateCrimTable(cTable)
- crimIllegal = cTable
- end
- addEvent("CITcrimTruck.updateCrimTable", true)
- addEventHandler("CITcrimTruck.updateCrimTable", localPlayer, updateCrimTable)
- function copCheck()
- copSearching[localPlayer] = 0
- local x, y, z = getElementPosition(localPlayer)
- for crim, bool in pairs(crimIllegal) do
- if (crim and bool) then
- local mx, my, mz = getElementPosition(crim)
- local gCrim, gPolice = getElementData(crim, "g"), getElementData(localPlayer, "g")
- local sCrim, sPolice = getElementData(crim, "s"), getElementData(localPlayer, "s")
- local uCrim, uPolice = getElementData(crim, "n"), getElementData(localPlayer, "n")
- if (getDistanceBetweenPoints2D(x, y, mx, my) <= 300 and gCrim ~= gPolice and sCrim ~= sPolice and uCrim ~= uPolice) then
- copSearching[localPlayer] = copSearching[localPlayer] + 1
- end
- end
- end
- if (copSearching[localPlayer] ~= 0) then
- exports.CIThelp:modTextBar(localPlayer, "crimSearching", t(localPlayer, "Exist %s illegal trucker(s) that are close to you!", math.ceil(copSearching[localPlayer], 0)), 0, 0, 200)
- else
- exports.CIThelp:modTextBar(localPlayer, "crimSearching", "")
- end
- end
- --
- function getJob(newJob, newTeam, oldJob, oldTeam)
- if (crimTeam[newJob]) then
- addEventHandler("onClientPlayerVehicleEnter", localPlayer, onPlrVehEnter)
- addEventHandler("onClientPlayerVehicleExit", localPlayer, onPlrVehExit)
- elseif (newJob == "Police Service") then
- triggerServerEvent("CITcrimTruck.updateTableToPlrs", resourceRoot, false, true)
- copTimer = setTimer(copCheck, 2000, 0)
- else
- if (copTimer) then
- killTimer(copTimer)
- end
- removeEventHandler("onClientPlayerVehicleEnter", localPlayer, onPlrVehEnter)
- removeEventHandler("onClientPlayerVehicleExit", localPlayer, onPlrVehExit)
- end
- end
- addEvent("onClientLocalPlayerChangeJobOrTeam")
- addEventHandler("onClientLocalPlayerChangeJobOrTeam", localPlayer, getJob)
- setTimer(getJob, 2000, 1, getElementData(localPlayer, "o"))
- --MTA exports
- function getElementSpeed(theElement, unit)
- local unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit))
- local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456)
- return (Vector3(getElementVelocity(theElement)) * mult).length
- end
Advertisement
Add Comment
Please, Sign In to add comment