• Need help with making a NPC spawn at a vector.
    4 replies, posted
Sorry if this is in the wrong section I was split between questions and requests. Hi we are making a new server and are having trouble making a NPC saleman spawn at a vector when the map loads. We are running Dark Rp, The target spawn vector is (803.47, 3968.94, -157.97). And in the entities or the addentities.lua, folder to spawn the car salesman from the F4 menu it shows a command like this " /adminnpccar". We have tried putting self:SetPos(VECTOR) and self:Spawn() in the ENT:intialize( ) functions But that seemed to 'Break' the F4 menu spawner and it still would not spawn. Any help or tips are greatly appreciated. Here is the full code. [CODE] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) function ENT:Initialize( ) self:SetModel( "models/player/humans/suits1/male_04.mdl" ) self:SetHullType( HULL_HUMAN ) self:SetUseType( SIMPLE_USE ) self:SetHullSizeNormal( ) self:SetSolid( SOLID_BBOX ) self:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_OPEN_DOORS | CAP_ANIMATEDFACE | CAP_USE_SHOT_REGULATOR | CAP_TURN_HEAD | CAP_AIM_GUN ) self:SetMaxYawSpeed( 5000 ) local PhysAwake = self.Entity:GetPhysicsObject( ) if PhysAwake:IsValid( ) then PhysAwake:Wake( ) end end function ENT:OnTakeDamage( dmg ) return false end function ENT:AcceptInput( name, activator, caller ) if ( name == "Use" && ValidEntity( activator ) && activator:IsPlayer( ) ) then umsg.Start( "PurchaseCars", activator ) umsg.End( ) end end local CarMiniSpawn = { } CarMiniSpawn[ 1 ] = Vector(1331.56, 3811.59, -157.97) CarMiniSpawn[ 2 ] = Vector(2345.50, 3773.06, -157.97) local CarGolfSpawn = { } CarGolfSpawn[ 1 ] = Vector(2083.97, 3790.75, -157.97) CarGolfSpawn[ 2 ] = Vector(2345.50, 3773.06, -157.97) local CarCorvetteSpawn = { } CarCorvetteSpawn[ 1 ] = Vector(2083.97, 3790.75, -157.97) CarCorvetteSpawn[ 2 ] = Vector(1605.58, 3805.72, -157.97) local CarMurcielagoSpawn = { } CarMurcielagoSpawn[ 1 ] = Vector(1605.58, 3805.72, -157.97) CarMurcielagoSpawn[ 2 ] = Vector(2083.97, 3790.75, -157.97) local CarBMWSpawn = { } CarBMWSpawn[ 1 ] = Vector(2345.50, 3773.06, -157.97) CarBMWSpawn[ 2 ] = Vector(1331.56, 3811.59, -157.97) local CarHummerSpawn = { } CarHummerSpawn[ 1 ] = Vector(2345.50, 3773.06, -157.97) CarHummerSpawn[ 2 ] = Vector(1605.58, 3805.72, -157.97) local CarATVSpawn = { } CarATVSpawn[ 1 ] = Vector(2345.50, 3773.06, -157.97) CarATVSpawn[ 2 ] = Vector(2083.97, 3790.75, -157.97) local CarSpyderSpawn = { } CarSpyderSpawn[ 1 ] = Vector(2083.97, 3790.75, -157.97) CarSpyderSpawn[ 2 ] = Vector(2345.50, 3773.06, -157.97) function SpawnCarMini(ply, ent) if not ply:CanAfford(45000) then Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "car")) return "" else ply:AddMoney(-45000) local Mini = ents.Create("prop_vehicle_jeep_old") Mini:SetModel("models/mini/mini.mdl") Mini:SetKeyValue("vehiclescript", "scripts/vehicles/mini.txt") Mini:SetPos(table.Random(CarMiniSpawn)) Mini.Owner = Mini:Own(ply) Mini:Spawn() Mini:Activate() end end concommand.Add("buy_mini", SpawnCarMini) function SpawnCarGolf(ply, ent) if not ply:CanAfford(50000) then Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "car")) return "" else ply:AddMoney(-50000) local golf = ents.Create("prop_vehicle_jeep") golf:SetModel("models/golf/golf.mdl") golf:SetKeyValue("vehiclescript", "scripts/vehicles/golf.txt") golf:SetPos(table.Random(CarGolfSpawn)) golf.Owner = golf:Own(ply) golf:Spawn() golf:Activate() end end concommand.Add("buy_golf", SpawnCarGolf) function SpawnCarCorvette(ply, ent) if not ply:CanAfford(100000) then Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "car")) return "" else ply:AddMoney(-100000) local Corvette = ents.Create("prop_vehicle_jeep") Corvette:SetModel("models/corvette/corvette.mdl") Corvette:SetKeyValue("vehiclescript", "scripts/vehicles/corvette.txt") Corvette:SetPos(table.Random(CarCorvetteSpawn)) Corvette.Owner = Corvette:Own(ply) Corvette:Spawn() Corvette:Activate() end end concommand.Add("buy_corvette", SpawnCarCorvette) function SpawnCarMurcielago(ply, ent) if not ply:CanAfford(250000) then Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "car")) return "" else ply:AddMoney(-250000) local Murcielago = ents.Create("prop_vehicle_jeep") Murcielago:SetModel("models/sickness/murcielago.mdl") Murcielago:SetKeyValue("vehiclescript", "scripts/vehicles/murcielago.txt") Murcielago:SetPos(table.Random(CarMurcielagoSpawn)) Murcielago.Owner = Murcielago:Own(ply) Murcielago:Spawn() Murcielago:Activate() end end concommand.Add("buy_murcielago", SpawnCarMurcielago) function SpawnCarBMW(ply, ent) if not ply:CanAfford(55000) then Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "car")) return "" else ply:AddMoney(-55000) local BMW = ents.Create("prop_vehicle_jeep") BMW:SetModel("models/sickness/bmw-m5.mdl") BMW:SetKeyValue("vehiclescript", "scripts/vehicles/BMW.txt") BMW:SetPos(table.Random(CarBMWSpawn)) BMW.Owner = BMW:Own(ply) BMW:Spawn() BMW:Activate() end end concommand.Add("buy_bmw", SpawnCarBMW) function SpawnCarHummer(ply, ent) if not ply:CanAfford(75000) then Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "car")) return "" else ply:AddMoney(-75000) local Hummer = ents.Create("prop_vehicle_jeep") Hummer:SetModel("models/sickness/hummer-h2.mdl") Hummer:SetKeyValue("vehiclescript", "scripts/vehicles/hummer.txt") Hummer:SetPos(table.Random(CarHummerSpawn)) Hummer.Owner = Hummer:Own(ply) Hummer:Spawn() Hummer:Activate() end end concommand.Add("buy_hummer", SpawnCarHummer) function SpawnCarSpyder(ply, ent) if not ply:CanAfford(80000) then Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "car")) return "" else ply:AddMoney(-80000) local Spyder = ents.Create("prop_vehicle_jeep") Spyder:SetModel("models/sickness/360spyder.mdl") Spyder:SetKeyValue("vehiclescript", "scripts/vehicles/Spyder.txt") Spyder:SetPos(table.Random(CarSpyderSpawn)) Spyder.Owner = Spyder:Own(ply) Spyder:Spawn() Spyder:Activate() end end concommand.Add("buy_Spyder", SpawnCarSpyder) --[[ Copy function SpawnCar(name)(ply, ent) to: concommand.Add("buy_(name)", SpawnCar(name) Change the settings to whatever you want. Now go abit up, where you see many tables. copy it: local Car(name)Spawn = { } Car(name)Spawn[ 1 ] = Vector( TYPE NUMBERS HERE ) Car(name)Spawn[ 2 ] = Vector( ) Car(name)Spawn[ 3 ] = Vector( ) Car(name)Spawn[ 4 ] = Vector( ) Car(name)Spawn[ 5 ] = Vector( ) Car(name)Spawn[ 6 ] = Vector( ) go in-game and find a position for the car, type getpos in console, and copy the numbers after setpos. Not the ones with setang. then type it in Vector. --]] [/CODE] Thanks, --------- --------- ImNotLoved & The rest of the Undisclosed Gaming community
What's with all of the: [lua] <Car Name>.Owner = -- Nothing is here. [/lua]
In my opinion, this is not the best way to go about spawning NPCs =P But oh well. That is neither here nor there. It is a little hard to decipher exactly what is happening in your code, I get the feeling your "F4 menu" is making some other function calls that aren't represented in your post. Either way, where are you actually creating the entity? The class you use is very important - make sure you have something like [lua] ents.Create("npc_citizen"); [/lua] somewhere. If you are using the wrong class type, your npc will not spawn at all. Also make sure you are actually spawning it somewhere. Like I said, I am sure there is a lot of missing code. If you could add more relevant snippets, we could help you out better =) [b]Edit[/b] [QUOTE=Chessnut;35298303]What's with all of the: [lua] <Car Name>.Owner = -- Nothing is here. [/lua][/QUOTE] Good question... Address Chessnut's point first =P That might be a larger issue with the spawning system!
To make an entity spawn at a specific vector when the map loads, you want to do it after the map as well as it entities are fully initialized. There is a hook for that, actually: [b][url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexa2bf.html?title=Gamemode.InitPostEntity&oldid=33015]Gamemode.InitPostEntity [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]. Of course inside that hook I assume you know what to do; SetPos(), Spawn(), Activate(), all that jazz.
We will look into that saint devil, Thanks. The code you see above is the NPC that let's you buy cars from it . Right now it is any ENT that admins can spawn only and we want to have the NPC spawn when the server restart/map change and so on. Thanks, The Undisclosed management.
Sorry, you need to Log In to post a reply to this thread.