CapsAdmin

Untitled

Mar 27th, 2011
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.52 KB | None | 0 0
  1. hook.Add("KeyPress", "surface_sit", function(ply, key)
  2.     if not ply:GetVehicle():IsValid() and key == IN_USE and ply:KeyDown(IN_WALK) then
  3.         local trace = util.QuickTrace(ply:EyePos(), ply:GetAimVector() * 100, ply)
  4.        
  5.         if trace.Hit and not trace.Entity:IsPlayer() and not trace.Entity:IsNPC() then
  6.    
  7.             local angle = trace.HitNormal:Angle()
  8.             angle:RotateAroundAxis(angle:Up(), 90)
  9.             angle:RotateAroundAxis(angle:Forward(), 90)
  10.                        
  11.             angle:RotateAroundAxis(trace.HitNormal, math.AngleDifference(ply:EyeAngles().y, 180))
  12.            
  13.             print(math.Round(angle.p), math.Round(angle.y), math.Round(angle.r))
  14.            
  15.             --if math.abs(angle.r) > 45 then return end
  16.  
  17.             local ent = ents.Create("weapon_seat")
  18.            
  19.             ent:SetModel("models/nova/airboat_seat.mdl")
  20.             ent:SetPos(trace.HitPos - (trace.HitNormal * 2))
  21.             ent:SetAngles(angle)
  22.            
  23.             ent.up_offset = 43.5
  24.             ent.right_offset = 1.75
  25.             ent.forward_offset = 0
  26.             ent.surface_sit = true
  27.            
  28.             ent:Spawn()
  29.            
  30.             ent:SetStoolSeat(true)     
  31.            
  32.             ply:EnterVehicle(ent)
  33.  
  34.             if trace.Entity:IsValid() and not trace.Entity:IsWorld() then
  35.                 ent:GetPhysicsObject():EnableMotion(true)
  36.                 constraint.Weld(trace.Entity, ent, 0, 0, 0, true)
  37.                 trace.Entity:CallOnRemove("surface_sit"..ply:UniqueID(), function()
  38.                     if ent:IsVehicle() then
  39.                         ent:Remove()
  40.                     end
  41.                 end)
  42.             else
  43.                 ent:SetMoveType(MOVETYPE_NONE)
  44.             end
  45.  
  46.         end
  47.     end
  48. end)
  49.  
  50. hook.Add("PlayerLeaveVehicle", "surface_sit", function(ply, ent)
  51.     if ent.surface_sit  then
  52.         ent:Remove()
  53.     end
  54. end)
Advertisement
Add Comment
Please, Sign In to add comment