Clientside Methods for ENT:Use

I’m trying to use sound.PlayURL on an entity. I was wondering if it was possible to do something like this.

My current init.lua


AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
 
function ENT:Initialize()
 
	self:SetModel( "models/props_lab/citizenradio.mdl" )
	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS )
 
        local phys = self:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
	end
end
 
function ENT:Use( activator, caller )
sound.PlayURL ( "http://mattjeanes.com/data/tardis/majestictale.mp3", "3d", function( station )
	if ( IsValid( station ) ) then

		station:SetPos( LocalPlayer():GetPos() )

		station:Play()

	else

		LocalPlayer():ChatPrint( "Invalid URL!" )

	end
end )

end
 
function ENT:Think()
end

Important bit:


function ENT:Use( activator, caller )
sound.PlayURL ( "http://mattjeanes.com/data/tardis/majestictale.mp3", "3d", function( station )
	if ( IsValid( station ) ) then

		station:SetPos( LocalPlayer():GetPos() )

		station:Play()

	else

		LocalPlayer():ChatPrint( "Invalid URL!" )

	end
end )

end

Obviously I’m trying to use a clientside method serverside in this code, my question is if and how it’s possible to make something like this work with an entity. I tried wrapping it with:



if (CLIENT) then
end


But, that’s a no go. Any help?

If you read the wiki page you can see ENT:Use is only called server side, I’d suggest using the net library.

Correct me if I am wrong.

You could use the KeyPress hook > Check if the key is the USE key and the if the player is looking at your entity > Sound.PlayURL

This actually ended up working for me. Is it possible to make it so that if you press the IN_USE key again after pressing it once it would stop the song being played like, station:Stop()

Like an on, off switch.

I’ve got some kinda system here:

Code’s kinda trash but I’ll add a snippet of code when I get home

Could you post your code for this so that I can figure this out? :slight_smile: