I am trying to figure out how I can get a vehicle spawn whenever I start an server.
Does anyone have any idea?
Please be more specific. Which vehicle do you want to spawn? By "whenever I start an server" do you mean when you restart the map or when a player first joins? By "get a vehicle spawn" do you mean designate a spot where all vehicles spawn or do you mean spawn a vehicle?
Let's say Buggy. And when I restart the map. And just 1 specific car.
OK well in init.lua put this:
[lua]
local buggy = ents.Create("prop_vehicle_jeep")
buggy:SetKeyValue("vehiclescript", "scripts/vehicles/jeep_test.txt")
buggy:SetModel("models/buggy.mdl")
buggy:SetPos(position here) -- put the position where you want the jeep to spawn
buggy:Spawn()
buggy:Activate()
[/lua]
I'm no pro at Lua but i think this will work
Okay I will try that.
don't forget to edit the part that says position here in line 4.
if you want it to spawn at a certain place on your map, you must put an entity inside the map to give it the position where it spawns. Or you could replace "position here" with a vector position
I tried that but it doesn't spawn and I don't get a error.
yes i expect you didn't change the part that said position here. try replacing "position here" with vector(0,0,0). Just to clarify replace the above script with this: [lua]
local buggy = ents.Create("prop_vehicle_jeep")
buggy:SetKeyValue("vehiclescript", "scripts/vehicles/jeep_test.txt")
buggy:SetModel("models/buggy.mdl")
buggy:SetPos(vector(0,0,0))
buggy:Spawn()
buggy:Activate()
[/lua]
Or you can tell me where you want the buggy to spawn and I'll tell you how to do it
With what lemmiwinkz said, make sure you capitalize vector. So it's Vector( x, y, z ). Also, to get the x, y and z coordinates, type getpos in console at the spot in the map.
I know. Tried it but It just didn't spawn? I didn't get a error too.
[editline]08:10PM[/editline]
I did it like this:
[lua]
function SpawnCar()
local buggy = ents.Create("prop_vehicle_jeep")
buggy:SetKeyValue("vehiclescript", "scripts/vehicles/jeep_test.txt")
buggy:SetModel("models/buggy.mdl")
buggy:SetPos(-718, 1623, 63) -- put the position where you want the jeep to spawn
buggy:Spawn()
buggy:Activate()
end
[/lua]
Ok well the obvious problem is that you havn't called the function you just created it. after the end, put a line that says: SpawnCar()
This ought to fix it
[editline]08:19PM[/editline]
or remove the function part altogether it is completely uneccessary
Okay, now the car spawned but it fucked everything else.
oh and you seem to have missed out vector before the string of numbers. after SetPos( put Vector( and after 63 put )
[QUOTE=Persious;22640398]Okay, now the car spawned but it fucked everything else.[/QUOTE]
What does that mean exactly?
[QUOTE=Persious;22640398]Okay, now the car spawned but it fucked everything else.[/QUOTE]
In what manner?
Oh, saw that now.
[editline]08:22PM[/editline]
Let me test it now.
[editline]08:24PM[/editline]
It worked! Well, another question. If I download hoffa's air planes and helicopters, how can I get them spawned?
To do that you can use the same code but you must delete the SetKeyValue line and change the strings for ents.Create and SetModel. For SetModel, find the model of the plane/helicopter. For ents.Create, find the type of entity that it is.
Oh, okay.
[editline]08:46PM[/editline]
It worked! I am so thankfull! Thanks!
Sorry, you need to Log In to post a reply to this thread.