• Please HELP NPC SHOP CARS WONT SPAWN. :)
    8 replies, posted
Hey guys im having problems with my cars showing up in the menu but when i click the purchase button the car doesn't spawn. Error message in console: I got 2 errors becuase i tried buying the expensive and and the cheap car. [url]http://imgur.com/egMpeCf[/url] [lua] /* Only change stuff in here! */ NPCSHOP = NPCSHOP or {} NPCSHOP.CarSpawn = {} NPCSHOP.NPCSpawn = {} /* Edit stuff below this line ************************** */ // Model of the NPC, can be changed to whatever you want, as long as it follows this path of models/<modelname>.mdl NPCSHOP.NPCModel = "models/vortigaunt.mdl" //Position of the NPC, in YOUR console, type getpos to get positioning co-ordinates NPCSHOP.NPCSpawn["rp_downtownv4c_v2"] = { pos = Vector(1779, -4483, -134), //Same co-ordinates used for the config file ang = Angle(5, -92, 0) } //Position for the carspawn NPCSHOP.CarSpawn["rp_downtownv4c_v2"] = { { pos = Vector(1779, -4483, -134), ang = Angle(5.091251, -92.267975, 0.000000) }, } //Which ULX usergroups are considered "VIP" NPCSHOP.UserGroups = {"vip", "admin"} /* Add vehicles here. The jobrestriction is abit wonky, in darkrp you can just do like {TEAM_POLICE, TEAM_CHIEF, TEAM_MAYOR} but it doesn't really work the same here. Jobrestriction is put with {1,2,3} where 1, 2 and 3 are the team numbers of those teams, in order to get the team numbers, just go ingame, open console using F11 and type "lua_run_cl print(TEAM_CITIZEN)" which will give you the team number for citizen. You can also get the teamnumber of your current team by typing "lua_run_cl print(LocalPlayer():Team())" If you add or remove darkrp teams, this process (in some cases) have to be done again! NPCSHOP.AddVehicle(name, class, model, price, jobrestriction, viponly) name: Name of the vehicle in the npcshop menu class: Vehicle-class of the vehicle. Use "rp_getvehicles" to find these. model: Model which will appear in the npcshop menu price: How much it costs jobrestriction: What jobs will be able to buy this (type nil if its available to all jobs) viponly: Is this vehicle only available for VIP's? true/false Display name > Class (rp_getvehicles in console) > Model directory > Price > Jobs > VIP/Not VIP - False = Not VIP, True = VIP */ NPCSHOP.AddVehicle("audir8", "audir8tdm", "models/tdmcars/audir8.mdl" , 50000, nil, false) NPCSHOP.AddVehicle("350z", "350ztdm", "models/tdmcars/350z.mdl" , 100, nil, false) [/lua] The reason the 350z price is low i was just testing to see if maybe i didnt have enough money
delete the space between the " and , near the price. See if that works.
[QUOTE=MysticBoogie;42093118]delete the space between the " and , near the price. See if that works.[/QUOTE] Since it says the error is in this file can someone take a look at it? [lua]if not SERVER then return end util.AddNetworkString( "npcshop_senddata" ) function SpawnnpcShop() local shop = ents.Create("npc_shop") shop:SetPos( Vector(1779, -4483, -134) ) shop:SetAngles( Angle(5, -92, 0) ) shop:Spawn() shop:DropToFloor() end hook.Add("InitPostEntity", "SpawnnpcShop", SpawnnpcShop) hook.Add("EntityTakeDamage", "PReventNPCfromdying", function( target, dmginfo ) if target:IsNPC() and target:GetClass() == "npc_shop" then dmginfo:ScaleDamage(0) end end) local function IsVIP(ply) local isvip = false for k,v in pairs(NPCSHOP.UserGroups) do if ply:GetUserGroup() == v then isvip = true break end end return isvip end //Utilizes darkrp's notify local function Notify(ply, text) if not IsValid(ply) then return end umsg.Start("_Notify", ply) umsg.String(text) umsg.Short(0) umsg.Long(4) umsg.End() end local function SaveVehicles() local str = util.TableToJSON(NPCSHOP.PlayerVehicles) file.Write( "npcshopsaves.txt", str ) end local function LoadVehicles() local str = file.Read( "npcshopsaves.txt", "DATA" ) or "[]" NPCSHOP.PlayerVehicles = util.JSONToTable(str) end LoadVehicles() function SendVehicles(ply) local sid = ply:SteamID() local cars = NPCSHOP.PlayerVehicles[sid] or {} net.Start("npcshop_senddata") net.WriteTable(cars) net.Send(ply) end hook.Add("PlayerInitialSpawn", "plyinitspawnnpcshop", function(ply) timer.Simple(2, function() SendVehicles(ply) end) end) local meta = FindMetaTable("Player") function meta:AddVehicle( class ) local sid = self:SteamID() if not NPCSHOP.PlayerVehicles[sid] then NPCSHOP.PlayerVehicles[sid] = {} end NPCSHOP.PlayerVehicles[sid][class] = true SaveVehicles() SendVehicles(self) end local function SpawnVehicle(ply, class) if not NPCSHOP.VehicleLookup[class] then return end if not NPCSHOP.Vehicles[NPCSHOP.VehicleLookup[class]] then return end if IsValid(ply.currentcar) then local d = ply.currentcar:GetDriver() if IsValid(d) and d != ply then Notify(d, "The owner of this car has removed it!") end ply.currentcar:Remove() end 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 carspawns = NPCSHOP.CarSpawn[game.GetMap()] local pos = carspawns[1].pos local ang = carspawns[1].ang for k,tbl in pairs(carspawns) do local p,a = tbl.pos, tbl.ang local entslist = ents.FindInBox(Vector(p.x + 100, p.y + 100, p.z - 20), Vector(p.x - 100, p.y - 100, p.z + 150)) if #entslist == 0 then pos = p ang = a break end end car:SetPos(pos) car:SetAngles(ang) car:Spawn() car:Activate() car.SID = ply.SID car.ClassOverride = vehicle.Class if vehicle.Members then table.Merge(car, vehicle.Members) end car:Own(ply) gamemode.Call("PlayerSpawnedVehicle", ply, car) ply.currentcar = car end concommand.Add("_npcshopbtnclick", function(ply, _, args) if #args != 1 then return end if not IsValid(ply) then return end if ply:GetPos():Distance(ents.FindByClass("npc_shop")[1]:GetPos()) > 80 then return end local class = args[1] if not NPCSHOP.VehicleLookup[class] then return end if not NPCSHOP.Vehicles[NPCSHOP.VehicleLookup[class]] then return end local cltbl = NPCSHOP.Vehicles[NPCSHOP.VehicleLookup[class]] if #cltbl.job > 0 then if not table.HasValue(cltbl.job, ply:Team()) then Notify(ply, "You're not in the correct job to spawn/purchase this!") return end end if ply:OwnsVehicle(class) then SpawnVehicle(ply, class) return end if cltbl.viponly and not IsVIP(ply) then Notify(ply, "This vehicle is VIP only!") return end if not ply:CanAfford(cltbl.price) then Notify(ply, "You can not afford that!") return end ply:AddMoney(-cltbl.price) Notify(ply, "You've bought the '" .. cltbl.name .. "' for "..(CUR or "$")..(cltbl.price).."!") ply:AddVehicle(class) umsg.Start("_updatenpcshopgui", ply) umsg.String(class) umsg.End() end) // DarkRP doesn't give me any way to check for job changes, then this shit is needed! local bkp = meta.SetTeam meta.SetTeam = function(self, job) bkp(self, job) if IsValid(self.currentcar) then local class = self.currentcar.VehicleName local cltbl = NPCSHOP.Vehicles[NPCSHOP.VehicleLookup[class]] if #cltbl.job > 0 then if not table.HasValue(cltbl.job, self:Team()) then self.currentcar:Remove() Notify(self, "Your current car isn't allowed for your new job!") return end end end end [/lua]
wrong. its trying to call the method CanAfford but something is wrong so it comes back as a nil value, causing the error.
So what do i do someone please help. :)
If you're using the new version of DarkRP you should replace CanAfford with canAfford
[QUOTE=ms333;42095350]If you're using the new version of DarkRP you should replace CanAfford with canAfford[/QUOTE] Thanks now atleast it lets me buy them but when i try to deploy them the car doesnt spawn and another error in console appears. ERROR: [url]http://imgur.com/zMxqCnD[/url] Lines 107-118 [lua] local carspawns = NPCSHOP.CarSpawn[game.GetMap()] local pos = carspawns[1].pos local ang = carspawns[1].ang for k,tbl in pairs(carspawns) do local p,a = tbl.pos, tbl.ang local entslist = ents.FindInBox(Vector(p.x + 100, p.y + 100, p.z - 20), Vector(p.x - 100, p.y - 100, p.z + 150)) if #entslist == 0 then pos = p ang = a break end end[/lua]
You wrote rp_downtownv4c_v2 as map name in your config file.
[QUOTE=ms333;42095687]You wrote rp_downtownv4c_v2 as map name in your config file.[/QUOTE] haha i cant believe i didn't notice that Thanks man. :) do you know how to make it so players can only spawn one car at a time and when it spawn to automatically be theirs (for it to say their name instead on saying press f2 to buy the car)
Sorry, you need to Log In to post a reply to this thread.