• YouTube Player Auto Updating?
    1 replies, posted
Hello, I've tried converting this entity from the Elevator:Source gamemode so that people can press E on the entity to change the URL. For some reason once the URL is entered (YouTube video.), the video is played for a second or so but returns back to the original HTML page instead of playing the video. (Can be seen as ENT.URL in the code.) any help would be greatly appreciated. [code] if SERVER then AddCSLuaFile("shared.lua") end ENT.RenderGroup = RENDERGROUP_BOTH ENT.Type = "anim" ENT.Base = "base_anim" ENT.Model = Model( "models/gmod_tower/suitetv.mdl" ) ENT.Width = 1024 ENT.Height = 768 ENT.Scale = 0.053 ENT.BasePosition = Vector( 0, -27, 35 ) local UMSG_OFF = 0 local UMSG_ON = 1 local UMSG_CONTROL = 2 if SERVER then ENT.TurnOffDist = 300 function ENT:Initialize() self:SetModel( self.Model ) self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) self:SetUseType( SIMPLE_USE ) local phys = self:GetPhysicsObject() if ( IsValid( phys ) ) then phys:EnableMotion( true ) end timer.Simple( .1, function() if ( !IsValid( self ) ) then return end // Create remote local ent = ents.Create( "elevator_tvremote" ) ent:SetPos( self:GetPos() + ( self:GetForward() * 12 ) ) ent:DrawShadow( false ) ent:Spawn() ent:Activate() ent:SetOwner( self ) end ) end function ENT:Think() for _, ply in pairs( player.GetAll() ) do if ( self:IsWatching( ply ) ) then local dist = ply:GetPos():Distance( self:GetPos() ) if ( dist > self.TurnOffDist ) then self:TurnOffTV( ply ) end end end end function ENT:Use( ply ) if ( !IsValid( ply ) ) then return end if ( !self:IsWatching( ply ) ) then self:TurnOnTV( ply ) self:OpenControls( ply ) else self:TurnOffTV( ply ) end local tv = self:GetOwner() end function ENT:AddPlayer( ply ) if ( !IsValid( ply ) ) then return end ply.ActiveTV = self end function ENT:RemovePlayer( ply ) if ( !IsValid( ply ) ) then return end ply.ActiveTV = nil end function ENT:IsWatching( ply ) return IsValid( ply.ActiveTV ) && ply.ActiveTV == self end function ENT:TurnOnTV( ply ) if ( !IsValid( ply ) ) then return end self:AddPlayer( ply ) umsg.Start( "elevator_tvstatus", ply ) umsg.Entity( self ) umsg.Char( UMSG_ON ) umsg.End() //if ( self:IsWatching( ply ) ) then self:UpdatePlayer( ply ) //end end function ENT:TurnOffTV( ply ) if ( !IsValid( ply ) ) then return end self:RemovePlayer( ply ) umsg.Start( "elevator_tvstatus", ply ) umsg.Entity( self ) umsg.Char( UMSG_OFF ) umsg.End() end function ENT:TVIsPlaying() return tobool( self.VideoID ) end function ENT:TVTime() return math.Round( CurTime() - ( self.VideoStartTime or 0 ) ) end function ENT:SetTV( ply, vid, dur ) if ( !IsValid( ply ) ) then return end self.VideoID = vid self.VideoStartTime = CurTime() self:UpdateAllPlayers( ply ) end function ENT:UpdateAllPlayers( starter ) for _, ply in pairs( player.GetAll() ) do // Don't update the starter - they're already up to date if ( IsValid( starter ) && ply == starter ) then continue end if ( self:IsWatching( ply ) ) then self:UpdatePlayer( ply ) GAMEMODE:PlayerMessage( ply, "TV", starter:Nick() .. " started a new video.", 3 ) end end // Dont forget the starter if ( IsValid( starter ) ) then self:AddPlayer( starter ) end end function ENT:UpdatePlayer( ply ) if ( !IsValid( ply ) ) then return end umsg.Start( "elevator_updatetv", ply ) umsg.Entity( self ) umsg.String( self.VideoID or "" ) umsg.Short( self:TVTime() or 0 ) umsg.End() end function ENT:OpenControls( ply ) if ( !IsValid( ply ) ) then return end umsg.Start( "elevator_tvstatus", ply ) umsg.Entity( self ) umsg.Char( UMSG_CONTROL ) umsg.End() end function ENT:LowerVolume( ply ) if ( !IsValid( ply ) ) then return end umsg.Start( "elevator_tvvolume", ply ) umsg.Bool( true ) // true to lower, false to raise umsg.End() end function ENT:RaiseVolume( ply ) if ( !IsValid( ply ) ) then return end umsg.Start( "elevator_tvvolume", ply ) umsg.Bool( false ) // true to lower, false to raise umsg.End() end concommand.Add( "elev_settv", function( ply, cmd, args ) if #args < 2 then return end local vid = args[1] Msg( vid ) local tvindex = tonumber( args[2] ) if !tvindex then return end local tv = Entity( tvindex ) if !IsValid( tv ) then return end tv:SetTV( ply, vid ) end ) else // Client ENT.URL = "http://www.pixeltailgames.com/elevator/tv/" function ENT:Draw() self:DrawModel() end function ENT:DrawTranslucent() local status, err = pcall( self.DrawPanel, self) if not status then print( err ) end end function ENT:TurnOff() if ( !self:IsOn() ) then return end if ValidPanel( self.Browser ) then self.Browser:Remove() self.Browser = nil end LocalPlayer().ActiveTV = nil self:EmitSound( "elevator/effects/tv_off.wav" ) end function ENT:TurnOn() if ( self:IsOn() ) then return end if !ValidPanel( self.Browser ) then self.Browser = vgui.Create( "EntityHTML" ) self.Browser:SetSize( self.Width, self.Height ) self.Browser:SetVisible( false ) self.Browser:SetPaintedManually( true ) self.Browser:SetEntity( self ) self:UpdateTV() end LocalPlayer().ActiveTV = self self:EmitSound( "elevator/effects/tv_on.wav" ) end function ENT:IsOn() return ValidPanel( self.Browser ) end function ENT:UpdateTV( vid, time ) if !ValidPanel( self.Browser ) then return end if ( vid && time ) then self.Browser:OpenURL( self.URL .. "index.php?type=w&t=" .. time .. "&id=" .. vid ) else self.Browser:OpenURL( self.URL .. "index.php?type=n" ) end end function ENT:DisplayControls() if !self:IsOn() then self:TurnOn() end if !ValidPanel( self.Browser ) then return end if !ValidPanel( self.HTMLFrame ) then local w, h = self.Browser:GetWide() + 10, self.Browser:GetTall() + 35 self.HTMLFrame = vgui.Create( "DFrame" ) self.HTMLFrame:SetSize( w, h ) self.HTMLFrame:SetTitle( "Elevator TV" ) self.HTMLFrame:SetPos( ( ScrW() / 2 ) - ( w / 2 ), ( ScrH() / 2 ) - ( h / 2 ) ) self.HTMLFrame:SetDraggable( false ) self.HTMLFrame:ShowCloseButton( true ) self.HTMLFrame:SetDeleteOnClose( false ) //Do not remove when the window is closed, just hide it end self.Browser:SetPaintedManually( false ) self.Browser:SetParent( self.HTMLFrame ) self.Browser:SetPos( 5, 25 ) self.Browser:SetVisible( true ) self.Browser:OpenURL( self.URL ) self.HTMLFrame:SetVisible( true ) self.HTMLFrame:MakePopup() local browser = self.Browser local tv = self self.HTMLFrame.Close = function( self ) DFrame.Close( self ) if ( ValidPanel( browser ) ) then browser:SetPaintedManually( true ) browser:SetParent( nil ) browser:SetVisible( false ) tv:UpdateTV( tv.VideoID, math.Round( CurTime() - ( tv.VideoStartTime or 0 ) ) ) //tv:TurnOff() end end end function ENT:GetPosBrowser() return self:GetPos() + (self:GetForward() * 1) + (self:GetUp() * -5.5) end function ENT:DrawBrowser() if !ValidPanel( self.Browser ) then return end self.Browser:UpdateHTMLTexture() local w, h = self.Browser:GetSize() surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( self.Browser:GetHTMLMaterial() ) surface.DrawTexturedRect( 0, 0, w, h ) end function ENT:DrawPanel() local pos, ang = self:GetPosBrowser(), self:GetAngles() local up, right = self:GetUp(), self:GetRight() pos = pos + (up * self.Height * self.Scal
Bump
Sorry, you need to Log In to post a reply to this thread.