• DColorMixer updating
    12 replies, posted
Hello. I have a Car NPC, and wanting to add a car color selection tool onto it. I am a bit stumped on how to get the DColorMixer to update live. I am also confused as to why it isnt working properly, and making the car purple. On the menu it stays as the default color, and dosent update, and on the car it is always purple. Here is the code. [lua] local Mixer = vgui.Create( "DColorMixer", frame ) -- Mixer:Dock( FILL ) Mixer:SetPalette( false ) Mixer:SetAlphaBar( false ) Mixer:SetWangs( false ) Mixer:SetColor( Color( 0,0,0 ) ) Mixer:SetSize( 200, 200) Mixer:Center() Mixer:SetPos(200, 490) NPCCarColorPick = Mixer:GetColor() local icon = vgui.Create("DModelPanel", pnl) icon:SetSize(128, 128) icon:SetPos(5, 5) icon:SetModel(model) icon:SetColor( NPCCarColorPick ) //icon:SetDirectionalLight(BOX_TOP, Color(100, 0, 255)) icon:SetCamPos( Vector( 140, 140, 100 ) ) icon:SetLookAt( Vector( 0, 0, 60 ) ) icon.hovered = false icon.speed = 0 icon.isdonator = donatoronly local paint = icon.Paint icon.Paint = function(self) -- surface.SetDrawColor(Color(0, 0, 0, 255)) //surface.DrawRect(-2, -2, 132, 130) local x,y = self:LocalToScreen(0, 0) local parent = self:GetParent():GetParent():GetParent() local _,py = parent:LocalToScreen(0,0) local pytall = py + parent:GetTall() [/lua] [lua] local car = ents.Create(vehicle.Class) if not car then return end car:SetModel(vehicle.Model) car:SetColor( NPCCarColorPick ) if vehicle.KeyValues then for k, v in pairs(vehicle.KeyValues) do car:SetKeyValue(k, v) end end[/lua] [img]http://cloud-4.steampowered.com/ugc/40847606225897446/17A11DB66BF1664B5EF9C88876248947FE97E9C8/[/img] [img]http://cloud-2.steampowered.com/ugc/40847606225898251/AB1DC888CAA590EA2B3CB7D2EC6C0A065DE63E52/[/img]
You want to use: [code] DModelPanel.Entity:SetColor(col) [/code] Also, using a lot of DModelPanels will cause a lot of lag on the client (even if you precache the models), although once the client has rendered the models, the lag will desist.
Wait, what would I use that for? I ama bit confused.
Use it on the DModelPanel to paint the cars.
So [lua] local Mixer = vgui.Create( "DColorMixer", frame ) -- Mixer:Dock( FILL ) Mixer:SetPalette( false ) Mixer:SetAlphaBar( false ) Mixer:SetWangs( false ) Mixer:SetColor( Color( 0,0,0 ) ) Mixer:SetSize( 200, 200) Mixer:Center() Mixer:SetPos(200, 490) Mixer.car:SetColor(col) local NPCCarColorPick = Mixer:GetColor()[/lua] ? That causes [lua][ERROR] addons/misc_cardealer/lua/npcshop/gui.lua:54: attempt to index field 'car' (a nil value) 1. AddVehicle - addons/misc_cardealer/lua/npcshop/gui.lua:54 2. CreateFrame - addons/misc_cardealer/lua/npcshop/gui.lua:254 3. Function - addons/misc_cardealer/lua/npcshop/gui.lua:277 4. unknown - lua/includes/modules/usermessage.lua:87 [/lua] or [lua] local car = ents.Create(vehicle.Class) if not car then return end car:SetModel(vehicle.Model) Mixer.car:SetColor(col) if vehicle.KeyValues then for k, v in pairs(vehicle.KeyValues) do car:SetKeyValue(k, v) end end [/lua]? Both cause errors, and the icon is still not updating.
Could you post your entire code, because from what you posted above; it looks like you don't have any idea what you're doing. Are you using a vehicle shop you made yourself or one from somewhere else?
Server.lua [url]http://pastebin.com/z4BgVDu2[/url] Gui.lua [url]http://pastebin.com/WCJuTVNb[/url] It isnt mine, I am trying to modify it. [url]http://facepunch.com/showthread.php?t=1266627[/url]
Anyone?
A DModelPanel and DColorMixer aren't the same thing. The Mixer has NO car variable. You're trying to index the Mixer's car variable which doesn't exist. That means we need to create a PANEL:ValueChanged() function for the mixer, and then set the icon's color to what it was. That would look like: [code] function Mixer:ValueChanged(self, color) icon:SetColor(color); end[/code] Judging by the code posted above though, you seem to be created a DColorMixer for every vehicle panel? Which is a horrible way to do this. Instead yo should make one under pnllist and then in the ValueChanged function loop through all the items and set their colors. I also suggest that instead of modifying someone else's you make your own. I think you should get a bit more practice with Lua before you attempt that, though.
As Crazyscouter has said, you'll want to use a single ColorMixer which, when it's color value has changed, will then apply the changes to your currently selected vehicle. No offence, but you should really look into learning the more basics of programming before you start messing around with Garry's Mod stuff - it will help massively with script development in the future :)
Thank you so much for being helpful. There is just one ColorMixer My gui.lua now looks like [lua] local Mixer = vgui.Create( "DColorMixer", pnllist ) Mixer:SetPalette( false ) Mixer:SetAlphaBar( false ) Mixer:SetWangs( false ) Mixer:SetColor( Color( 0,0,0 ) ) Mixer:SetSize( 200, 200) Mixer:Center() Mixer:SetPos(200, 490) function Mixer:ValueChanged(self, color) icon:SetColor(color); end[/lua] But that uh, breaks the game. [url]http://steamcommunity.com/sharedfiles/filedetails/?id=287174308[/url]
[code] function Mixer:ValueChanged(color) icon:SetColor(color); end [/code]
Thank you!
Sorry, you need to Log In to post a reply to this thread.