Jump to content

Speaker !


TorNix~|nR

Recommended Posts

hey everyone, I have speaker script of xXMADEXx, the speaker only attachElements for vehicle!

I need to attachElements for player too (attach element on his back)

anyone help?

Client Side:

------------------------------------------
-- Author: xXMADEXx						--
-- Name: 3D Speakers 2.0				--
-- File: client.lua						--
-- Copyright 2013 ( C ) Braydon Davis	--
------------------------------
-- Variables				--
------------------------------
local subTrackOnSoundDown = 0.1	-- The volume that goes down, when the player clicks "Volume -"
local subTrackOnSoundUp = 0.1	-- The volume that goes up, when the player clicks "Volume +"


function print ( message, r, g, b )
	outputChatBox ( message, r, g, b )
end

------------------------------
-- The GUI					--
------------------------------
local rx, ry = guiGetScreenSize ( )
button = { }
window = guiCreateWindow( ( rx - 295 ), ( ry / 2 - 253 / 2 ), 293, 253, "LS - Speakers", false)
        guiSetProperty(window, "CaptionColour", "FFFF0000")
guiWindowSetSizable(window, false)
guiSetVisible ( window, false )
TorNix = guiCreateLabel(0.692,0.900,0.5,0.5,"TorNix~|nR ®",true,window)
guiSetFont(TorNix, "default-bold-small")
guiLabelSetColor(TorNix, 255, 0, 0)		
CurrentSpeaker = guiCreateLabel(8, 33, 254, 17, "Do you have a currently have a speaker: No", false, window)
volume = guiCreateLabel(10, 50, 252, 17, "Current Volume: 100%", false, window)
pos = guiCreateLabel(10, 66, 252, 15, "X: 0 | Y: 0 | Z: 0", false, window)
guiCreateLabel(11, 81, 251, 15, "URL:", false, window)
--url = guiCreateEdit(11, 96, 272, 23, "", false, window)  
url = guiCreateEdit(11, 96, 272, 23, "http://www.181.fm/stream/asx/181-power", false, window)  
button["place"] = guiCreateButton(9, 129, 274, 20, "Create Speaker", false, window)
        guiSetProperty(button["place"], "NormalTextColour", "FF00FF00")
        guiSetProperty(button["place"], "HoverTextColour", "FF00FF00")	
        guiSetFont(button["place"], "default-bold-small")		
button["remove"] = guiCreateButton(9, 159, 274, 20, "Destroy Speaker", false, window)
        guiSetProperty(button["remove"], "NormalTextColour", "FFFF0000")
        guiSetProperty(button["remove"], "HoverTextColour", "FFFF0000")	
        guiSetFont(button["remove"], "default-bold-small")		
button["v-"] = guiCreateButton(9, 189, 128, 20, "Volume -", false, window)
        guiSetProperty(button["v-"], "NormalTextColour", "FFFF0000")
        guiSetProperty(button["v-"], "HoverTextColour", "FFFF0000")	
        guiSetFont(button["v-"], "default-bold-small")		
button["v+"] = guiCreateButton(155, 189, 128, 20, "Volume +", false, window)
        guiSetProperty(button["v+"], "NormalTextColour", "FF00FF00")
        guiSetProperty(button["v+"], "HoverTextColour", "FF00FF00")	
        guiSetFont(button["v+"], "default-bold-small")		
button["close"] = guiCreateButton(9, 219, 174, 20, "Exit", false, window)  
        guiSetProperty(button["close"], "NormalTextColour", "FFFFFF00")
        guiSetProperty(button["close"], "HoverTextColour", "FFFFFF00")	
        guiSetFont(button["close"], "default-bold-small")		

--------------------------
-- My sweet codes		--
--------------------------
local isSound = false
addEvent ( "onPlayerViewSpeakerManagment", true )
addEventHandler ( "onPlayerViewSpeakerManagment", root, function ( current )
	local toState = not guiGetVisible ( window ) 
	guiSetVisible ( window, toState )
	showCursor ( toState ) 
	if ( toState == true ) then
		guiSetInputMode ( "no_binds_when_editing" )
		local x, y, z = getElementPosition ( localPlayer )
		guiSetText ( pos, "X: "..math.floor ( x ).." | Y: "..math.floor ( y ).." | Z: "..math.floor ( z ) )
		if ( current ) then guiSetText ( CurrentSpeaker, "Do you currently have a speaker: Yes" ) isSound = true
		else guiSetText ( CurrentSpeaker, "Do you currently have a speaker: No" ) end
	end
end )

addEventHandler ( "onClientGUIClick", root, function ( )
	if ( source == button["close"] ) then
		guiSetVisible ( window, false ) 
		showCursor ( false )
	elseif ( source == button["place"] ) then
		if ( isURL ( ) ) then
			triggerServerEvent ( "onPlayerPlaceSpeakerBox", localPlayer, guiGetText ( url ), isPedInVehicle ( localPlayer ) )
			guiSetText ( CurrentSpeaker, "Do you currently have a speaker: Yes" )
			isSound = true
			guiSetText ( volume, "Current Volume: 100%" )
		else
			print ( "You need to enter a URL.", 255, 0, 0 )
		end
	elseif ( source == button["remove"] ) then
		triggerServerEvent ( "onPlayerDestroySpeakerBox", localPlayer )
		guiSetText ( CurrentSpeaker, "Do you currently have a speaker: No" )
		isSound = false
		guiSetText ( volume, "Current Volume: 100%" )
	elseif ( source == button["v-"] ) then
		if ( isSound ) then
			local toVol = math.round ( getSoundVolume ( speakerSound [ localPlayer ] ) - subTrackOnSoundDown, 2 )
			if ( toVol > 0.0 ) then
				print ( "Volume set to "..math.floor ( toVol * 100 ).."%!", 0, 255, 0 )
				triggerServerEvent ( "onPlayerChangeSpeakerBoxVolume", localPlayer, toVol )
				guiSetText ( volume, "Current Volume: "..math.floor ( toVol * 100 ).."%" )
			else
				print ( "The volume cannot go any lower.", 255, 0, 0 )
			end
		end
	elseif ( source == button["v+"] ) then
		if ( isSound ) then
			local toVol = math.round ( getSoundVolume ( speakerSound [ localPlayer ] ) + subTrackOnSoundUp, 2 )
			if ( toVol < 1.1 ) then
				print ( "Volume set to "..math.floor ( toVol * 100 ).."%!", 0, 255, 0 )
				triggerServerEvent ( "onPlayerChangeSpeakerBoxVolume", localPlayer, toVol )
				guiSetText ( volume, "Current Volume: "..math.floor ( toVol * 100 ).."%" )
			else
				print ( "The volume cannot go any higher.", 255, 0, 0 )
			end
		end
	end
end )

speakerSound = { }
addEvent ( "onPlayerStartSpeakerBoxSound", true )
addEventHandler ( "onPlayerStartSpeakerBoxSound", root, function ( who, url, isCar )
	if ( isElement ( speakerSound [ who ] ) ) then destroyElement ( speakerSound [ who ] ) end
	local x, y, z = getElementPosition ( who )
		speakerSound [ who ] = playSound3D ( url, x, y, z, true )
	setSoundVolume ( speakerSound [ who ], 1 )
	setSoundMinDistance ( speakerSound [ who ], 15 )
	setSoundMaxDistance ( speakerSound [ who ], 60.1 )
	if ( isCar ) then
		local car = getPedOccupiedVehicle ( who )
		attachElements ( speakerSound [ who ], car, 0, 5, 1 )
	end
end )

addEvent ( "onPlayerDestroySpeakerBox", true )
addEventHandler ( "onPlayerDestroySpeakerBox", root, function ( who ) 
	if ( isElement ( speakerSound [ who ] ) ) then 
		destroyElement ( speakerSound [ who ] ) 
	end
end )

addEventHandler ( "OnClientPlayerWasted", root, function ( who ) 
	if ( isElement ( speakerSound [ who ] ) ) then 
		destroyElement ( speakerSound [ who ] ) 
	end
end )

--------------------------
-- Volume				--
--------------------------
addEvent ( "onPlayerChangeSpeakerBoxVolumeC", true )
addEventHandler ( "onPlayerChangeSpeakerBoxVolumeC", root, function ( who, vol ) 
	if ( isElement ( speakerSound [ who ] ) ) then
		setSoundVolume ( speakerSound [ who ], tonumber ( vol ) )
	end
end )

function isURL ( )
	if ( guiGetText ( url ) ~= "" ) then
		return true
	else
		return false
	end
end

function math.round(number, decimals, method)
    decimals = decimals or 0
    local factor = 10 ^ decimals
    if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
    else return tonumber(("%."..decimals.."f"):format(number)) end
end



