• Spawn an entity with a vehicle
    5 replies, posted
How would you go about making it so when you spawn a vehicle, it will spawn an entity with it? So a good example of what im trying to do. If you spawned a car, and wanted to put a light on it so when you drive around the light would be on the same place relative to the car. How would you do something like this?
You mean like parenting? I know you can set the entity to a point relative to the vehicle's model, but I think they both have to be entities, and the actual method is unknown to me...maybe look up gmod parenting on google, see whatcha find.
Hmmm yeah I did a little research and didn't seem to turn up much.
Quick example : [lua]hook.Add("PlayerSpawnedVehicle","JeepAttachment",function( ply, vehicle ) if not vehicle:GetModel( ) == "models/buggy.mdl" then return end local horse = ents.Create( "prop_dynamic" ) horse:SetModel( "models/props_c17/statue_horse.mdl" ) horse:SetPos( vehicle:GetPos() + Vector(0,0,50) ) horse:SetAngles( vehicle:GetAngles() + Angle(-25,-90,0) ) horse:SetParent( vehicle ) vehicle:DeleteOnRemove( horse ) horse:Spawn( ) end)[/lua] Result : [URL=http://img691.imageshack.us/i/gmconstruct0004es.jpg/][IMG]http://img691.imageshack.us/img691/7959/gmconstruct0004es.th.jpg[/IMG][/URL] :science: [editline]03:06AM[/editline] [QUOTE=Killer_Steel;22157910]I think they both have to be entities[/QUOTE] Entities don't have to be models, lights are entities too and can be parented just as easily.
Very nice! Thank you mucho!
Note that my example will only work in Sandbox, or sandbox derived gamemodes. Otherwise you need another way to get the jeep entity, preferably by spawning it yourself.
Sorry, you need to Log In to post a reply to this thread.