• Drawing elements for all players to see
    2 replies, posted
Hey everyone :D I'm trying to draw a progress bar on an entity (in this case a workbench) using 3D2D. It essentially works, but there's one problem. Only the player who used the workbench can see the 3D2D. Here's the idea: Player uses (E) workbench --> Derma is displayed --> Player starts process (crafting) --> 3D2D progress bar is displayed. Which means: Entity(server) --> Player(client) --> Entity(client). Now, for the code: [I]After the player has used Derma (player - clientside):[/I] [CODE]function craftShipment( wep, bench ) net.Start( "guncraft_craftShipment" ) net.WriteTable( wep ) net.WriteEntity( bench ) net.SendToServer() bench:DrawProgress( wep ) -- Telling entity to draw 3D2D. end[/CODE] [I]The receiving end (entity - clientside)[/I] [CODE]function ENT:DrawProgress( wep ) local prevTime = CurTime() local mulTime = wep.time * GC_cfg_shipmentTimeMultiplier function self:Draw() local owner = self:GetNWEntity( "GC_owner"):Nick() or "Unknown" self:DrawModel() local ang = self:GetAngles() ang:RotateAroundAxis( self:GetAngles():Up() , 90 ) cam.Start3D2D( self:GetPos() - Vector( 0, 0, -31 ), ang, 0.1 ) draw.RoundedBox( 2, -290, -150, 580, 60, Color( 50, 50, 50, 200 ) ) -- Name Box draw.SimpleTextOutlined( owner.."'s Weapon Workbench" , "header1" , 0, -120, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER , TEXT_ALIGN_CENTER, 1, Color( 0, 0, 0, 255 ) ) -- Name Text draw.RoundedBox( 2, -290, -80, 580, 230, Color( 50, 50, 50, 200 ) ) -- Status Box draw.RoundedBox( 2, -280, -10, 560, 150, Color( 50, 50, 50, 200 ) ) -- Progress Bar Box cam.End3D2D() if( CurTime() > prevTime + mulTime ) then return end cam.Start3D2D( self:GetPos() - Vector( 0, 0, -31 ), ang, 0.1 ) draw.SimpleTextOutlined( wep.name.." Shipment" , "header1" , 0, -45, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER , TEXT_ALIGN_CENTER, 1, Color( 0, 0, 0, 255 ) ) -- Crafting Text draw.RoundedBox( 2, -275, -5, ( ( CurTime() - prevTime ) / mulTime ) * 550, 140, Color( 50, 255, 50, 255 ) ) -- Progress Bar draw.SimpleTextOutlined( math.floor( ( ( CurTime() - prevTime ) / mulTime ) * 100 ).."%", "header0", 0, 60, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color( 0, 0, 0, 150 ) ) -- Percent Indicator cam.End3D2D() end end[/CODE] To recap, the last piece of code only shows up for the player who used the workbench, not for any other player looking at it. I don't understand why this wont show itself for all players. It's the entity who is told to draw stuff on itself, which should be visible to all players. It's not the client-side of the player that is told to draw stuff on the entity. Any help is very much appreciated :)
Setup some datatables using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/SetupDataTables]ENT:SetupDataTables[/url] and then use some code like this [LUA] function ENT:DrawProgress( wep ) self:SetDrawProgress(true) self:SetPrevTime(CurTime()) self:SetWep(wep) end function ENT:Draw() if self:GetDrawProgress() == true then local wep = self:GetWep() local prevTime = self:GetPrevTime() local mulTime = wep.time * GC_cfg_shipmentTimeMultiplier local owner = self:GetNWEntity( "GC_owner"):Nick() or "Unknown" local ang = self:GetAngles() ang:RotateAroundAxis( self:GetAngles():Up() , 90 ) cam.Start3D2D( self:GetPos() - Vector( 0, 0, -31 ), ang, 0.1 ) draw.RoundedBox( 2, -290, -150, 580, 60, Color( 50, 50, 50, 200 ) ) -- Name Box draw.SimpleTextOutlined( owner.."'s Weapon Workbench" , "header1" , 0, -120, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER , TEXT_ALIGN_CENTER, 1, Color( 0, 0, 0, 255 ) ) -- Name Text draw.RoundedBox( 2, -290, -80, 580, 230, Color( 50, 50, 50, 200 ) ) -- Status Box draw.RoundedBox( 2, -280, -10, 560, 150, Color( 50, 50, 50, 200 ) ) -- Progress Bar Box cam.End3D2D() if( CurTime() > prevTime + mulTime ) then return end cam.Start3D2D( self:GetPos() - Vector( 0, 0, -31 ), ang, 0.1 ) draw.SimpleTextOutlined( wep.name.." Shipment" , "header1" , 0, -45, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER , TEXT_ALIGN_CENTER, 1, Color( 0, 0, 0, 255 ) ) -- Crafting Text draw.RoundedBox( 2, -275, -5, ( ( CurTime() - prevTime ) / mulTime ) * 550, 140, Color( 50, 255, 50, 255 ) ) -- Progress Bar draw.SimpleTextOutlined( math.floor( ( ( CurTime() - prevTime ) / mulTime ) * 100 ).."%", "header0", 0, 60, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color( 0, 0, 0, 150 ) ) -- Percent Indicator cam.End3D2D() end self:DrawModel() end [/LUA]
Or as an alternative you can just make an if statement and when you send client -> server do a server -> client back using net.Broadcast(); that sets the variable to true?
Sorry, you need to Log In to post a reply to this thread.