SHARE
TWEET

Untitled

a guest Aug 13th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Now this is really stupid
  2. --Seems like i can't get the name of the vehicle when it's spawned but i can get the name when it's about to get spawned
  3. --In the wiki it says that jalopy = "prop_vehicle_jalopy" and jeep = "prop_vehicle_jeep" but in fact THEY ARE BOTH EQUAL TO "prop_vehicle_jeep"
  4. --And there is no way to check any difference between them so i have to use a temp variable.
  5. local lastVehicleName = ""
  6.  
  7. function SpawningVehicleWithExtraSeats( player, model, vehiclename, vehicletable ) --Vehicle is about to spawn
  8.     lastVehicleName = vehiclename
  9. end
  10. hook.Add( "PlayerSpawnVehicle", "SpawningVehicleWithExtraSeats", SpawningVehicleWithExtraSeats )
  11.  
  12.  
  13. --Adding the extra seats to a vehicle when it's spawned
  14. function SpawnVehicleWithExtraSeats( ply, veh ) --Vehicle is spawned
  15.  
  16.  
  17.     local seatInfo = SeatRegister:GetCarSeatInfo( lastVehicleName )
  18.     lastVehicleName = ""
  19.    
  20.     if seatInfo then
  21.         local allSeats = {}
  22.        
  23.         for i = 1, seatInfo.NumberOfSeats do
  24.             allSeats[i] = ents.Create("prop_vehicle_prisoner_pod")  
  25.             allSeats[i]:SetModel("models/nova/airboat_seat.mdl")
  26.             allSeats[i]:SetPos( veh:GetPos() + veh:GetForward() * seatInfo.SeatPos[i].y + veh:GetRight() * seatInfo.SeatPos[i].x + veh:GetUp() * seatInfo.SeatPos[i].z )
  27.             allSeats[i]:SetAngles( veh:GetAngles() + seatInfo.SeatAng[i])
  28.             allSeats[i]:Spawn()  
  29.             allSeats[i]:GetPhysicsObject():EnableGravity(false)
  30.             allSeats[i]:GetPhysicsObject():SetMass(1)
  31.             allSeats[i]:SetNotSolid( true )
  32.             allSeats[i]:GetPhysicsObject():EnableDrag(false)   
  33.             allSeats[i]:DrawShadow( false )
  34.             allSeats[i].IsExtraVehicle = true
  35.             allSeats[i].OffsetPos = seatInfo.ExitPositions[i]
  36.             allSeats[i].ParentCar = veh
  37.  
  38.             if seatInfo.HideSeats == true then
  39.                 allSeats[i]:SetColor(0,0,0,0)
  40.             end
  41.            
  42.             constraint.Weld( veh, allSeats[i], 0, 0, 0, true )
  43.            
  44.             veh.ExtraSeats = {}
  45.             veh.ExtraSeats.seats = allSeats
  46.             veh.ExtraSeats.seatInfo = seatInfo
  47.             veh.HasExtraSeats = true
  48.         end
  49.        
  50.             --[[
  51.             local enterHelper = ents.Create("enterDetector")
  52.             enterHelper.maxS = veh:OBBMaxs()
  53.             enterHelper.minS = veh:OBBMins()
  54.             enterHelper.Seats = allSeats
  55.             enterHelper.SeatInfo = seatInfo
  56.             enterHelper.EntOwner = veh
  57.            
  58.            
  59.             enterHelper:Spawn()
  60.             local height = enterHelper.maxS.z - enterHelper.minS.z
  61.             enterHelper:SetPos( veh:GetPos() + veh:GetUp() )
  62.             enterHelper:SetAngles( veh:GetAngles() )
  63.             constraint.Weld( veh, enterHelper, 0, 0, 0, true )
  64.             --]]
  65.        
  66.     end
  67.  
  68. end
  69. hook.Add( "PlayerSpawnedVehicle", "SpawnVehicleWithExtraSeats", SpawnVehicleWithExtraSeats )
  70.  
  71.  
  72. --GETTING THE NEXT EMPTY EXTRA SEAT
  73. function GetNextEmptySeat( start, nrOfSeats, seats )
  74.     for i = start, (nrOfSeats + start) do
  75.    
  76.         local slot = i % (nrOfSeats + 1)
  77.        
  78.         if slot != 0 && ValidEntity( seats[slot] ) && seats[slot]:GetDriver() == NULL then
  79.             return slot
  80.         end
  81.     end
  82.  
  83.     return 0
  84. end
  85. --[[
  86. --PLAYER ENTERING VEHICLE
  87. local function CanEnterExtraSeats( ply, veh, role )
  88.  
  89.  
  90.     Msg("Player tried to enter vehicle\n")
  91.  
  92.     if veh.HasExtraSeats == true && veh:GetDriver():IsPlayer() then
  93.     --if veh.HasExtraSeats == true then
  94.         Msg("1\n")
  95.         local slot = GetNextEmptySeat( 1, veh.ExtraSeats.seatInfo.NumberOfSeats, veh.ExtraSeats.seats  )
  96.    
  97.         if slot != 0 then
  98.             Msg("2\n")
  99.             ply:EnterVehicle( veh.ExtraSeats.seats[slot] )
  100.             ply.ExtraVehicleSlot = slot
  101.             return false
  102.         end
  103.         Msg("3\n")
  104.     end
  105.     Msg("4\n")
  106.  
  107. end
  108. hook.Add( "CanPlayerEnterVehicle", "CanEnterExtraSeats", CanEnterExtraSeats )
  109.     --]]
  110.  
  111.     --[[
  112. --PLAYER ENTERING VEHICLE
  113. local function CanEnterExtraSeats( ply, veh, role )
  114.  
  115.  
  116.     Msg("Player tried to enter vehicle\n")
  117.  
  118.     if veh.HasExtraSeats == true && veh:GetDriver():IsPlayer() then
  119.     --if veh.HasExtraSeats == true then
  120.         Msg("1\n")
  121.         local slot = GetNextEmptySeat( 1, veh.ExtraSeats.seatInfo.NumberOfSeats, veh.ExtraSeats.seats  )
  122.    
  123.         if slot != 0 then
  124.             Msg("2\n")
  125.             ply:EnterVehicle( veh.ExtraSeats.seats[slot] )
  126.             ply.ExtraVehicleSlot = slot
  127.             return false
  128.         end
  129.         Msg("3\n")
  130.     end
  131.     Msg("4\n")
  132.  
  133. end
  134. hook.Add( "CanPlayerEnterVehicle", "CanEnterExtraSeats", CanEnterExtraSeats )  
  135. --]]
  136.    
  137. function CanEnterExtraSeatsUse( ply, ent )
  138.  
  139.     if  (ply.enterExtraSeatDel == nil or ply.enterExtraSeatDel < CurTime()) && ent:IsVehicle() && ent.HasExtraSeats == true && ent:GetDriver():IsPlayer() then
  140.         local slot = GetNextEmptySeat( 1, ent.ExtraSeats.seatInfo.NumberOfSeats, ent.ExtraSeats.seats  )
  141.    
  142.         if slot != 0 then
  143.             ply.enterExtraSeatDel = CurTime() + 1
  144.             ply:EnterVehicle( ent.ExtraSeats.seats[slot] )
  145.             ply.ExtraVehicleSlot = slot
  146.             return false
  147.         end
  148.     end
  149. end
  150. hook.Add( "PlayerUse", "CanEnterExtraSeatsUse", CanEnterExtraSeatsUse )
  151.    
  152. --[[
  153. --PLAYER ENTERING VEHICLE
  154. local function CanEnterExtraSeats( ply, veh, role )
  155.  
  156.     if veh.HasExtraSeats == true or (!ply.enterExtraSeatDel == nil && ply.enterExtraSeatDel > CurTime()) then
  157.         return false
  158.     end
  159. end
  160. hook.Add( "CanPlayerEnterVehicle", "CanEnterExtraSeats", CanEnterExtraSeats )  
  161. --]]
  162.    
  163. function CanExitExtraSeats( veh, ply )
  164.     if (ply.enterExtraSeatDel && ply.enterExtraSeatDel > CurTime()) then
  165.         return false
  166.     end
  167. end
  168. hook.Add( "CanExitVehicle", "CanExitExtraSeats", CanExitExtraSeats )
  169.    
  170. --PLAYER LEAVING VEHICLE
  171. function LeavingExtraSeats( ply, veh )
  172.  
  173.    
  174.    
  175.     if (ply.enterExtraSeatDel == nil or ply.enterExtraSeatDel < CurTime()) && veh.IsExtraVehicle == true && veh.OffsetPos then
  176.         ply.enterExtraSeatDel = CurTime() + 1
  177.         local pos = veh.OffsetPos
  178.         ply:SetPos( veh.ParentCar:GetPos() + veh.ParentCar:GetForward() * pos.y + veh.ParentCar:GetRight() * pos.x + veh.ParentCar:GetUp() * pos.z)
  179.     end
  180. end
  181. hook.Add( "PlayerLeaveVehicle", "LeavingExtraSeats", LeavingExtraSeats )
  182.  
  183.  
  184. --REMOVE EXTRA SEATS WHEN THE VEHICLE IS REMOVED
  185. function RemoveExtraSeats( ent )
  186.  
  187.     if ent.HasExtraSeats == true then
  188.         for i = 1, ent.ExtraSeats.seatInfo.NumberOfSeats do
  189.             ent.ExtraSeats.seats[i]:Remove()
  190.         end
  191.     end
  192. end
  193. hook.Add( "EntityRemoved", "RemoveExtraSeats", RemoveExtraSeats )
RAW Paste Data
Top