Advertisement
Guest User

Untitled

a guest
May 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.68 KB | None | 0 0
  1. require("datastream")
  2. require("glon")
  3.  
  4. SELL = {}
  5.  
  6. /************************************************ EDIT BELOW THIS LINE ***********************************************/
  7. SELL.SellersFile = "npc_sellers.txt" -- This is the data file the seller info will save to
  8. SELL.WeaponsFile  = "npc_weapons.txt " -- This is the data file the weapon info will save to
  9.  
  10. --[[ SELL.Info is the information about where the NPCs are, what they look like, and what they can sell
  11. Here's how it should look:
  12.  
  13. ["mapname_lowercase_only"] = {
  14.     {
  15.         pos = Vector( x, y, z ),
  16.         ang = Angle( pitch, yaw, roll ),
  17.         model = "your_model",
  18.         allowed = {
  19.             "weapon_name",
  20.             "weapon_name_2",
  21.         },
  22.     },
  23. }
  24.  
  25. It is VERY VERY VERY important that you get the syntax EXACTLY RIGHT, or this WILL BREAK AND FAIL ENTIRELY! I would recommend
  26. finding a Lua coder to do it for you, or anyone who understands the syntax of Lua tables. ALL VARIABLE NAMES SHOULD BE THE SAME AS SHOWN!
  27. Note: The model can only be that of a citizen's (for now, at least). ]]--
  28.  
  29. SELL.Info = {
  30.     ["rp_downtown_v2"] = {
  31.         {
  32.             pos = Vector( 78.5428, -2400.1790, -191.9688 ),
  33.             ang = Angle( 0, 135, 0 ),
  34.             model = "models\Humans/Group03m/male_03.mdl",
  35.             allowed = {
  36.                 "ak47",
  37.             }
  38.         },
  39.         {
  40.             pos = Vector( 123.8559, 257.2510, -199.9688 ),
  41.             ang = Angle( 0, 90, 0 ),
  42.             model = "models/Humans/Group01/Male_05.mdl",
  43.             allowed = {
  44.                 "mp5",
  45.             }
  46.         },
  47.         {
  48.             pos = Vector( -1948.2770, -2604.4736, -879.9688 ),
  49.             ang = Angle( 0, 26, 0 ),
  50.             model = "models\Humans/Group03m/Female_02.mdl",
  51.             allowed = {
  52.                 "mp5",
  53.                 "ak47",
  54.             }
  55.         },
  56.     },
  57. }
  58.  
  59. --[[ SELL.Weapons is the information about the weapons each NPC can sell
  60. Here's how it should look:
  61.  
  62. ["unique_print_name"] = {
  63.     model = "weapon_model.mdl",
  64.     class = "weapon_class",
  65.     cost = 1500,
  66.     desc = "A description, tabbing is removed",
  67. }
  68.  
  69. Once again, the syntax MUST BE CORRECT and the variables MUST STAY THE SAME NAME.
  70. Note: The "key" used (in the brackets) is how you will refer to the weapon in the above NPC information, so it must be unique. Casing is irrelevant,
  71. but that name is also what will show up on the Seller's menu. ]]--
  72.  
  73. SELL.Weapons = {
  74.     ["AK47"] = {
  75.         model = "models/sickness/bmw-m5.mdl",
  76.         class = "scripts/vehicles/bmwm5.txt",
  77.         var = ak47
  78.         cost = 1200,
  79.         name = "BMW M5",
  80.         desc = [[Entertain your friends and
  81.         kill your enemies
  82.         with this one of a kind weapon!]],
  83.         ammo = { type = "smg1", amount = 50 },
  84.     },
  85.     ["MP5"] = {
  86.         model = "models/sickness/360spyder.mdl",
  87.         class = "scripts/vehicles/360.txt",
  88.         var = mp5
  89.         cost = 600,
  90.         desc = [[Pew pew pew]],
  91.         ammo = { type = "smg1", amount = 50 },
  92.     },
  93. }
  94. /************************************************ EDIT ABOVE THIS LINE ************************************************/
  95.  
  96. SELL.MaxDist = 200
  97. SELL.Sellers = {}
  98.  
  99. function SELL:GetWeaponByClass( class ) for _,v in pairs(self.Weapons) do if v.class == class then return v end end end
  100.  
  101. if SERVER then
  102.    
  103.     AddCSLuaFile( "npc_sellers.lua" )
  104.  
  105.     function SELL:Initialize()
  106.        
  107.         print("NPC SELLERS Initializing [SERVER]")
  108.  
  109.         local mapinfo = self.Info[string.lower(game.GetMap())]
  110.        
  111.         if not mapinfo then
  112.             print("NPCSELLERS: No data found for this map!")
  113.             return
  114.         end
  115.            
  116.         for _,v in pairs( ents.FindByClass( "npc_citizen" ) ) do
  117.             if string.find( v:GetName(), "npcseller" ) then v:Remove() end
  118.         end
  119.        
  120.         for k,v in pairs(mapinfo) do
  121.             self:CreateSeller( { pos = v.pos, ang = v.ang, model = v.model, allowed = v.allowed, id = k, created = (v.created or false) } )
  122.         end
  123.        
  124.         hook.Add("KeyPress","SELLDetectUse",function( pl, key )
  125.             if key == IN_USE then
  126.                 local ent = pl:GetEyeTrace().Entity
  127.                 if ValidEntity( ent ) and self:WithinRange( pl ) and table.HasValue( self.Sellers, ent ) then
  128.                     pl:ConCommand("sell_menu")
  129.                 end
  130.             end
  131.         end)
  132.        
  133.         hook.Add("ScaleNPCDamage","SELLInvulnSellers",function( npc, hit, dmg )
  134.             if table.HasValue( self.Sellers, npc ) then dmg:SetDamage( 0 ) end
  135.         end)
  136.        
  137.         hook.Add("PlayerAuthed","SELLSendInfo",function( pl )
  138.             self:SendSellerInfo( pl )
  139.         end)
  140.        
  141.         concommand.Add("sell_buyweapon",function( pl, cmd, args )
  142.             if not self:WithinRange( pl ) then return end
  143.            
  144.             local wep,seller = self:GetWeaponByClass( args[2] ), pl:GetEyeTrace().Entity
  145.             print( wep, wep.cost, pl:CanAfford( wep.cost ) )
  146.             if not self:CanSell( seller, string.lower(args[1]) ) then Notify(pl, 1, 4, "That Seller cannot sell that car!") return end
  147.             if not wep then Notify(pl, 1, 4, string.format(LANGUAGE.unavailable, "car")) return end
  148.             if not pl:CanAfford( wep.cost ) then Notify(pl, 1, 4, string.format(LANGUAGE.cant_afford, string.lower(args[1]))) return end
  149.             local cartype = wep.class
  150.             if pl.string.lower(args[1]) == false then ply.string.lower(args[1]) = true pl:SetPData(args[1], "true") end
  151.             car = ents.Create("prop_vehicle_jeep")
  152.             car:SetModel(wep.model)
  153.             car:SetKeyValue("vehiclescript", cartype)
  154.             car:SetPos(pl:GetPos() + Vector(200, 200, 0))
  155.             car.nodupe = true
  156.             car:Spawn()
  157.             car:Activate()
  158.             car:PhysWake()
  159.             car:Own(pl)
  160.             pl:AddMoney( -wep.cost )
  161.             Notify(pl, 1, 4, string.format(LANGUAGE.you_bought_x, wep.name, tostring(wep.cost)))
  162.            
  163.            
  164.             /*local weapon = ents.Create("spawned_weapon")
  165.             weapon:SetModel(wep.model)
  166.             weapon.weaponclass = wep.class
  167.             weapon.ShareGravgun = true
  168.             weapon:SetPos( util.TraceLine({start=ply:EyePos(),endpos=trace.start+ply:GetAimVector() * 85,filter=ply}).HitPos )
  169.             weapon.nodupe = true
  170.             weapon:Spawn()*/
  171.            
  172.         end)
  173.        
  174.         hook.Add("AcceptStream","SELLAllowRegister",function( pl, handle, id )
  175.             if pl:IsAdmin() and handle == "SELLRegister" then return true end
  176.         end)
  177.        
  178.         datastream.Hook("SELLRegister",function(pl,hand,id,enc,args)
  179.             if not pl:IsAdmin() then pl:ChatPrint("You must be an admin to do this!") return end
  180.            
  181.             local npc = self:CreateSeller( { pos = args.pos, ang = args.ang, model = args.model, allowed = args.allowed, id = table.Count(self.Sellers) + 1 } )
  182.             npc:SetNWBool("SELLCreated",true)
  183.             table.insert(self.Info[string.lower(game.GetMap())],{ pos = args.pos, ang = args.ang, model = npc:GetModel(), allowed = args.allowed} )
  184.             pl:ChatPrint("Seller successfully created!")
  185.             self:SaveSellers()
  186.             self:SendSellerInfo( player.GetAll() )
  187.         end)
  188.        
  189.         concommand.Add("sell_removeseller",function(pl,cmd,args)
  190.             if not pl:IsAdmin() then pl:ChatPrint("You must be an admin to do this!") return end
  191.             local e = pl:GetEyeTrace().Entity
  192.             if not ValidEntity( e ) || not table.HasValue( self.Sellers, e ) then pl:ChatPrint("That is not an NPC Seller!") return end
  193.            
  194.             self:RemoveSeller( e, pl )
  195.         end)
  196.        
  197.         self:SendSellerInfo( player.GetAll() )
  198.        
  199.     end
  200.    
  201.     function SELL:LoadSellers()
  202.  
  203.         if not file.Exists(self.SellersFile) then file.Write(self.SellersFile,glon.encode({}))
  204.         else
  205.             local info = glon.decode(file.Read(self.SellersFile))[string.lower(game.GetMap())]
  206.             if not info then return end
  207.             for _,v in pairs( info ) do v.created = true end
  208.            
  209.             table.Add( self.Info[string.lower(game.GetMap())], info )
  210.         end
  211.     end
  212.    
  213.     function setwhatcarsyouown()
  214.     for k, v in pairs(self.Weapons) do local a = ply:GetPData(v.var);
  215.     if a == true then ply.a = true end end
  216.     hook.Add("PlayerInitialSpawn", "broomcheesecake", setwhatcarsyouown)
  217.    
  218.     function SELL:SaveSellers()
  219.         local data = table.Copy(self.Info)
  220.         local mapinfo = self.Info[string.lower(game.GetMap())]
  221.         if not mapinfo then return end
  222.         local to_save = {}
  223.        
  224.         for _,v in pairs( self.Sellers ) do
  225.             local sellerinfo = mapinfo[v:GetNWInt("SellerID")]
  226.             if v:GetNWBool("SELLCreated") then table.insert(to_save,sellerinfo) end
  227.         end
  228.         data[string.lower(game.GetMap())] = to_save
  229.         file.Write(self.SellersFile,glon.encode(data))
  230.         self:SendSellerInfo( player.GetAll() )
  231.     end
  232.    
  233.     function SELL:RemoveSeller( seller, pl )
  234.         if not ValidEntity( seller ) then pl:ChatPrint("Invalid entity!") return end
  235.         if not seller:GetNWBool("SELLCreated") then pl:ChatPrint("You cannot remove that seller! Edit the npc_sellers.lua to do that.") return end
  236.        
  237.         table.remove(self.Info[string.lower(game.GetMap())],seller:GetNWInt("SellerID"))
  238.         for k,v in pairs( self.Sellers ) do if v == seller then table.remove( self.Sellers, k ) end end
  239.         seller:Remove()
  240.         self:SaveSellers()
  241.         pl:ChatPrint("Seller successfully removed!")
  242.         self:SendSellerInfo( player.GetAll() )
  243.     end
  244.    
  245.     function SELL:SendSellerInfo( obj )
  246.         datastream.StreamToClients( obj, "SELLGetInfo", self.Info[string.lower(game.GetMap())] )
  247.     end
  248.    
  249.     function SELL:CreateSeller( args )
  250.        
  251.         local npc = ents.Create("npc_citizen")
  252.         npc:SetPos( args.pos or Vector(0,0,0) )
  253.         npc:SetAngles( args.ang or Angle(0,0,0) )
  254.         npc:SetModel( args.model or "models/Humans/Group02/male_07.mdl" )
  255.         npc:SetSkin( args.skin or 0 )
  256.         npc:SetKeyValue("expressiontype","3")
  257.         npc:Spawn()
  258.         npc:Activate()
  259.         npc:SetName( "npcseller"..tonumber(#self.Sellers) )
  260.         npc:SetAnimation( ACT_IDLE_ANGRY )
  261.         npc:CapabilitiesClear()
  262.         npc:CapabilitiesAdd( CAP_ANIMATEDFACE | CAP_TURN_HEAD )
  263.         npc.SellerInfo = args
  264.         npc:SetNWInt("SellerID",args.id)
  265.         npc:SetNWBool("SELLCreated",args.created)
  266.         for _,v in pairs( ents.GetAll() ) do npc:AddEntityRelationship( v, D_LI, 99 ) end
  267.        
  268.         self.Sellers[ npc:EntIndex() ] = npc
  269.         return npc
  270.        
  271.     end
  272.    
  273.     function SELL:WithinRange( pl )
  274.         local e = pl:GetEyeTrace().Entity
  275.         return ValidEntity( e ) and pl:GetShootPos():Distance( pl:GetEyeTrace().HitPos )  <= self.MaxDist and table.HasValue( self.Sellers, e )
  276.     end
  277.    
  278.     function SELL:CanSell( seller, name ) return table.HasValue(seller.SellerInfo.allowed,name) end
  279.    
  280.     SELL:LoadSellers()
  281.    
  282.     concommand.Add("sell_init_sv",function( pl ) if pl:IsAdmin() then SELL:Initialize() end end)
  283.  
  284. end
  285.  
  286. if CLIENT then
  287.  
  288.     function SELL:Initialize()
  289.    
  290.         print("NPC SELLERS Initializing [CLIENT]")
  291.         concommand.Add("sell_menu",function( pl )
  292.             if not self:WithinRange( pl ) then return end
  293.             local seller = pl:GetEyeTrace().Entity
  294.            
  295.            
  296.             local fr = vgui.Create("DFrame")
  297.             fr:SetSize( 300, 340 )
  298.             fr:Center()
  299.             fr:SetTitle("")
  300.             fr:MakePopup()
  301.             function fr:Paint()
  302.                 draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color( 30, 30, 30, 220 ) )
  303.                 draw.DrawText( "Car Dealer", "ScoreboardText", self:GetWide() / 2, 4, color_white, 1 )
  304.             end
  305.            
  306.             local itempan = vgui.Create("DPanel",fr)
  307.             itempan:SetSize( 165, 290 )
  308.             itempan:SetPos( 20, 30 )
  309.             local itemtext,itemdesc,itemclass,itemcost = "NPC Shop", "Click on an item to see it","", ""
  310.             function itempan:Paint()
  311.                 draw.RoundedBox(0,0,0,self:GetWide(),self:GetTall(),Color(50,50,50,255))
  312.                 draw.DrawText( itemtext .. (itemcost != "" && ": $" ..itemcost || "" ), "ScoreboardText", self:GetWide() / 2, 5, color_white, 1 )
  313.                 draw.DrawText( string.gsub(itemdesc,"\t",""), "Default", self:GetWide() / 2, 20, color_white, 1 )
  314.             end
  315.            
  316.                 local itemmdl = vgui.Create("DModelPanel",itempan)
  317.                 itemmdl:SetSize( itempan:GetWide() - 20, itempan:GetWide() - 20 )
  318.                 itemmdl:SetPos( 10, 80 )
  319.                
  320.                 local function ModelSet(mdl,mdlname)
  321.                     mdl:SetModel(mdlname)
  322.                     local prop = ents.Create("prop_physics")
  323.                     prop:SetModel(mdlname)
  324.                     function mdl:LayoutEntity(Entity)
  325.                         Entity:SetAngles( Angle( -60, math.fmod(CurTime(),360)*50, 0) )
  326.                     end
  327.                     mdl:SetCamPos(prop:OBBCenter()-Vector(prop:BoundingRadius()*1.3,prop:BoundingRadius() * 1,-prop:BoundingRadius() / 1))
  328.                     mdl:SetLookAt(prop:OBBCenter()-Vector(0,0,-prop:BoundingRadius()/13))
  329.                     prop:Remove()
  330.                 end
  331.                
  332.                 local buybtn = vgui.Create("DButton",itempan)
  333.                
  334.                 buybtn:SetSize( itempan:GetWide() - 20, 20 )
  335.                 buybtn:SetPos( 10, itempan:GetTall() - 30 )
  336.                 if LocalPlayer().itemvar == true then
  337.                 buybtn:SetText("Spawn Car")
  338.                 else buybtn:SetText("Buy car") end
  339.                 buybtn.DoClick = function()
  340.                     if itemclass == "" then LocalPlayer():ChatPrint("Select a car first!") return end
  341.                    
  342.                     RunConsoleCommand( "sell_buyweapon", itemtext, itemclass )
  343.                     fr:Close()
  344.                 end
  345.            
  346.             local weps = vgui.Create("DPanelList",fr)
  347.             weps:SetSize( (table.Count(self.Weapons) < 3 && 85 || 100 ), 290 )
  348.             weps:SetPos( fr:GetWide() - weps:GetWide() - 20, 30 )
  349.             weps:SetPadding( 5 )
  350.             weps:SetSpacing( 5 )
  351.             weps:EnableVerticalScrollbar( true )
  352.             for k,v in pairs( self.Weapons ) do
  353.                 if self:CanSell( seller, string.lower(k) ) then
  354.                     local pan = vgui.Create("DPanel")
  355.                     pan:SetSize( weps:GetWide() - 10, (table.Count(self.Weapons) < 3 && weps:GetWide() || weps:GetWide() - 10 ) )
  356.                     function pan:Paint()
  357.                         draw.DrawText( k, "Default", self:GetWide() / 2, 2, color_white, 1 )
  358.                         draw.RoundedBox( 4, 0, 0, self:GetWide(), self:GetTall(), Color( 100, 100, 100, 100 ) )
  359.                     end
  360.                    
  361.                     local icon = vgui.Create("SpawnIcon",pan)
  362.                     icon:SetModel( v.model )
  363.                     icon:SetPos( 5, 15 )
  364.                     icon:SetTooltip( k ..": $" .. v.cost )
  365.                     icon.OnMousePressed = function()
  366.                         ModelSet(itemmdl,v.model)
  367.                         itemtext = k
  368.                         itemdesc = v.desc
  369.                         itemvar = v.var
  370.                         itemclass = v.class
  371.                         itemcost = v.cost
  372.                     end
  373.                    
  374.                     weps:AddItem( pan )
  375.                 end
  376.             end
  377.         end)
  378.        
  379.         concommand.Add("sell_admin",function()
  380.             if !LocalPlayer():IsAdmin() then LocalPlayer():ChatPrint("You must be an admin to access this!") return end
  381.             local fr = vgui.Create("DFrame")
  382.             fr:SetSize( 250, 65 )
  383.             fr:Center()
  384.             fr:SetTitle("")
  385.             fr:MakePopup()
  386.             function fr:Paint()
  387.                 draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color( 30, 30, 30, 220 ) )
  388.                 draw.DrawText( "Modify Sellers", "ScoreboardText", self:GetWide() / 2, 3, color_white, 1 )
  389.             end
  390.            
  391.             local npc = vgui.Create("DButton",fr)
  392.             npc:SetPos( 20, 30 )
  393.             npc:SetSize( 100, 20 )
  394.             npc:SetText("Add a Seller")
  395.             npc.DoClick = function()
  396.                 self:AddSellerMenu()
  397.                 fr:Close()
  398.             end
  399.            
  400.             local wpn = vgui.Create("DButton",fr)
  401.             wpn:SetPos( 130, 30 )
  402.             wpn:SetSize( 100, 20 )
  403.             wpn:SetText("Add a Weapon")
  404.             wpn.DoClick = function()
  405.                 LocalPlayer():ChatPrint("That is not yet implemented. Contact your local developer for more information.")
  406.             end
  407.         end)
  408.        
  409.     end
  410.    
  411.     function SELL:AddSellerMenu()
  412.         local fr = vgui.Create("DFrame")
  413.         fr:SetSize( 450,200 )
  414.         fr:Center()
  415.         fr:SetTitle("")
  416.         fr:MakePopup()
  417.         function fr:Paint()
  418.             draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color( 30, 30, 30, 220 ) )
  419.             draw.DrawText( "Add Seller", "ScoreboardText", self:GetWide() / 2, 3, color_white, 1 )
  420.             draw.DrawText("Model:","Default", 20, 173, color_white, 0 )
  421.         end
  422.        
  423.         local pPos = vgui.Create("DPanel",fr)
  424.         pPos:SetPos( 20, 25 )
  425.         pPos:SetSize( 130, 135 )
  426.         function pPos:Paint()
  427.             draw.RoundedBox(0,0,0,self:GetWide(),self:GetTall(),Color(100,100,100,255))
  428.         end
  429.             local pos = { "X", "Y", "Z" }
  430.             for k,v in pairs( pos ) do
  431.                 local text = vgui.Create("DTextEntry", pPos )
  432.                 text:SetPos( 25, 10 + ( k - 1 ) * 30 )
  433.                 text:SetSize( 70, 20 )
  434.                 local lbl =  vgui.Create("DLabel", pPos )
  435.                 lbl:SetPos( 10, 10 + (k - 1) * 30 )
  436.                 lbl:SetText( v..":" )
  437.                 pos[k] = text
  438.             end
  439.             local current = vgui.Create("DButton",pPos)
  440.             current:SetPos( 10, 105 )
  441.             current:SetSize( pPos:GetWide() - 20, 20 )
  442.             current:SetText("Get Current Position")
  443.             current.DoClick = function()
  444.                 local curpos = LocalPlayer():GetPos()
  445.                 pos[1]:SetValue( math.Round(curpos.x) )
  446.                 pos[2]:SetValue( math.Round(curpos.y) )
  447.                 pos[3]:SetValue( math.Round(curpos.z) )
  448.             end
  449.            
  450.         local pAng= vgui.Create("DPanel",fr)
  451.         pAng:SetPos( 160, 25 )
  452.         pAng:SetSize( 130, 135 )
  453.         function pAng:Paint()
  454.             draw.RoundedBox(0,0,0,self:GetWide(),self:GetTall(),Color(100,100,100,255))
  455.         end
  456.             local ang = { "P", "Y", "R" }
  457.             for k,v in pairs( ang ) do
  458.                 local text = vgui.Create("DTextEntry", pAng )
  459.                 text:SetPos( 25, 10 + ( k - 1 ) * 30 )
  460.                 text:SetSize( 70, 20 )
  461.                 local lbl =  vgui.Create("DLabel", pAng )
  462.                 lbl:SetPos( 10, 10 + (k - 1) * 30 )
  463.                 lbl:SetText( v..":" )
  464.                 ang[k] = text
  465.             end
  466.             local current = vgui.Create("DButton",pAng)
  467.             current:SetPos( 10, 105 )
  468.             current:SetSize( pAng:GetWide() - 20, 20 )
  469.             current:SetText("Get Current Angles")
  470.             current.DoClick = function()
  471.                 local curang = LocalPlayer():GetAngles()
  472.                 ang[1]:SetValue( math.Round(curang.x) )
  473.                 ang[2]:SetValue( math.Round(curang.y) )
  474.                 ang[3]:SetValue( math.Round(curang.z) )
  475.             end
  476.        
  477.         local pWep= vgui.Create("DPanel",fr)
  478.         pWep:SetPos( 300, 25 )
  479.         pWep:SetSize( 130, 135 )
  480.         function pWep:Paint()
  481.             draw.RoundedBox(0,0,0,self:GetWide(),self:GetTall(),Color(100,100,100,255))
  482.         end
  483.             local weps = vgui.Create("DPanelList",pWep)
  484.             weps:SetPos( 10, 10 )
  485.             weps:SetSize( pWep:GetWide() - 20, pWep:GetTall() - 20 )
  486.             weps:EnableVerticalScrollbar( true )
  487.             weps:SetPadding(2)
  488.             weps:SetSpacing(2)
  489.             for k,v in pairs( self.Weapons ) do
  490.                 local pan = vgui.Create("DPanel")
  491.                 function pan:Paint()
  492.                     draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color( 100, 100, 100, 100 ) )
  493.                 end
  494.                 local chb = vgui.Create("DCheckBoxLabel",pan)
  495.                 chb:SetPos( 5, 5 )
  496.                 chb:SetText( k )
  497.                 pan.Item = k
  498.                 pan.chb = chb
  499.                 weps:AddItem( pan )
  500.             end
  501.            
  502.         local model = vgui.Create("DTextEntry",fr)
  503.         model:SetPos( 60, 170 )
  504.         model:SetSize(175, 20 )
  505.        
  506.         local submit = vgui.Create("DButton",fr)
  507.         submit:SetSize( 75, 20 )
  508.         submit:SetText("Submit")
  509.         submit:SetPos( fr:GetWide() - submit:GetWide() - 20, 170 )
  510.         submit.DoClick = function()
  511.             local x,y,z,p,yaw,r = tonumber(pos[1]:GetValue()),tonumber(pos[2]:GetValue()),tonumber(pos[3]:GetValue()),tonumber(ang[1]:GetValue()),tonumber(ang[2]:GetValue()),tonumber(ang[3]:GetValue())
  512.             if not x or not y or not z or not p or not yaw or not r then LocalPlayer():ChatPrint("Malformed number!") return end
  513.             local data = {
  514.                 pos = Vector(x,y,z),
  515.                 ang = Angle(p,yaw,r),
  516.                 model = model:GetValue(),
  517.                 allowed = {}
  518.             }
  519.             for _,v in pairs( weps:GetItems() ) do if v.chb:GetChecked() then
  520.                 table.insert(data.allowed,string.lower(v.Item))
  521.             end end
  522.             if not data.allowed[1] then LocalPlayer():ChatPrint("Select at least one weapon!") return end
  523.             datastream.StreamToServer("SELLRegister",data)
  524.         end
  525.        
  526.     end
  527.    
  528.     function SELL:WithinRange( pl )
  529.         local e = pl:GetEyeTrace().Entity
  530.         return ValidEntity( e ) and pl:GetShootPos():Distance( pl:GetEyeTrace().HitPos )  <= self.MaxDist and e:GetClass() == "npc_citizen"
  531.     end
  532.    
  533.     function SELL:CanSell( seller, name ) return table.HasValue( self.Info[string.lower(game.GetMap())][seller:GetNWInt("SellerID")].allowed, name) end
  534.    
  535.     concommand.Add("sell_init_cl",function() SELL:Initialize() end)
  536.    
  537.     datastream.Hook("SELLGetInfo",function(hand,id,enc,dec) SELL.Info[string.lower(game.GetMap())] = dec end)
  538.    
  539. end
  540.  
  541. hook.Add("InitPostEntity","SELLInitialize",function() SELL:Initialize() end)
  542.  
  543. --lua_openscript autorun/npc_sellers.lua
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement