• At Wits End - Spawn an addon vehicle
    4 replies, posted
I've been trying to create a derma panel button that spawns an addon (photon and SGM vehicle to be precise). I've literally spent the last 6 hours on this. I've been searching, googling and found a few things. Keep in mind, it's not just one addon, it's ALL of them I can't figure out. I was able to do this after MANY hours to spawn custom npc and I figured it would be a similar process. from the developer of the mod: [url]http://facepunch.com/showthread.php?t=1436368[/url] I found this : [CODE]local ent = ents.Create("prop_vehicle_jeep") -- all your entity setting up goes here if youWantThisAsAPhotonCar then ent.VehicleTable = list.Get("Vehicles")["photonnameyouwant"] end ent:Spawn()[/CODE] [CODE]local ent = ents.Create ("prop_vehicle_jeep") ent:SetModel ("models/sentry/caison_fire.mdl") ent:SetPos(hit) if "Caison Fire Truck" then ent.VehicleTable = list.Get("Vehicles")["Emergency Vehicles"] //have to pull up the correct vehicle for the photon script to work end ent:Spawn()[/CODE] Right now this is as far as I can get on my own. [url]http://facepunch.com/showthread.php?t=1461475&highlight=VehicleTable[/url] has this code : [CODE]local function SpawnVehicle(ply, class) local vehicle = list.Get("Vehicles")[class] if not vehicle then return end local car = ents.Create(vehicle.Class) if not car then return end car:SetModel(vehicle.Model) if vehicle.KeyValues then for k, v in pairs(vehicle.KeyValues) do car:SetKeyValue(k, v) end end car.VehicleName = class car.VehicleTable = vehicle car.Owner = ply local pos = Vector(0,0,0) local ang = Angle(0,0,0) car:SetPos(pos) car:SetAngles(ang) car:Spawn() car:Activate() car:SetCollisionGroup(COLLISION_GROUP_WEAPON) car.ClassOverride = vehicle.Class if vehicle.Members then table.Merge(car, vehicle.Members) end gamemode.Call("PlayerSpawnedVehicle", ply, car) end[/CODE] With help, I've been able to get a long output of the vehicle table that contains some information as a txt file but I do not know what the table names are actually called and where everything goes. EDIT : Right now I should mention none of these resources are in my gamemode mode directory because they are still in the root folder for garrysmod. That shouldn't matter correct?
why hello sir try this: [code] ent.VehicleTable = list.Get("Vehicles")["Caison Fire Truck"] [/code] The "Caison Fire Truck" text needs to be the name of the vehicle. To explain, the Vehicles table is a table of all the vehicles Sandbox uses in the Spawn Menu. The text afterwards (Caison Fire Truck in this case) is the table's index/key. In order for a vehicle to be registered in sandbox, it adds its own index into the Vehicles table with all the appropriate parameters. Photon rides on this technique to throw in the additional Photon information as a single model can be outfitted with different Photon parameters. Not an ideal circumstance, but it works for right now.
[QUOTE=iSchmal;48315786]why hello sir try this: [code] ent.VehicleTable = list.Get("Vehicles")["Caison Fire Truck"] [/code] The "Caison Fire Truck" text needs to be the name of the vehicle. To explain, the Vehicles table is a table of all the vehicles Sandbox uses in the Spawn Menu. The text afterwards (Caison Fire Truck in this case) is the table's index/key. In order for a vehicle to be registered in sandbox, it adds its own index into the Vehicles table with all the appropriate parameters. Photon rides on this technique to throw in the additional Photon information as a single model can be outfitted with different Photon parameters. Not an ideal circumstance, but it works for right now.[/QUOTE] Wow, thanks for replying man, this made my day. after dealing with some stack overflows, this is as minimal of an error that I can get from console: [QUOTE][Photon] No .VehicleTable present, assuming models/sentry/caison_fire.mdl is a(n) Ford C-Series Firetruck.[/QUOTE] Does it give you any ideas? I tried swapping "Ford C-Series Firetruck" to the IF statement but no change. [editline]28th July 2015[/editline] [QUOTE=Blakestr;48315971] Does it give you any ideas? I tried swapping "Ford C-Series Firetruck" to the IF statement but no change.[/QUOTE] Progress. Apparently there was SUPPOSED to be a SPACE at the end of the "Caisons Fire Truck ". (see?) Now I can drive it but it still spawns without photon and isn't colored right... EDIT: WTF is [QUOTE]"Bad pstudiohdr in GetSequenceLinearMotion()!" [/QUOTE] [editline]28th July 2015[/editline] I'm not giving up on this. This error message: [QUOTE][ERROR] 339648087/lua/autorun/photon/sh_photon_vehicles.lua:5: bad argument #1 to 'tostring' (value expected) 1. tostring - [C]:-1 2. RecoverVehicleTable - addons/photon_lighting_engine_[beta]_339648087/lua/autorun/photon/sh_photon_vehicles.lua:5 3. unknown - addons/photon_lighting_engine_[beta]_339648087/lua/autorun/photon/sh_photon_vehicles.lua:37 Timer Failed! [189-PHOTON-13.349999427795][@addons/photon_lighting_engine_[beta]_339648087/lua/autorun/photon/sh_photon_vehicles.lua (line 29)] [/QUOTE] Anyone?
[QUOTE][Photon] No .VehicleTable present, assuming models/sentry/caison_fire.mdl is a(n) Ford C-Series Firetruck.[/QUOTE] Hmm, so this is the fallback message as I'm sure you guessed. The latest error you posted would happen when Photon can't find a vehicle table and tries to pull the model name but GetModel is failing for some reason. Maybe add ent:Activate() below the ent:Spawn()? Also unrelated but just so you know [code]if "Caison Fire Truck" then[/code] will always evaluate to true because Lua interprets any string as being true, and there isn't any real conditional you're setting up, as opposed to [code]if vehicleName == "Caison Fire Truck" then[/code]. But that aside, you don't need to wrap that in an if statement at all. If none of that makes sense you can post your code block you have atm and I'll take a look.
[QUOTE=iSchmal;48320338]Hmm, so this is the fallback message as I'm sure you guessed. The latest error you posted would happen when Photon can't find a vehicle table and tries to pull the model name but GetModel is failing for some reason. Maybe add ent:Activate() below the ent:Spawn()? Also unrelated but just so you know [code]if "Caison Fire Truck" then[/code] will always evaluate to true because Lua interprets any string as being true, and there isn't any real conditional you're setting up, as opposed to [code]if vehicleName == "Caison Fire Truck" then[/code]. But that aside, you don't need to wrap that in an if statement at all. If none of that makes sense you can post your code block you have atm and I'll take a look.[/QUOTE] Again, THANK YOU for checking back on this. However, it is still a model and not drivable or photoned. Error messsage from console. [QUOTE][ERROR] 339648087/lua/autorun/photon/sh_photon_vehicles.lua:5: bad argument #1 to 'tostring' (value expected) 1. tostring - [C]:-1 2. RecoverVehicleTable - addons/photon_lighting_engine_[beta]_339648087/lua/autorun/photon/sh_photon_vehicles.lua:5 3. unknown - addons/photon_lighting_engine_[beta]_339648087/lua/autorun/photon/sh_photon_vehicles.lua:37 Timer Failed! [197-PHOTON-1534.2149658203][@addons/photon_lighting_engine_[beta]_339648087/lua/autorun/photon/sh_photon_vehicles.lua (line 29)] [/QUOTE] Below is as far as I can get. This actually spawns a RED model (versus always being white). [CODE]local ent = ents.Create ("prop_vehicle_jeep") local car = ents.Create ("prop_vehicle_jeep") ent:SetModel ("models/sentry/caison_fire.mdl") ent:SetPos(hit) ent.VehicleTable = list.Get("Vehicles")["Caison Fire Truck "] ent:Spawn() ent:Activate() [/CODE] [B]IMPORTANT[/B] (possibly) : Where should the photon and car models packs be located. Is it okay if I have them just as GMA's and [B]NOT[/B] in my gamemode or referenced in any of my gamemode lua files? Or do I need to take elements and ADDCSLUA / include them for this to work? (That might be why it continually fails) Secondary, I ran [CODE] lua_run for k,v in pairs(list.Get("Vehicles")) do print(k,v.Name) end [/CODE] an found the actual table name table: 0x347fa2c8. I have no clue whether that is something I can (or even SHOULD) reference as a way to get around this tostring error I get. Maybe it's just a path issue where I have the files stored. In any event, again, [B]THANK YOU[/B] I have only been activalying learning lua over the past 2 weeks, mainly by googling, searching the forums and reading previous posters problems and solutions, and posting questions when I was absolutely stuck. Having someone experience chime in makes a world of difference.
Sorry, you need to Log In to post a reply to this thread.