Fixing up VUmod for DarkRP, almost working, but..

As the title suggests VUmod doesn’t work with DarkRPs way of spawning a vehicle.

DarkRP does not use the PlayerSpawnedVehicle hook to create a vehicle.
It does it by using the Entity.Create.

The PlayerSpawnedVehicle hook is what VUmod uses to add seats.

I’ve circumvented it by defining the vehicle which normally the hook did.

I’ve almost got VUmod working, but am baffled by something I do not fully understand.

The parented seat freaks out whenever a 2nd vehicle is spawned. It’s like it wants to get attached to the 2nd vehicle. But it can’t because it’s parented with the first vehicle. It causes the server to crash after the two vehicles spazz out on each other.

Here is the code: ( I have left out “unimportant” pieces of code )


local function SpawnedVehicle(player)
if player:InVehicle() then
local vehicle = player:GetVehicle() --Defining the vehicle used in further code.
local localpos = vehicle:GetPos()
local localang = vehicle:GetAngles()

if vehicle:GetNWInt(“Seats”) == 1 then --A Check to see if the seats have already been added.
return --Return if statement is true.

if vehicle.VehicleTable then
if vehicle.VehicleTable.Passengers then
-----Grab the data for the extra seats, we want the sitting
vehicle:SetNWInt(“Seats”, 1)
local SeatName = vehicle.VehicleTable.SeatType
local seatdata = list.Get( “Vehicles” )[ SeatName ]

  -----Repeat for each seat.
 for a,b in pairs(vehicle.VehicleTable.Passengers) do
  local SeatPos = localpos + ( localang:Forward() * b.Pos.x) + ( localang:Right() * b.Pos.y) + ( localang:Up() * b.Pos.z)
  local Seat = ents.Create( "prop_vehicle_prisoner_pod" )
  Seat:SetModel( seatdata.Model )
  Seat:SetKeyValue( "vehiclescript" , "scripts/vehicles/prisoner_pod.txt" )
  Seat:SetAngles( localang + b.Ang )
  Seat:SetPos( SeatPos )
   if vehicle.VehicleTable.HideSeats then
   if ( seatdata.Members ) then
   table.Merge( Seat, seatdata.Members )
   if ( seatdata.KeyValues ) then
    for k, v in pairs( seatdata.KeyValues ) do
    Seat:SetKeyValue( k, v )
  Seat.VehicleName = "Jeep Seat"
  Seat.VehicleTable = seatdata
  Seat.ClassOverride = "prop_vehicle_prisoner_pod"
  Seat:DeleteOnRemove( vehicle )
  ----------- Replace the position with the ent so we can find it later.
  vehicle.VehicleTable.Passengers[a].Ent = Seat
if vehicle.VehicleTable.HeadLights then
 vehicle.HeadLights = {}
 local lights = vehicle.VehicleTable.HeadLights
 local angles = vehicle:GetAngles()
 for a,b in pairs(lights) do
 local pos = vehicle:GetPos() + ( angles:Forward() * b.Pos.x ) + ( angles:Right() * b.Pos.y ) + ( angles:Up() * b.Pos.z )
   vehicle.HeadLights[a] = ents.Create( "vu_headlight" )
   vehicle.HeadLights[a]:SetAngles( angles + b.Ang )
   vehicle.HeadLights[a]:DeleteOnRemove( vehicle )


local function Vehicle( player, vehicle, role )
player:ConCommand(“VehicleSeats”) --Added to run the console command to add seats, when the player enters the vehicle.


concommand.Add(“VehicleSeats”, SpawnedVehicle) --Added to trigger the seats to spawn.
/hook.Add( “PlayerSpawnedVehicle”, “SpawnedVehicle”, SpawnedVehicle );/ --Deactivated as it doesn’t work with DarkRPs way of creating a vehicle.
hook.Add( “PlayerEnteredVehicle”, “EnteredVehicle”, EnteredVehicle );


If you have any suggestions or ideas, please post them. I thank you for your time.

Probbably your doing someting wrong… like paranting the seats to something bad or something, i suggest to modify DarkRP instead of VU, you probbably want to copy VU code into DarkRP

According to the wiki, the player:InVehicle() should be:
[lua]if (player:InVehicle()) then[/lua]

Just tried this, it gives the same problem, the server crashes whenever a second vehicle is spawned.




Can you make a fast tut explaining how to make it work? :S i dont understand where to put your code!

He wanted help with his code, not giving his code for people to use