Advertisement
glitchdetector

omni_conductor/client.lua

Aug 5th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.22 KB | None | 0 0
  1. local GotTrain = false
  2.  
  3. local models = {
  4.     "freight", "freightcar", "freightgrain", "freightcont1", "freightcont2",
  5.     "freighttrailer", "tankercar",
  6.  
  7.     "metrotrain", "s_m_m_lsmetro_01" ,
  8.  
  9.     "6f01", "6f02", "6f03", "6f04", "6f05",
  10.  
  11.     "df4b1", "df4b2",
  12.  
  13.     -- "tgv01", "tgv02", "tgv03", "tgv04", "tgv05", "tgv06", "tgv07", "tgv08", "tgv09",
  14.  
  15.     "go_tankercar"
  16. }
  17.  
  18. local TRAIN_SPAWNS = {
  19.     -- {name = "PTPS Tanker Train", perms = {""}, location = {x = 2617.8984375, y = 1707.5870361328, z = 27.597440719604}, spawner = {train = 3, x = 2611.0749511719, y = 1766.9490966797, z = 26.37712097168} },
  20.     {name = "LS Cargo Train 1", perms = {""}, location = {x = 677.14953613281, y = -895.89562988281, z = 23.462062835693}, spawner = {train = 1, x = 666.98468017578, y = -894.25457763672, z = 22.377431869507} },
  21.     {name = "LS Cargo Train 2", perms = {""}, location = {x = 677.22564697266, y = -886.04205322266, z = 23.462043762207}, spawner = {train = 10, x = 672.77630615234, y = -886.46014404297, z = 22.561025619507} },
  22.     {name = "GS Grain Train", perms = {""}, location = {x = 2873.7795410156, y = 4868.2573242188, z = 62.395622253418}, spawner = {train = 4, x = 2867.0922851563, y = 4893.3720703125, z = 63.378673553467} },
  23.     {name = "MJ Cargo Train", perms = {""}, location = {x = -341.57598876953, y = 3744.947265625, z = 69.970855712891}, spawner = {train = 17, x = -337.26611328125, y = 3756.5151367188, z = 70.42813873291} },
  24.  
  25.     {name = "TM Passenger Long Boi (Level 10)", perms = {""}, location = {x = 2534.5405273438, y = -183.10217285156, z = 87.172782897949}, spawner = {train = 42, x = 2534.7648925781, y = -184.93153381348, z = 93.409767150879} },
  26.     {name = "LS Passenger Long Boi (Level 10)", perms = {""}, location = {x = 665.88830566406, y = -703.22497558594, z = 37.343109130859}, spawner = {train = 46, x = 926.28533935547, y = -494.29217529297, z = 30.667287826538} },
  27.     {name = "LS Passenger Train Long (Level 10)", perms = {""}, location = {x = 793.67242431641, y = -1908.7456054688, z = 21.784048080444}, spawner = {train = 43, x = 803.51043701172, y = -1908.5551757813, z = 20.564588546753} },
  28.     {name = "LS Passenger Train (Level 10)", perms = {""}, location = {x = 211.31231689453, y = -2424.5163574219, z = 8.5115089416504}, spawner = {train = 45, x = 311.2541809082, y = -2612.9780273438, z = 8.6949901580811} },
  29.     {name = "PB Passenger Train (Level 10)", perms = {""}, location = {x = -323.34335327148, y = 5962.9868164063, z = 41.883724212646}, spawner = {train = 45, x = -361.04824829102, y = 5911.4516601563, z = 45.679042816162} },
  30.     -- {name = "PB TGV (Level 20)", perms = {""}, location = {x = -315.04263305664, y = 5972.6552734375, z = 40.778701782227}, spawner = {train = 27, x = -361.04824829102, y = 5911.4516601563, z = 45.679042816162} },
  31.  
  32.     {name = "GS Passenger Train (Level 10)", perms = {""}, location = {x = 2999.7514648438, y = 4097.2358398438, z = 57.107582092285}, spawner = {train = 43, x = 3006.3293457031, y = 4097.3481445313, z = 57.612167358398} },
  33.     -- {name = "TEST 25", perms = {""}, location = {x = 2996.7514648438, y = 4087.2358398438, z = 57.107582092285}, spawner = {train = 25, x = 3006.3293457031, y = 4097.3481445313, z = 57.612167358398} },
  34.     -- {name = "TEST 26", perms = {""}, location = {x = 2993.7514648438, y = 4087.2358398438, z = 57.107582092285}, spawner = {train = 26, x = 3006.3293457031, y = 4097.3481445313, z = 57.612167358398} },
  35.  
  36.     {name = "Globe Oil Tanker Train", perms = {""}, location = {x = 2617.8984375, y = 1707.5870361328, z = 27.597440719604}, spawner = {train = 26, x = 2611.0749511719, y = 1766.9490966797, z = 26.37712097168} },
  37.  
  38.     -- {name = "TGV 27", perms = {""}, location = {x = 1287.8082275391, y = 6417.193359375, z = 26.299634933472}, spawner = {train = 27, x = 1271.0749511719, y = 6429.5927734375, z = 31.852146148682} },
  39.     -- {name = "TGV 28 (Level 20)", perms = {""}, location = {x = 1295.1345214844, y = 6415.7954101563, z = 26.497575759888}, spawner = {train = 28, x = 1271.0749511719, y = 6429.5927734375, z = 31.852146148682} },
  40.     -- {name = "TGV 29", perms = {""}, location = {x = 1290.7263183594, y = 6410.3115234375, z = 26.601089477539}, spawner = {train = 29, x = 1271.0749511719, y = 6429.5927734375, z = 31.852146148682} },
  41.  
  42.     {name = "LS Metro Tram", perms = {""}, location = {x = 563.8271484375, y = -1984.6627197266, z = 17.775186538696}, spawner = {train = 24, x = 562.055969, y = -1978.789307, z = 16.775246} },
  43.     {name = "LS Metro Tram", perms = {""}, location = {x = -1105.1005859375, y = -2744.1628417969, z = -7.4101328849792}, spawner = {train = 24, x = -1099.512207, y = -2746.507568, z = -9.923965} },
  44.     {name = "LS Metro Passenger Train (Level 10)", perms = {""}, location = {x = -401.71618652344, y = -681.5390625, z = 11.616627693176}, spawner = {train = 45, x = -412.29736328125, y = -669.05096435547, z = 10.895616531372} },
  45. }
  46.  
  47. local function LoadModel(model)
  48.     tempmodel = GetHashKey(model)
  49.     RequestModel(tempmodel)
  50.     local _timeout = 0
  51.     local _boundary = 2000
  52.     while not HasModelLoaded(tempmodel) do
  53.         Citizen.Wait(0)
  54.         _timeout = _timeout + 1
  55.         if _timeout >= _boundary then
  56.             print("Timed out loading model " .. model)
  57.             break
  58.         end
  59.     end
  60. end
  61.  
  62. Citizen.CreateThread(function()
  63.     function LoadTrainModels()
  64.         DeleteAllTrains()
  65.  
  66.         for k, v in pairs(models) do
  67.             LoadModel(v)
  68.         end
  69.  
  70.         Citizen.Trace("Done Loading Train Models")
  71.     end
  72.     LoadTrainModels()
  73.  
  74.     -- ------------------------------------------ --
  75.     Citizen.Trace("Loading Train Keys")
  76.     local localPed = GetPlayerPed(PlayerId())
  77.  
  78.  
  79.     local TrainVars = {}
  80.     local TrainList = {}
  81.     TrainVars.inTrain = false
  82.     TrainVars.isPassenger = false
  83.     TrainVars.TrainVeh = 0
  84.     TrainVars.Speed = 0
  85.     TrainVars.EnterExitDelay = 0
  86.     TrainVars.EnterExitDelayMax = 3000
  87.  
  88.     TrainVars.TrainSpeeds = {}
  89.     TrainVars.TrainSpeeds.FTrain = {}
  90.     TrainVars.TrainSpeeds.FTrain.MaxSpeed = 40
  91.     TrainVars.TrainSpeeds.FTrain.Accel = 0.03
  92.  
  93.     TrainVars.TrainSpeeds.JTrain = {}
  94.     TrainVars.TrainSpeeds.JTrain.MaxSpeed = 60
  95.     TrainVars.TrainSpeeds.JTrain.Accel = 0.06
  96.  
  97.     TrainVars.TrainSpeeds.DF4BTrain = {}
  98.     TrainVars.TrainSpeeds.DF4BTrain.MaxSpeed = 40
  99.     TrainVars.TrainSpeeds.DF4BTrain.Accel = 0.04
  100.  
  101.     TrainVars.TrainSpeeds.Trolley = {}
  102.     TrainVars.TrainSpeeds.Trolley.MaxSpeed = 25
  103.     TrainVars.TrainSpeeds.Trolley.Accel = 0.1
  104.  
  105.     function findNearestTrain()
  106.         for _, train in ipairs(TrainList) do
  107.             if(not IsEntityDead(train)) then
  108.                 local pedPosition = GetEntityCoords(LocalPed())
  109.                 local trainPosition = GetEntityCoords(train)
  110.                 local thedist = GetDistanceBetweenCoords(pedPosition.x, pedPosition.y, pedPosition.z, trainPosition.x, trainPosition.y, trainPosition.z, false)
  111.                 Citizen.Trace("Checking ".. GetEntityModel(train) .." at: " .. tostring(trainPosition))
  112.                 Citizen.Trace("Checking Player at: " .. tostring(pedPosition))
  113.  
  114.                 Citizen.Trace("Dist: " .. thedist)
  115.                 if (thedist <= 40) then
  116.                     return train
  117.                 end
  118.             end
  119.         end
  120.         return 0
  121.     end
  122.  
  123.     function getTrainSpeeds()
  124.         local mod = GetEntityModel(TrainVars.TrainVeh)
  125.         local ret = {}
  126.         ret.MaxSpeed = 10
  127.         ret.Accel = 1
  128.  
  129.         -- print("trainmod: " .. mod)
  130.         -- print("tgv01 hash: " .. GetHashKey("tgv01"))
  131.  
  132.         -- Is there a better way to do this? (GetEntityModel(TrainVars.TrainVeh))
  133.         if (mod == 1030400667) then
  134.             ret.MaxSpeed = TrainVars.TrainSpeeds.FTrain.MaxSpeed -- Heavy, but fast.
  135.             ret.Accel = TrainVars.TrainSpeeds.FTrain.Accel
  136.         elseif (mod == 868868440) then
  137.             ret.MaxSpeed = TrainVars.TrainSpeeds.Trolley.MaxSpeed -- Light weight, carrys people around not to fast
  138.             ret.Accel = TrainVars.TrainSpeeds.Trolley.Accel
  139.         elseif (mod == 1377039676) then
  140.             ret.MaxSpeed = TrainVars.TrainSpeeds.JTrain.MaxSpeed -- Light weight, carrys people around not to fast
  141.             ret.Accel = TrainVars.TrainSpeeds.JTrain.Accel
  142.         elseif (mod == GetHashKey("df4b1")) then -- df4b1
  143.             ret.MaxSpeed = TrainVars.TrainSpeeds.DF4BTrain.MaxSpeed -- Light weight, carrys people around not to fast
  144.             ret.Accel = TrainVars.TrainSpeeds.DF4BTrain.Accel
  145.         elseif (mod == GetHashKey("df4b2")) then -- df4b2
  146.             ret.MaxSpeed = TrainVars.TrainSpeeds.DF4BTrain.MaxSpeed -- Light weight, carrys people around not to fast
  147.             ret.Accel = TrainVars.TrainSpeeds.DF4BTrain.Accel
  148.         elseif (mod == 2158407904) then -- go_tankercar
  149.             ret.MaxSpeed = 80
  150.             ret.Accel = 2.0
  151.         elseif (mod == GetHashKey("tgv01")) then -- tgv01
  152.             ret.MaxSpeed = 70 -- Light weight, carrys people around not to fast
  153.             ret.Accel = 0.12
  154.         else
  155.             ret.MaxSpeed = 10
  156.             ret.Accel = 1.0
  157.         end
  158.  
  159.         return ret
  160.     end
  161.  
  162.     RegisterNetEvent("conductor:setSpeed")
  163.     function SetSpeed(speed)
  164.         TrainVars.Speed = 0
  165.     end
  166.     AddEventHandler("conductor:setSpeed", SetSpeed)
  167.  
  168.     RegisterNetEvent("conductor:setLimit")
  169.     function SetLimit(speed)
  170.         TrainVars.TrainSpeeds.FTrain.MaxSpeed = 0
  171.     end
  172.     AddEventHandler("conductor:setLimit", SetSpeed)
  173.  
  174.     RegisterNetEvent("UpdateTrainList")
  175.     function UpdateTrainList(Trains, Del)
  176.         if (Del == true) then
  177.             for _, k in ipairs(TrainList) do
  178.                 DeleteMissionTrain(k)
  179.             end
  180.  
  181.             TrainVars.inTrain = false
  182.             TrainVars.TrainVeh = 0
  183.             TrainVars.Speed = 0
  184.             TrainVars.EnterExitDelay = 0
  185.  
  186.             Citizen.Trace("Got Delete Message, have not removed array yet.")
  187.             return
  188.         end
  189.  
  190.         Citizen.Trace("Added new Trains from server.")
  191.         TrainList = Trains
  192.     end
  193.     AddEventHandler("UpdateTrainList", UpdateTrainList)
  194.  
  195.     function createNewTrain(type, x, y, z)
  196.         local train = CreateMissionTrain(type, x, y, z, true)
  197.         SetTrainSpeed(train, 0)
  198.         SetTrainCruiseSpeed(train, 0)
  199.         Citizen.Trace("Created Train, sending to server.")
  200.         TriggerServerEvent("AddToTrainList", train)
  201.         return train
  202.     end
  203.  
  204.     function DeleteTrains()
  205.         TriggerServerEvent("DeleteTrains")
  206.     end
  207.  
  208.     function CoolDown()
  209.         SetTimeout(300000, function() GotTrain = false end)
  210.     end
  211.  
  212.     function LocalPed()
  213.         return GetPlayerPed(-1)
  214.     end
  215.  
  216.     function DrawText3D(text, x, y, z, s)
  217.         exports['omni_common']:DrawText3D(text, x, y, z, s)
  218.     end
  219.  
  220.     while true do
  221.         Wait(1)
  222.  
  223.         if (TrainVars.EnterExitDelay == 0) then
  224.             TrainVars.EnterExitDelay = GetGameTimer()
  225.         end
  226.  
  227.         if (TrainVars.inTrain and not TrainVars.isPassenger) then
  228.             SetTrainSpeed(TrainVars.TrainVeh, TrainVars.Speed)
  229.         end
  230.  
  231.         -- Speed Up/Forwards (W)
  232.         if (IsControlPressed(0, 71) and TrainVars.inTrain and TrainVars.Speed < getTrainSpeeds().MaxSpeed and not TrainVars.isPassenger) then
  233.             TrainVars.Speed = TrainVars.Speed + getTrainSpeeds().Accel
  234.             SetTrainSpeed(TrainVars.TrainVeh, TrainVars.Speed)
  235.         end
  236.  
  237.         -- Slow down/Reverse (S)
  238.         if (IsControlPressed(0, 72) and TrainVars.inTrain and TrainVars.Speed > - (getTrainSpeeds().MaxSpeed / 4) and not TrainVars.isPassenger) then
  239.             TrainVars.Speed = TrainVars.Speed - (getTrainSpeeds().Accel * 1.5)
  240.             SetTrainSpeed(TrainVars.TrainVeh, TrainVars.Speed)
  241.         end
  242.  
  243.         -- HORN
  244.         if (IsControlJustPressed(0, 86) and TrainVars.inTrain and not TrainVars.isPassenger) then
  245.  
  246.         end
  247.         if (IsControlJustReleased(0, 86) and TrainVars.inTrain and not TrainVars.isPassenger) then
  248.  
  249.         end
  250.  
  251.         -- Slow break (Spacebar)
  252.         local speed = GetEntitySpeed(GetVehiclePedIsIn(GetPlayerPed(-1), true)) * 2.236936
  253.         if speed <= 25.0 and (
  254.             IsVehicleModel(GetVehiclePedIsIn(GetPlayerPed(-1), true), GetHashKey('freight')) or
  255.             IsVehicleModel(GetVehiclePedIsIn(GetPlayerPed(-1), true), GetHashKey('6f01')) or
  256.             IsVehicleModel(GetVehiclePedIsIn(GetPlayerPed(-1), true), GetHashKey('tgv01')) or
  257.             IsVehicleModel(GetVehiclePedIsIn(GetPlayerPed(-1), true), GetHashKey('df4b1')) or
  258.             IsVehicleModel(GetVehiclePedIsIn(GetPlayerPed(-1), true), GetHashKey('df4b2'))
  259.         ) then
  260.             if (IsControlJustPressed(0, 76) and TrainVars.inTrain and TrainVars.Speed ~= 0 and not TrainVars.isPassenger) then
  261.                 --Citizen.Trace("break:" .. GetEntityCoords(TrainVars.TrainVeh))
  262.                 TrainVars.Speed = 0
  263.                 SetTrainSpeed(TrainVars.TrainVeh, TrainVars.Speed)
  264.             end
  265.         end
  266.  
  267.         local speed = GetEntitySpeed(GetVehiclePedIsIn(GetPlayerPed(-1), true)) * 2.236936
  268.         if speed <= 5.0 and (
  269.             IsVehicleModel(GetVehiclePedIsIn(GetPlayerPed(-1), true), GetHashKey('metrotrain')) or
  270.             IsVehicleModel(GetVehiclePedIsIn(GetPlayerPed(-1), true), GetHashKey('6f01')) or
  271.             IsVehicleModel(GetVehiclePedIsIn(GetPlayerPed(-1), true), GetHashKey('tgv01'))
  272.         ) then
  273.             if (IsControlPressed(0, 76) and TrainVars.inTrain and TrainVars.Speed ~= 0 and not TrainVars.isPassenger) then
  274.                 --Citizen.Trace("break:" .. GetEntityCoords(TrainVars.TrainVeh))
  275.                 TrainVars.Speed = 0
  276.                 SetTrainSpeed(TrainVars.TrainVeh, TrainVars.Speed)
  277.             end
  278.         end
  279.         --[[
  280.                     if (IsControlPressed(0,22) and TrainVars.inTrain and TrainVars.Speed ~= 0)then
  281.                         --Citizen.Trace("break:" .. GetEntityCoords(TrainVars.TrainVeh))
  282.                         TrainVars.Speed = 30
  283.                         SetTrainSpeed(TrainVars.TrainVeh, TrainVars.Speed)
  284.                     end]]
  285.  
  286.         --AntiBreak for blah
  287.  
  288.         -- Enter/Exit (F)X
  289.         if(IsControlPressed(0, 75) and(GetGameTimer() - TrainVars.EnterExitDelay) > TrainVars.EnterExitDelayMax) then
  290.             TrainVars.EnterExitDelay = 0
  291.  
  292.             if(TrainVars.inTrain) then
  293.                 Citizen.Trace("exit")
  294.                 if (TrainVars.TrainVeh ~= 0) then
  295.                     local pedPosition = GetEntityCoords(LocalPed())
  296.                     SetEntityCoords(LocalPed(), pedPosition.x, pedPosition.y - 0.5, pedPosition.z + 2.3, false, false, false, false)
  297.                 end
  298.                 TrainVars.inTrain = false
  299.                 TrainVars.isPassenger = false
  300.                 TrainVars.TrainVeh = 0
  301.             else
  302.                 Citizen.Trace("enter")
  303.                 local _train = findNearestTrain()
  304.                 if (TrainVars.TrainVeh == 0) then
  305.                     if not IsVehicleSeatFree(_train, -1) then
  306.                         if not IsVehicleSeatFree(_train, 0) then
  307.                             -- Train is full
  308.                             print("Train full")
  309.                         else
  310.                             print("Seat 2 free")
  311.                             SetPedIntoVehicle(LocalPed(), _train, 0)
  312.                             TrainVars.inTrain = true
  313.                             TrainVars.isPassenger = true
  314.                             TrainVars.TrainVeh = _train
  315.                         end
  316.                     else
  317.                         print("Seat 1 free")
  318.                         SetPedIntoVehicle(LocalPed(), _train, -1)
  319.                         TrainVars.inTrain = true
  320.                         TrainVars.isPassenger = false
  321.                         TrainVars.TrainVeh = _train
  322.                     end
  323.                 end
  324.             end
  325.         end
  326.  
  327.         local playerPed = LocalPed()
  328.         local playerPos = GetEntityCoords(playerPed)
  329.         for train_no, train_spawner in next, TRAIN_SPAWNS do
  330.             if not train_spawner.cooldown then train_spawner.cooldown = 0 end
  331.             if train_spawner.cooldown > 0 then train_spawner.cooldown = train_spawner.cooldown - 1 end
  332.  
  333.             local dist = Vdist(playerPos.x, playerPos.y, playerPos.z, train_spawner.location.x, train_spawner.location.y, train_spawner.location.z)
  334.             if not IsPedInAnyVehicle(playerPed, false) then
  335.                 if dist < 150.0 then
  336.                     DrawMarker(0, train_spawner.location.x, train_spawner.location.y, train_spawner.location.z, 0, 0, 0, 0, 0, 0, 1.0, 1.0, 1.0, 139, 69, 19, 255, true, false)
  337.                 end
  338.                 if dist < 3.0 then
  339.                     if train_spawner.cooldown <= 0 then
  340.                         DrawText3D("Press ~y~E ~w~to spawn a~n~~y~" .. train_spawner.name, train_spawner.location.x, train_spawner.location.y, train_spawner.location.z + 1.0)
  341.                         if IsControlJustPressed(0, 38) then
  342.                             train_spawner.cooldown = 2000
  343.                             TrainVars.EnterExitDelay = 0
  344.  
  345.                             local _newTrain = createNewTrain(train_spawner.spawner.train, train_spawner.spawner.x, train_spawner.spawner.y, train_spawner.spawner.z)
  346.  
  347.                             Wait(60)
  348.                             --TrainVars.Speed = 0
  349.                             GotTrain = true
  350.                             TrainVars.TrainVeh = _newTrain
  351.                             TrainVars.inTrain = true
  352.                             TaskWarpPedIntoVehicle(GetPlayerPed(-1), _newTrain, - 1)
  353.                             CoolDown()
  354.  
  355.                         end
  356.                     else
  357.                         DrawText3D("~r~Please wait before spawning this again~n~~y~" .. train_spawner.name, train_spawner.location.x, train_spawner.location.y, train_spawner.location.z + 1.0)
  358.                     end
  359.                 end
  360.             end
  361.         end
  362.     end
  363.  
  364.     function drawTxt(text, font, centre, x, y, scale, r, g, b, a)
  365.         SetTextFont(font)
  366.         SetTextProportional(0)
  367.         SetTextScale(scale, scale)
  368.         SetTextColour(r, g, b, a)
  369.         SetTextDropShadow(0, 0, 0, 0, 255)
  370.         SetTextEdge(1, 0, 0, 0, 255)
  371.         SetTextDropShadow()
  372.         SetTextOutline()
  373.         SetTextCentre(centre)
  374.         SetTextEntry("STRING")
  375.         AddTextComponentString(text)
  376.         DrawText(x, y)
  377.     end
  378. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement