Jump to content

Speaker script


Recommended Posts

I have a speaker script, I wanted to make sure that when I left the server, the speaker disappeared. Because it keeps flying in the air.

Server:

function createTuneObject(player, object)
	local vehicle = getPedOccupiedVehicle(player)
	if vehicle then
		if not tune.elements[object][vehicle] then
			local x, y, z = getElementPosition(vehicle)
            local rx, ry, rz = getElementRotation (vehicle)
            local ID = getTuneObjectID(object)
            tune.elements[object][vehicle] = createObject(ID, x, y, z, rx, ry, rz)
            attachElements(tune.elements[object][vehicle], vehicle, 0, -0.15 , 0.1 , 0, 0, 0)
        else
        	if isElement(tune.elements[object][vehicle]) then destroyElement(tune.elements[object][vehicle]) end
        	tune.elements[object][vehicle] = false
		end
	end
end
addEvent("createTuneObject", true)
addEventHandler("createTuneObject", root, createTuneObject)

function moveTuneObject(player, object, move)
	local vehicle = getPedOccupiedVehicle(player)
	if vehicle then
		if tune.elements[object][vehicle] then
			x, y, z = getElementAttachedOffsets(tune.elements[object][vehicle])
			if move == "up" then
				setElementAttachedOffsets (tune.elements[object][vehicle], x, y, z+0.03)
			elseif move == "down" then
				setElementAttachedOffsets (tune.elements[object][vehicle], x, y, z-0.03)
			elseif move == "left" then
				setElementAttachedOffsets (tune.elements[object][vehicle], x-0.03, y, z)
			elseif move == "right" then
				setElementAttachedOffsets (tune.elements[object][vehicle], x+0.03, y, z)
			elseif move == "front" then
				setElementAttachedOffsets (tune.elements[object][vehicle], x, y+0.03, z)
			elseif move == "back" then
				setElementAttachedOffsets (tune.elements[object][vehicle], x, y-0.03, z)
			end
		end
	end
end
addEvent("moveTuneObject", true)
addEventHandler("moveTuneObject", root, moveTuneObject)

addEventHandler("onElementDestroy", root, function ()
	if getElementType(source) == "vehicle" then
		local attached = getAttachedElements(source)
		for i,v in pairs(attached) do
		end
 	end
end)

 

Client:

screenW, screenH = guiGetScreenSize()

tune.window = guiCreateStaticImage(650, screenH*0.5-285*0.5, 300, 285, "files/main.png", false)
guiSetVisible(tune.window, false)

tune.grid = guiCreateGridList(5, 47, 290, 150, false, tune.window)
guiGridListAddColumn(tune.grid, "Objeler", 0.9)

tune.select = guiCreateStaticImage(140, 210, 140, 25, "files/but.png", false, tune.window)
tune.close = guiCreateStaticImage(140, 245, 140, 25, "files/buts.png", false, tune.window)

tune.front = guiCreateStaticImage(45, 210, 30, 30, "files/up.png", false, tune.window)
tune.left = guiCreateStaticImage(10, 245, 30, 30, "files/l.png", false, tune.window)
tune.right = guiCreateStaticImage(80, 245, 30, 30, "files/r.png", false, tune.window)
tune.back = guiCreateStaticImage(45, 245, 30, 30, "files/do.png", false, tune.window)

tune.up = guiCreateStaticImage(80, 210, 30, 30, "files/s.png", false, tune.window)
tune.down = guiCreateStaticImage(10, 210, 30, 30, "files/s1.png", false, tune.window)

addEventHandler("onClientGUIClick", root, function ()
	local selected = guiGridListGetItemText(tune.grid, guiGridListGetSelectedItem(tune.grid), 1)
	if source == tune.select then
		if selected ~= "" then
			triggerServerEvent("createTuneObject", localPlayer, localPlayer, selected)
		end
	elseif source == tune.close then
		guiSetVisible(tune.window, false)
		showCursor(false)
	elseif source == tune.front then
		if selected == "" then return end
		triggerServerEvent("moveTuneObject", localPlayer, localPlayer, selected, "front")
	elseif source == tune.back then
		if selected == "" then return end
		triggerServerEvent("moveTuneObject", localPlayer, localPlayer, selected, "back")
	elseif source == tune.left then
		if selected == "" then return end
		triggerServerEvent("moveTuneObject", localPlayer, localPlayer, selected, "left")
	elseif source == tune.right then
		if selected == "" then return end
		triggerServerEvent("moveTuneObject", localPlayer, localPlayer, selected, "right")
	elseif source == tune.down then
		if selected == "" then return end
		triggerServerEvent("moveTuneObject", localPlayer, localPlayer, selected, "down")
	elseif source == tune.up then
		if selected == "" then return end
		triggerServerEvent("moveTuneObject", localPlayer, localPlayer, selected, "up")
	end
end)

tune.table = {}
for i,v in pairs(tune.elements) do
	table.insert(tune.table, {i})
	table.sort(tune.table, function(a, b) return a[1] < b[1] end )
end

for i,v in pairs(tune.table) do
	row = guiGridListAddRow(tune.grid)
	guiGridListSetItemText(tune.grid, row, 1, v[1], false, false)
end

bindKey(tune.key, "down", function ()
	guiSetVisible(tune.window, not guiGetVisible(tune.window))
	showCursor(guiGetVisible(tune.window))
end)

for i,v in pairs(tune.mods) do 
	txd = engineLoadTXD(v[1], v[3])
	engineImportTXD(txd, v[3])
	dff = engineLoadDFF(v[2], v[3])
	engineReplaceModel(dff, v[3])
end

 

https://imgur.com/a/lOrUPUw

Link to comment
  • Moderators
28 minutes ago, ~Sr.Victor said:

I have a speaker script, I wanted to make sure that when I left the server, the speaker disappeared. Because it keeps flying in the air.

The resource/script is unfinished. You should ask the creator to finish it, finish it yourself or download a resource that is finished.

Edited by IIYAMA
Link to comment

There is a "shared.Lua"

 

tune = {
	--- Lista de objetos
	elements = {
		["Caixa de Som #1"] = {},
		["Caixa de Som #2"] = {},
		["Caixa de Som #3"] = {},
		["Caixa de Som #4"] = {},
		["Caixa de Som #5"] = {},	
	},
	--- Registre mods para arquivos aqui
	mods = {		
		{"mods/sab.txd", "mods/sab.dff", 1924},
		{"mods/taxi_4.txd", "mods/sab_2.dff", 1925},
		{"mods/sab_3.txd", "mods/sab_3.dff", 1926},
		{"mods/sab_4.txd", "mods/sab_4.dff", 1927},
		{"mods/sab_4.txd", "mods/sab_5.dff", 1928},
	}
}

tune.key = "5" --- bind para abrir o painel

tune.move = {}
---- ID dos objetos
tune.ID = {		
		["Caixa de Som #1"] = 1924,
		["Caixa de Som #2"] = 1925,
		["Caixa de Som #3"] = 1926,
		["Caixa de Som #4"] = 1927,
		["Caixa de Som #5"] = 1928,
}


function getTuneObjectID(name)
	return tune.ID[name]
end

 

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...