• What am I doing wrong? (ent.Create)
    2 replies, posted
I googled this AND tried searching page after page on Facepunch, I have made an NPC in Singleplayer that sells vehicles and spawns them using ent.Create, works perfectly fine in SinglePlayer. I uploaded it onto the server and tried it, first I was getting the error caused by the fact I hadn't forced it to run serversidely, rather than on whatever it was trying to, so I added if (SERVER) then, and closed it off etc. But now I don't get any errors, I get nothing... It just won't spawn :| [CODE]concommand.Add("buy_car", function (ply, com, args, full) if (SERVER) then if #args < 3 then ply:ChatPrint("You have not supplied enough detail") return end local script = args[1] local model = args[2] local price = args[3] local car=ents.Create("prop_vehicle_jeep") car:SetKeyValue("vehiclescript", script) car:SetModel(model) car:SetAngles(Angle(0, 90, 0)) car:Own(ply) car.Owner = ply car:KeysLock() car:SetPos(ply:GetPos() + Vector(0,300,10)) car:Spawn() ply:AddMoney(-price) end end) [/CODE] And when I get rid of the if (SERVER) then etc, I get. [CODE][ERROR] ...modes/darkrp/entities/entities/npc_car_dealer/shared.lua:38: attempt to call field 'Create' (a nil value) 1. unknown - ...modes/darkrp/entities/entities/npc_car_dealer/shared.lua:38 2. unknown - lua/includes/modules/concommand.lua:69 [/CODE] It works fine in singleplayer.
Hi, Try this code : [code]function buycar( ply ) local script = args[1] local model = args[2] local price = args[3] buycar = ents.Create("prop_vehicle_jeep") buycar:SetModel( model ) buycar:SetKeyValue("vehiclescript", script) buycar:SetAngles(Angle(0, 90, 0)) buycar:Own(ply) buycar.Owner = ply buycar:SetPos( ply:GetPos() + Vector(0,300,10) ) buycar:KeysLock() buycar:Spawn() ply:AddMoney( - price ) end concommand.Add("buy_car", function (ply, com, args, full)[/code] Not sure if this code will work, just try
[QUOTE=Didileking;39216001]Hi, Try this code : [code]function buycar( ply ) local script = args[1] local model = args[2] local price = args[3] buycar = ents.Create("prop_vehicle_jeep") buycar:SetModel( model ) buycar:SetKeyValue("vehiclescript", script) buycar:SetAngles(Angle(0, 90, 0)) buycar:Own(ply) buycar.Owner = ply buycar:SetPos( ply:GetPos() + Vector(0,300,10) ) buycar:KeysLock() buycar:Spawn() ply:AddMoney( - price ) end concommand.Add("buy_car", function (ply, com, args, full) [B]end)[/B][/code] Not sure if this code will work, just try[/QUOTE] I gave it a shot, and unfortunately it didn't work.
Sorry, you need to Log In to post a reply to this thread.