Spawn an entity with a vehicle?

Someone could explain me why this shit doesn’t working?

In Autorun

[lua]local function SpawnedVehicle ( player, vehicle )
if player:InVehicle() then
local vehicle = player:GetVehicle()

local class = player:GetVehicle():GetClass();
local model = player:GetVehicle():GetModel();
if(class == “prop_vehicle_jeep” and model == “models/buggy.mdl”) then

     self.gun = ents.Create( "Test" )
    self.gun:SetParent( vehicle )    
    self.gun:SetPos( vehicle:GetPos() + vehicle:GetForward() * 20 + vehicle:GetUp() * 60 + vehicle:GetRight() * 17  )
    self.gun:SetAngles( vehicle:GetAngles() )


hook.Add( “PlayerSpawnedVehicle”, “SpawnedVehicle”, SpawnedVehicle );[/lua]

playerWarthogVehicle isn’t a valid hook. Did you mean **[Gamemode.PlayerSpawnVehicle](**?

i tryied with that[lua] local function SpawnedVehicle ( player, vehicle ) hook.Add( “PlayerSpawnedVehicle”, “SpawnedVehicle”, SpawnedVehicle ); [/lua] it still doesn’t work

A few problems here I’m afraid. But you need to tell us what your goal is with this code and exactly what’s happening, whether or not you’re getting any errors etc.

As for the problems themselves, this isn’t in the code of SWEP or SENT and so self doesn’t exist on lines 9-14. On line 12 you used Vehicle, which should be vehicle. It’s case sensitive.

Your indentation looks quite messy as well, if you fix that we can read your code much more easily.

in fact, when you spawn a buggy and enter in it, It should spawn the test entity and weld it to the buggy(vehicle)

This is what i’m trying to make

If you want it to spawn the entity when you enter the vehicle, what you’re looking for is a PlayerEnteredVehicle hook. eg

local function JeepAttachEnt(ply, ent, role)
if ent:GetClass() == “prop_vehicle_jeep” and ent:GetModel() == “models/buggy.mdl” then
–spawn testent
hook.Add(“PlayerEnteredVehicle”, “JeepAttachTestEnt”, JeepAttachEnt)

what about i want to delete it without deleting the car?