function openadminpanel ()
if guiGetVisible(window) == false then
guiSetVisible(window, true)
showCursor(true)
elseif guiGetVisible(window) == true then
guiSetVisible(window, false)
showCursor(false)
end
end
addEvent("openAdmin", true)
addEventHandler("openAdmin", getRootElement(), openadminpanel)

Server-Side

------------------------------------------
-- Author: xXMADEXx						--
-- Name: 3D Speakers 2.0				--
-- File: server.lua						--
-- Copyright 2013 ( C ) Braydon Davis	--
------------------------------------------

function permission (source)
if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Yohan")) or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("SMODCHAT")) or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("MODCHAT")) or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("VIP")) or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("RICHVIP")) then
triggerClientEvent(source, "openAdmin", getRootElement())
end
end
addCommandHandler("speaker", permission)

speakerBox = { }
addCommandHandler ( "", function ( thePlayer  )
	if ( isElement ( speakerBox [ thePlayer] ) ) then isSpeaker = true end
	triggerClientEvent ( thePlayer, "onPlayerViewSpeakerManagment", thePlayer, isSpeaker )
end )

local isSpeaker = false

function print ( player, message, r, g, b )
	outputChatBox ( message, player, r, g, b )
end

addEvent ( "onPlayerPlaceSpeakerBox", true )
addEventHandler ( "onPlayerPlaceSpeakerBox", root, function ( url, isCar ) 
	if ( url ) then
		if ( isElement ( speakerBox [ source ] ) ) then
			local x, y, z = getElementPosition ( speakerBox [ source ] ) 
			print ( source, "Destroyed old speaker located at: "..math.floor ( x )..", "..math.floor ( y )..", "..math.floor ( z ), 255, 0, 0 )
			destroyElement ( speakerBox [ source ] )
			removeEventHandler ( "onPlayerQuit", source, destroySpeakersOnPlayerQuit )
			removeEventHandler ( "onPlayerWasted", source, destroySpeakersOnPlayerQuit )			
		end
		local x, y, z = getElementPosition ( source )
		local rx, ry, rz = getElementRotation ( source )
		speakerBox [ source ] = createObject ( 2229, x-0.5, y+0.5, z - 1, 0, 0, rx )
		print ( source, "Speaker box placed at "..math.floor ( x )..", "..math.floor ( y )..", "..math.floor ( z ), 0, 255, 0 )
		addEventHandler ( "onPlayerQuit", source, destroySpeakersOnPlayerQuit )
		addEventHandler ( "onPlayerWasted", source, destroySpeakersOnPlayerQuit )		
		triggerClientEvent ( root, "onPlayerStartSpeakerBoxSound", root, source, url, isCar )
		if ( isCar ) then
			local car = getPedOccupiedVehicle ( source )
			attachElements ( speakerBox [ source ], car, -0.7, -1.5, -0.5, 0, 90, 0 )
		end
	end
end )

addEvent ( "onPlayerDestroySpeakerBox", true )
addEventHandler ( "onPlayerDestroySpeakerBox", root, function ( )
	if ( isElement ( speakerBox [ source ] ) ) then
		destroyElement ( speakerBox [ source ] )
		triggerClientEvent ( root, "onPlayerDestroySpeakerBox", root, source )
		removeEventHandler ( "onPlayerQuit", source, destroySpeakersOnPlayerQuit )
		removeEventHandler ( "onPlayerWasted", source, destroySpeakersOnPlayerQuit )		
		print ( source, "Speaker box has been removed.", 255, 0, 0 )
	else
		print ( source, "You don't have a speaker box.", 255, 255, 0 )
	end
end )

addEvent ( "onPlayerChangeSpeakerBoxVolume", true ) 
addEventHandler ( "onPlayerChangeSpeakerBoxVolume", root, function ( to )
	triggerClientEvent ( root, "onPlayerChangeSpeakerBoxVolumeC", root, source, to )
end )

function destroySpeakersOnPlayerQuit ( )
	if ( isElement ( speakerBox [ source ] ) ) then
		destroyElement ( speakerBox [ source ] )
		triggerClientEvent ( root, "onPlayerDestroySpeakerBox", root, source )
	end
end

Thanks ^_^

Edited by TorNix~|nR
Link to comment

Done guys, I made it by myself! ^_^

but little problem? how to set the object like the pickup? because when I make the object under my back, I can't see nothing.

like this, I can not see anything, any help please?

mta_screen_2016_12_14_14_48_27.png

mta_screen_2016_12_14_14_48_31.png

 

Done guys! I find it and thanks

if anyone has this problem? use this

setElementCollisionsEnabled

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...