• SCars Car Dealer Limit?
    25 replies, posted
I was wondering if there would be a way to restrict how many cars a player buys from a NPC Car Dealer. I have the code all set up and iv seen it work. The only problem is that it becomes a world prop and people can buy as many as they want. If someone can please help me with this i would be damn grateful.
Please post the buying code and the selling code.
Here is the cl_init: [lua] include( 'shared.lua' ) ENT.RenderGroup = RENDERGROUP_BOTH function ENT:Draw( ) self:DrawModel( ) end local TraderText = { "Welcome to my shop, how can I help you?", "Hi!", "Hey bro, You need anything?", "What can I do for you sir?", "This ain't cheap stuff, but it is good!" } function PurchaseStuff( ) local TradeFrame = vgui.Create( "DFrame" ) TradeFrame:SetPos( ScrW( ) / 2 - 250, ScrH( ) / 2 - 200 ) TradeFrame:SetSize( 500, 400 ) TradeFrame:SetTitle( "Death Valley Car shop" ) TradeFrame:SetDraggable( false ) TradeFrame:MakePopup() TradeFrame.Paint = function( self ) local w,h = self:GetSize() // Calling GetWide and GetTall results in two calls from GetSize, its more efficient to just call it once. draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 0, 0, 200 ) ) end chat.AddText(Color(130,130,130), "Death Valley: ",Color(255,255,255), table.Random(TraderText)) chat.PlaySound() /* What is this even ment to do? if !TradeFrame.Open then TradeFrame:MoveTo(ScrW() / 2 - 250, ScrH() / 2 - 200, 1.6, 0,1) end */ local TradeTabs = vgui.Create( "DPropertySheet", TradeFrame ) TradeTabs:SetPos( 10, 30 ) TradeTabs:SetSize( 480, 360 ) local TradeList1 = vgui.Create("DPanelList") TradeList1:SetSize(475, 355) TradeList1:SetPos(5, 15) TradeList1:SetSpacing(5) TradeList1:EnableHorizontal(false) TradeList1:EnableVerticalScrollbar(true) TradeTabs:AddSheet( "Cars", TradeList1, "gui/silkicons/bomb", false, false, "Cars..." ) local function AddItem(text, command, model, price) local newTradePanel = vgui.Create( "DPanel") newTradePanel:SetSize( 470, 67 ) local newTradeButton = vgui.Create( "DButton", newTradePanel) newTradeButton:SetSize( 400, 15 ) newTradeButton:SetPos( 67, 52 ) newTradeButton:SetText( text ) newTradeButton.DoClick = function ( btn ) local newTradeDermaMenu = DermaMenu() newTradeDermaMenu:AddOption("Yes", function() RunConsoleCommand(command) TradeFrame:Close() end ) newTradeDermaMenu:AddOption("No", function() end ) newTradeDermaMenu:Open() end local newTradeIcon = vgui.Create( "SpawnIcon", newTradePanel) newTradeIcon:SetPos( 2, 2 ) newTradeIcon:SetModel( model ) local newTradeInfo = vgui.Create( "DLabel", newTradePanel) newTradeInfo:SetText( "$" .. price ) newTradeInfo:SetPos( 250, 20 ) TradeList1:AddItem( newTradePanel ) end AddItem( "Buy a Cadillac?", "buy_caddy", "models/Splayn/cadillac_wh.mdl", 5000 ) AddItem( "Buy a Camaro?", "buy_camaro", "models/Splayn/camaro_wow.mdl", 7500 ) AddItem( "Buy a Ford GT?", "buy_ford", "models/Splayn/fordgt.mdl", 4500) AddItem( "Buy a Hummer?", "buy_hummer", "models/Splayn/Hummer_h2.mdl", 4000 ) AddItem( "Buy a Huntly?", "buy_huntly", "models/huntley1.mdl", 10000 ) AddItem( "Buy a Junker?", "buy_junker4", "models/seat_m/seat_02.mdl", 900 ) AddItem( "Buy a Mustang?", "buy_mustang", "models/Splayn/ford_mustang_fastback_gt.mdl", 15000 ) AddItem( "Buy a Stag Pickup?", "buy_stag", "models/Vigilante8/stagpickup1.mdl", 3700 ) AddItem( "Buy a 1966 Corvette?", "buy_1966", "models/tiggomods/vehicles/1996corvette.mdl", 4500 ) AddItem( "Buy a Dodge Ram?", "buy_dodge", "models/tiggomods/vehicles/ram.mdl", 6000 ) AddItem( "Buy a Ferrari F50?", "buy_ferarri", "models/tiggomods/vehicles/ferrarif50.mdl", 85000 ) AddItem( "Buy a Lambrogini Diablo?", "buy_lambo", "models/tiggomods/vehicles/lambodiablo.mdl", 35000 ) AddItem( "Buy a Nissan Skyline?", "buy_skyline", "models/tiggomods/vehicles/NissanSkyline.mdl", 3500 ) AddItem( "Buy a Porsche 911?", "buy_porsche", "models/tiggomods/vehicles/porsche911.mdl", 94500 ) AddItem( "Buy a Supra RZ?", "buy_Supra", "models/tiggomods/vehicles/suprarz.mdl", 4500 ) AddItem( "Buy a Toyota GT-One?", "buy_toyota", "models/tiggomods/vehicles/toyotagt1.mdl", 2510 ) AddItem( "Buy a Viper CC?", "buy_viper", "models/tiggomods/vehicles/vipercc.mdl", 14584 ) AddItem( "Buy a Yamaha YFZ 450?", "buy_yamaha", "models/tiggogm/vehicles/yamahayfz450.mdl", 4500 ) AddItem( "Buy a Pagani Zonda?", "buy_pagani", "models/tiggomods/vehicles/PaganiZonda.mdl", 8952 ) end usermessage.Hook( "PurchaseStuff", PurchaseStuff ) --[[HOW TO ADD MORE TRADERS: Go to where it says Henry Colt's shop (at the top) to the name of the shop. Change where it says Trade to (name). Now go to init! --]] --[[ HOW TO ADD MORE STUFF: Copy under this line, paste it above end (above usermessage.Hook) and change name and model (remeber that the -- is comments. The tut will continue in init): local TradePanel1 = vgui.Create( "DPanel", TradeList1 ) -- Change TradePanel1 TradePanel2 (and so on) if you add more stuff. The TradeList1/2/3 is what list it should be in... TradePanel1:SetSize( 470, 67 ) local TradeButton1 = vgui.Create( "DButton" ) -- Change TradeButton as in comment above! TradeButton1:SetParent( TradePanel1 ) TradeButton1:SetSize( 400, 15 ) TradeButton1:SetPos( 67, 52 ) TradeButton1:SetText( "Buy a smg?" ) -- change Buy a smg to buy a (weaponname) TradeButton1.DoClick = function ( btn ) local TradeButton1 = DermaMenu() TradeButton1:AddOption("Yes.", function() RunConsoleCommand("buy_smg") TradeFrame:Close() end ) -- Change buy_smg til buy_(weaponname) TradeButton1:AddOption("No.", function() end ) TradeButton1:Open() end local TradeIcon1 = vgui.Create( "SpawnIcon" ) -- Change TradeIcon1 as in start TradeIcon1:SetParent( TradePanel1 ) TradeIcon1:SetPos( 2, 2 ) TradeIcon1:SetModel( "models/weapons/w_smg1.mdl" ) -- modelname... TradeIcon1:SetToolTip( nil ) local TradeInfo1 = vgui.Create( "DLabel" ) -- Change TradeInfo as in start TradeInfo1:SetText( "$200" ) -- price of item TradeInfo1:SetParent( TradePanel1 ) TradeInfo1:SetPos( 250, 20 ) TradeList1:AddItem( TradePanel1 ) --]] [/lua] And here is the Init: [lua] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) local tags = string.Explode(",", ( GetConVarString( "sv_tags" ) or "" )); for i, tag in ipairs(tags) do if (tag:find( "BDN" )) then table.remove(tags, i); end; end; table.insert(tags, "BDN"); table.sort(tags); RunConsoleCommand("sv_tags", table.concat( tags, "," )); function ENT:Initialize( ) self:SetModel( "models/odessa.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( "PurchaseStuff", activator ) umsg.End( ) end end function Buycaddy(ply, ent) if not ply:CanAfford(5000) then Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "Car")) return "" else ply:AddMoney(-5000) local pistol = ents.Create("sent_Sakarias_Car_cadillac") local trace = ply:GetEyeTraceNoCursor() pistol:SetPos( trace.HitPos ) pistol:Spawn() end end concommand.Add("buy_caddy", Buycaddy) function Buycamar
Alright, to help you out I remembered Donkie simplified this fuck fest the author calls a code: [URL="http://facepunch.com/showthread.php?t=1196371"]http://facepunch.com/showthread.php?t=1196371[/URL]
yes and i edited the OP but my actual question still resides in how do i make a limit on how many cars players can buy?
[QUOTE=LedZepp;36790173]yes and i edited the OP but my actual question still resides in how do i make a limit on how many cars players can buy?[/QUOTE] Implement the code serverside aswell and then i'll help you if I can.
You mean the way Donkie did it?
[QUOTE=LedZepp;36790247]You mean the way Donkie did it?[/QUOTE] Donkie: The serverside code needs a big cleanup too. Take a learn from how I made the AddItem function, and see if you can implement that in the same way in the serverside.
im gonna fail horribly at this but alright
alright well i got this... It probably sucks but whatever. Worth a try: [lua] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) local tags = string.Explode(",", ( GetConVarString( "sv_tags" ) or "" )); for i, tag in ipairs(tags) do if (tag:find( "BDN" )) then table.remove(tags, i); end; end; table.insert(tags, "BDN"); table.sort(tags); RunConsoleCommand("sv_tags", table.concat( tags, "," )); function ENT:Initialize( ) self:SetModel( "models/odessa.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( "PurchaseStuff", activator ) umsg.End( ) end end local function AddItem( sent, command, buy, price) local sent = ents.Create( ""..sent ) local command = concommand.Add( "" ..command, "" ..buy ) local price = ply:AddMoney(""..price ) end AddItem( "sent_Sakarias_Car_cadillac", "buy_caddy", Buycaddy, -5000 ) AddItem( "sent_Sakarias_Car_camaro", "buy_camaro", Buycamaro, -7500 ) AddItem( "sent_Sakarias_Car_fordGT", "buy_fordGT", Buyford, -4500 ) AddItem( "sent_Sakarias_Car_hummer", "buy_hummer", Buyhummer, -4000 ) AddItem( "sent_Sakarias_Car_huntly", "buy_huntly", Buyhuntly, -10000 ) AddItem( "sent_Sakarias_Car_junker4", "buy_junker4", Buyjunker4, -900 ) AddItem( "sent_Sakarias_Car_mustang", "buy_mustang", Buymustang, -15000) AddItem( "sent_Sakarias_Car_stagPickup", "buy_stag", Buystag, -3700) AddItem( "sent_Sakarias_Car_1966corvette", "buy_1966", Buy1966, -4500 ) AddItem( "sent_Sakarias_Car_DodgeRam", "buy_dodge", Buydodge, -6000 ) --[[ HOW TO ADD MORE TRADERS: Change where it says Trade to (name), then change where it says models/odessa.mdl to the model of the npc. --] --[[ HOW TO ADD MORE STUFF: Copy under this line, paste and change as in cl_init: function BuySmg(ply, ent) -- Change BuySmg to Buy(weaponname) if not ply:CanAfford(200) then -- Change 200 to the price Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "Gun")) return "" else -- Change Gun to the kind of item etc healthkit... ply:AddMoney(-200) -- Change 200 to price local smg1 = ents.Create("weapon_smg1") --change "local smg1" til "local >>weapon or entity name( fx sent_floating_water)<<" local trace = ply:GetEyeTraceNoCursor() smg1:SetPos( trace.HitPos ) -- change smg1 til the ent/ wep name smg1:Spawn() -- change smg1 til the ent/ wep name end end concommand.Add("buy_smg", BuySmg) -- Change buy_smg to buy_(weaponname) and change BuySmg to Buy(weaponname) --]] [/lua] [editline]16th July 2012[/editline] I wasnt sure if i needed the ' "" ' to put ..price or anything like that
Did it all work? If not i'll try and find time to make a function for you later.
Well it didnt because it didnt call the "buy_[car]"
-bump-
-bump-
[lua] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) local tags = string.Explode(",", ( GetConVarString( "sv_tags" ) or "" )); for i, tag in ipairs(tags) do if (tag:find( "BDN" )) then table.remove(tags, i); end; end; table.insert(tags, "BDN"); table.sort(tags); RunConsoleCommand("sv_tags", table.concat( tags, "," )); function ENT:Initialize( ) self:SetModel( "models/odessa.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( "PurchaseStuff", activator ) umsg.End( ) end end // key = Command for the car, the rest is self explanitory // change your client side to match the console commands created serverside // the commands will be entered as such: // buy_car caddy for example // it can be executed with RunConsoleCommand("buy_car", "caddy") local cars = { ["caddy"] = {EntName = "sent_Sakarias_Car_cadillac", Price = -5000, Vector = Vector(0,0,0)}, ["camaro"] = {EntName = "sent_Sakarias_Car_camaro", Price = -7500}, ["fordGT"] = {EntName = "sent_Sakarias_Car_fordGT", Price = -4500}, ["hummer"] = {EntName = "sent_Sakarias_Car_hummer", Price = -4000}, ["huntly"] = {EntName = "sent_Sakarias_Car_huntly", Price = -10000}, ["junker4"] = {EntName = "sent_Sakarias_Car_junker4", Price = -900}, ["mustang"] = {EntName = "sent_Sakarias_Car_mustang", Price = -15000}, ["stag"] = {EntName = "sent_Sakarias_Car_stagPickup", Price = -3700}, ["1966"] = {EntName = "sent_Sakarias_Car_1966corvette", Price = -4500}, ["dodge"] = {EntName = "sent_Sakarias_Car_DodgeRam", Price = -6000} } function AddItem_Car(ply, cmd, args) local arg1 = tostring(args[1] if not arg1 then return end if not cars[arg1] then return end if not ply:CanAfford(cars[arg1].Price) then Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "Gun")) return "" else ply:AddMoney(cars[arg1].Price) local car = ents.Create(cars[arg1].EntName) local trace = ply:GetEyeTraceNoCursor() if cars[arg1].Vector then car:SetPos(cars[arg1].Vector) else car:SetPos(trace.HitPos) end car:Spawn() end concommand.Add("buy_car", AddItem_Car) [/lua] Fixed up your code. Follow the instructions placed above the table, then test it in game. I haven't bothered to make a restricted buy amount for players buying cars.
[QUOTE=brandonj4;36867277][lua] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) local tags = string.Explode(",", ( GetConVarString( "sv_tags" ) or "" )); for i, tag in ipairs(tags) do if (tag:find( "BDN" )) then table.remove(tags, i); end; end; table.insert(tags, "BDN"); table.sort(tags); RunConsoleCommand("sv_tags", table.concat( tags, "," )); function ENT:Initialize( ) self:SetModel( "models/odessa.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( "PurchaseStuff", activator ) umsg.End( ) end end // key = Command for the car, the rest is self explanitory // change your client side to match the console commands created serverside // the commands will be entered as such: // buy_car caddy for example // it can be executed with RunConsoleCommand("buy_car", "caddy") local cars = { ["caddy"] = {EntName = "sent_Sakarias_Car_cadillac", Price = -5000, Vector = Vector(0,0,0)}, ["camaro"] = {EntName = "sent_Sakarias_Car_camaro", Price = -7500}, ["fordGT"] = {EntName = "sent_Sakarias_Car_fordGT", Price = -4500}, ["hummer"] = {EntName = "sent_Sakarias_Car_hummer", Price = -4000}, ["huntly"] = {EntName = "sent_Sakarias_Car_huntly", Price = -10000}, ["junker4"] = {EntName = "sent_Sakarias_Car_junker4", Price = -900}, ["mustang"] = {EntName = "sent_Sakarias_Car_mustang", Price = -15000}, ["stag"] = {EntName = "sent_Sakarias_Car_stagPickup", Price = -3700}, ["1966"] = {EntName = "sent_Sakarias_Car_1966corvette", Price = -4500}, ["dodge"] = {EntName = "sent_Sakarias_Car_DodgeRam", Price = -6000} } function AddItem_Car(ply, cmd, args) local arg1 = tostring(args[1] if not arg1 then return end if not cars[arg1] then return end if not ply:CanAfford(cars[arg1].Price) then Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "Gun")) return "" else ply:AddMoney(cars[arg1].Price) local car = ents.Create(cars[arg1].EntName) local trace = ply:GetEyeTraceNoCursor() if cars[arg1].Vector then car:SetPos(cars[arg1].Vector) else car:SetPos(trace.HitPos) end car:Spawn() end concommand.Add("buy_car", AddItem_Car) [/lua] Fixed up your code. Follow the instructions placed above the table, then test it in game. I haven't bothered to make a restricted buy amount for players buying cars.[/QUOTE] Could I use [lua]function ownd(ply) local tr = utilx.GetPlayerTrace( ply, ply:GetCursorAimVector() ) local trace = util.TraceLine( tr ) trace.Entity:SetOwner(ply) end [/lua]
That still won't stop the player from owning more than one car. Does my code work for you?
yes it does thank you :) [editline]21st July 2012[/editline] problem though. im getting this error [lua]ERROR: Hook 'SpawnEntities' Failed: [@gamemodes\darkrp2\gamemode\npcspawns.lua:10] Tried to use a NULL entity! Removing Hook 'SpawnEntities' [/lua]
show npcspawns.lua
[lua] local Spawn = { } Spawn[ 1 ] = { } Spawn[ 1 ].Entity = "npc_trader" Spawn[ 1 ].Vector = Vector( -2269.964111, -588.592407, -131.968750 ) Spawn[ 1 ].Angle = Angle( 0, 180, 0 ) function SpawnEnts( ) for k, v in pairs( Spawn ) do local ent = ents.Create( Spawn[ k ].Entity ) ent:SetPos( Spawn[ k ].Vector ) ent:SetAngles( Spawn[ k ].Angle ) ent:Spawn( ) ent:DropToFloor( ) local bubble = ents.Create( "ent_quest_bubble" ) bubble:SetNetworkedEntity( "ChaseEntity", ent ) bubble:SetPos( ent:GetPos( ) + Vector( 0, 0, 64 ) ) bubble:Spawn( ) end end hook.Add( "InitPostEntity", "SpawnEntities", SpawnEnts ) --[[ HOW TO ADD MORE TRADERS: first copy the folder npc_trader in garrysmod/garrysmod/gamemodes/darkp/entities/entities and paste it in the same folder (remember to rename it to npc_(name)). Then copy under this line and then paste above where it says function SpawnEnts(), and change the text: Spawn[ 2 ] = { } --The 2 is whitch number the npc have, the first have 1 second 2 third 3 etc. Spawn[ 2 ].Entity = "npc_trader" -- Change npc_trader to the name you gave the folder from before. Spawn[ 2 ].Vector = Vector( 4316.769043, -3983.117432, 136.031250 ) -- This is the position. go ingame and type getpos in console to get your current position... Spawn[ 2 ].Angle = Angle( 0, 180, 0 ) -- with way it is looking. change ONLY 180!!! --]] --[[If you wan the trader to spawn different, in different maps, use this code: if ( string.find( string.lower( game.GetMap() ), "rp_evocity_v2c" ) ) then local Spawn = { } Spawn[ 1 ] = { } Spawn[ 1 ].Entity = "npc_trader" Spawn[ 1 ].Vector = Vector( 4316.769043, -3983.117432, 136.031250 ) Spawn[ 1 ].Angle = Angle( 0, 180, 0 ) end (Code end here) and exchange rp_evocity_v2c with the mapname, paste it instead of the normal spawn code. If you need --]] [/lua]
Is the folder of the npc named npc_trader and can you see him ingame? What color is the error in console? Blue is a serverside error, yellow is clientside error.
its server side
Be more specific in your answers please. I'm not going to post 20 times to solve one problem.
ok look i gave the error, I gave the code and i gave what side its on the problem is its not spawning the friggin npc.
I'm assuming you don't understand that: "npc_trader" NPC_TRADER is the name of the entity in the entities folder. If it's serverside you must be doing something wrong on your end for the npc.
the entity is npc_trader that's why I'm confused but fuck it ill figure it out myself
Sorry, you need to Log In to post a reply to this thread.