Mateuswiesner Posted January 21, 2014 Share Posted January 21, 2014 I wonder if it is possible to create a shortcut to a command example: /setradio http://1in.kz/s/music/1310701564_lil-wa ... -party.mp3 But I do not use the /bind. Because I want to create multiple radios wanted to use a short command with the same function example: /lilwayne Link to comment
DNL291 Posted January 21, 2014 Share Posted January 21, 2014 local soundsPath = { ["lilwayne"] = "http://1in.kz/s/music/1310701564_lil-wayne-ft-lil-b-grove-st-party.mp3" } addCommandHandler("setradio", function(cmdName, sound, vol) local music = playSound(soundsPath[sound]) setSoundVolume( music, vol or 0.8 ) end ) e.g: /setradio lilwayne. Link to comment
Mateuswiesner Posted January 21, 2014 Author Share Posted January 21, 2014 But when I use this command, he is playing straight. No pause I was referring to a command to link to a resource that I have, that would be the Sound_3D the resouce Sound_3D has a command that is so /setradio wanted to know if you have to link this command with that of resource cVehRadio3D radioSound = { } addEventHandler("onClientResourceStart", resourceRoot, function() bindKey("r", "down", clientToggleRadio) bindKey("m", "down", volumeUp) bindKey("n", "down", volumeDown) end ) addEventHandler("onClientVehicleEnter", root, function(thePlayer, seat) if thePlayer == getLocalPlayer() then local msg = "Pressione R para ligar a radio. Use M para aumentar e N diminuir o volume." if radioSound[source] == nil then outputChatBox(msg, 124, 252, 0) else if radioSound[source].soundElement == nil then outputChatBox(msg, 124, 252, 0) end end end end ) addEventHandler("onClientSoundStream", root, function(success, length, streamName) if streamName then local veh = getPedOccupiedVehicle(getLocalPlayer()) if veh then if radioSound[veh] == nil then return end if radioSound[veh].soundElement == source then outputChatBox("#696969Rádio: #22AA22 " .. streamName, 0, 0, 0, true) end end end end ) addEventHandler("onClientSoundChangedMeta", root, function(streamTitle) if streamTitle then local veh = getPedOccupiedVehicle(getLocalPlayer()) if veh then if radioSound[veh] == nil then return end if radioSound[veh].soundElement == source then outputChatBox("#696969Música: #AA2222 " .. streamTitle, 0, 0, 0, true) end end end end ) addEvent("onServerToggleRadio", true) addEventHandler("onServerToggleRadio", getLocalPlayer(), function(toggle, url, veh, volume) if not isElement(veh) then if radioSound[veh] ~= nil then stopSound(radioSound[veh].soundElement) radioSound[veh].soundElement = nil end return end if toggle == true then local x, y, z = getElementPosition(veh) if radioSound[veh] ~= nil then stopSound(radioSound[veh].soundElement) local sound = playSound3D(url, x, y, z) if volume ~= nil then setSoundVolume(sound, volume) end setSoundMinDistance(sound, 80.0) setSoundMaxDistance(sound, 300.0) attachElements(sound, veh) radioSound[veh] = { } radioSound[veh].soundElement = sound else local sound = playSound3D(url, x, y, z) if volume ~= nil then setSoundVolume(sound, volume) end setSoundMinDistance(sound, 80.0) setSoundMaxDistance(sound, 300.0) attachElements(sound, veh) radioSound[veh] = { } radioSound[veh].soundElement = sound end else if radioSound[veh] ~= nil then stopSound(radioSound[veh].soundElement) radioSound[veh].soundElement = nil end end end ) addEvent("onServerRadioURLChange", true) addEventHandler("onServerRadioURLChange", getLocalPlayer(), function(newurl, veh, volume) if radioSound[veh] ~= nil then stopSound(radioSound[veh].soundElement) local x, y, z = getElementPosition(veh) local sound = playSound3D(newurl, x, y, z) if volume ~= nil then setSoundVolume(sound, volume) end setSoundMinDistance(radioSound, 80.0) setSoundMaxDistance(radioSound, 1000.0) attachElements(sound, veh) radioSound[veh] = { } radioSound[veh].soundElement = sound end end ) addEvent("onServerVolumeChangeAccept", true) addEventHandler("onServerVolumeChangeAccept", getLocalPlayer(), function(veh, newVolume) if veh then if radioSound[veh] ~= nil then setSoundVolume(radioSound[veh].soundElement, newVolume) end end end ) function clientToggleRadio() triggerServerEvent("onPlayerToggleRadio", getLocalPlayer()) end function volumeUp() local veh = getPedOccupiedVehicle(getLocalPlayer()) if veh then if radioSound[veh] ~= nil then local volume = getSoundVolume(radioSound[veh].soundElement) if volume ~= false then triggerServerEvent("onPlayerRadioVolumeChange", getLocalPlayer(), volume, true) end end end end function volumeDown() local veh = getPedOccupiedVehicle(getLocalPlayer()) if veh then if radioSound[veh] ~= nil then local volume = getSoundVolume(radioSound[veh].soundElement) if volume ~= false then triggerServerEvent("onPlayerRadioVolumeChange", getLocalPlayer(), volume, false) end end end end sVehRadio3D g_VehicleList = {} local radioStreams = 0 local defaultRadio = "http://212.117.39.164:8000/" addEventHandler("onResourceStart", resourceRoot, function() for i,veh in ipairs(getElementsByType("vehicle")) do g_VehicleList[veh] = { } g_VehicleList[veh].radio = false g_VehicleList[veh].radioStation = defaultRadio g_VehicleList[veh].volume = 1.0 end end ) addEventHandler("onPlayerJoin", root, function() for i,veh in ipairs(getElementsByType("vehicle")) do if g_VehicleList[veh] ~= nil then if g_VehicleList[veh].radio == true then triggerClientEvent(source, "onServerToggleRadio", root, true, g_VehicleList[veh].radioStation, veh, g_VehicleList[veh].volume) end end end end ) addEventHandler("onVehicleExplode", root, function() if g_VehicleList[source] ~= nil then if g_VehicleList[source].radio == true then triggerClientEvent("onServerToggleRadio", root, false, nil, source) g_VehicleList[source].radio = false destroyElement(g_VehicleList[source].radioMarker) killTimer(g_VehicleList[source].idleTimer) if radioStreams ~= 0 then radioStreams = radioStreams - 1 end end end end ) addEventHandler("onElementDestroy", root, function() if g_VehicleList[source] ~= nil then if g_VehicleList[source].radio == true then triggerClientEvent("onServerToggleRadio", root, false, nil, source) g_VehicleList[source].radio = false destroyElement(g_VehicleList[source].radioMarker) killTimer(g_VehicleList[source].idleTimer) if radioStreams ~= 0 then radioStreams = radioStreams - 1 end end end end ) addEvent("onPlayerToggleRadio", true) addEventHandler("onPlayerToggleRadio", root, function() if source and getElementType(source) == "player" then toggleRadio(source) end end ) function toggleRadio(player) local veh = getPedOccupiedVehicle(player) if veh then local occupants = getVehicleOccupants(veh) local seats = getVehicleMaxPassengers(veh) local playerSeat = getPedOccupiedVehicleSeat(player) if playerSeat ~= 0 and playerSeat ~= 1 then outputChatBox("You can't switch the radio.", player, 255, 255, 255) return end if g_VehicleList[veh] == nil then g_VehicleList[veh] = { } g_VehicleList[veh].radio = false g_VehicleList[veh].radioStation = defaultRadio g_VehicleList[veh].volume = 1.0 end if g_VehicleList[veh].radio == false then if not get("toggleAntifloodTick") or not get("streamLimit") or not get("radioEnabledIdleTime") then return end local settingToggleAntifloodTick = get("toggleAntifloodTick") local settingStreamLimit = get("streamLimit") local idleTime = get("radioEnabledIdleTime") if g_VehicleList[veh].lastTick and (getTickCount() - g_VehicleList[veh].lastTick) <= settingToggleAntifloodTick then return end if radioStreams >= settingStreamLimit then outputChatBox("The limit of streams has reached (" .. settingStreamLimit .. ")", player, 255, 255, 255) return end local x, y, z = getElementPosition(veh) g_VehicleList[veh].radio = true g_VehicleList[veh].lastTick = getTickCount() g_VehicleList[veh].turnedOnBy = getPlayerName(player) g_VehicleList[veh].radioMarker = createMarker(x, y, z, "corona", 0.05, 255, 0, 0) attachElements(g_VehicleList[veh].radioMarker, veh) g_VehicleList[veh].idleTimer = setTimer(radioIdleTimer, idleTime, 0, veh) radioStreams = radioStreams + 1 outputServerLog(getPlayerName(player) .. " has turned the radio on in his vehicle (streams: " .. radioStreams .. ")") for seat = 0, seats do local occupant = occupants[seat] if occupant and getElementType(occupant) == "player" then triggerClientEvent("onServerToggleRadio", root, true, g_VehicleList[veh].radioStation, veh, g_VehicleList[veh].volume) local r, g, b = getPlayerNametagColor(player) colorHex = string.format("%02X%02X%02X", r, g, b) outputChatBox("#" .. colorHex .. "" .. getPlayerName(player) .. " #696969Rádio: [#00ff00ON#696969]", occupant, 0, 0, 0, true) end end else g_VehicleList[veh].radio = false destroyElement(g_VehicleList[veh].radioMarker) killTimer(g_VehicleList[veh].idleTimer) radioStreams = radioStreams - 1 outputServerLog(getPlayerName(player) .. " has turned the radio off in his vehicle (streams: " .. radioStreams .. ")") for seat = 0, seats do local occupant = occupants[seat] if occupant and getElementType(occupant) == "player" then triggerClientEvent("onServerToggleRadio", root, false, nil, veh, g_VehicleList[veh].volume) local r, g, b = getPlayerNametagColor(player) colorHex = string.format("%02X%02X%02X", r, g, b) outputChatBox("#" .. colorHex .. "" .. getPlayerName(player) .. " #696969Rádio: [#ff0000OFF#696969]", occupant, 0, 0, 0, true) end end end end end function radioIdleTimer(veh) if not get("radioIdlePlayerDistanceCheck") then return end local settingDist = get("radioIdlePlayerDistanceCheck") if veh then if g_VehicleList[veh] ~= nil then if g_VehicleList[veh].radio == true then local playerInRange = false local vx, vy, vz = getElementPosition(veh) for i,player in ipairs(getElementsByType("player")) do local px, py, pz = getElementPosition(player) local distance = getDistanceBetweenPoints3D(vx, vy, vz, px, py, pz) if distance ~= false and distance < settingDist then playerInRange = true end end if playerInRange == false then triggerClientEvent("onServerToggleRadio", root, false, nil, veh) g_VehicleList[veh].radio = false destroyElement(g_VehicleList[veh].radioMarker) killTimer(g_VehicleList[veh].idleTimer) if radioStreams ~= 0 then radioStreams = radioStreams - 1 end outputServerLog("An " .. getVehicleName(veh) .. "'s radio has been idled (streams: " .. radioStreams .. ")") end end end end end addEvent("onPlayerRadioVolumeChange", true) addEventHandler("onPlayerRadioVolumeChange", root, function(currentVol, volumeUp) local veh = getPedOccupiedVehicle(source) if veh then local playerSeat = getPedOccupiedVehicleSeat(source) if playerSeat == 0 or playerSeat == 1 then if volumeUp == true then g_VehicleList[veh].volume = currentVol + 0.05 if g_VehicleList[veh].volume >= 1.00 then g_VehicleList[veh].volume = 1.00 end else g_VehicleList[veh].volume = currentVol - 0.05 if g_VehicleList[veh].volume <= 0.00 then g_VehicleList[veh].volume = 0.00 end end triggerClientEvent("onServerVolumeChangeAccept", root, veh, g_VehicleList[veh].volume) end end end ) function cmdChangeRadioURL(source, commandName, url) if not url then outputChatBox("Usage: /setradio newurl", source, 255, 255, 255) return end local veh = getPedOccupiedVehicle(source) if veh then local occupants = getVehicleOccupants(veh) local seats = getVehicleMaxPassengers(veh) if g_VehicleList[veh] == nil then local x, y, z = getElementPosition(veh) g_VehicleList[veh] = { } g_VehicleList[veh].radio = true g_VehicleList[veh].lastTick = getTickCount() g_VehicleList[veh].radioStation = defaultRadio g_VehicleList[veh].volume = 1000.0 g_VehicleList[veh].radioMarker = createMarker(x, y, z, "corona", 0.1, 255, 0, 0) attachElements(g_VehicleList[veh].radioMarker, veh) g_VehicleList[veh].idleTimer = setTimer(radioIdleTimer, idleTime, 0, veh) end local playerSeat = getPedOccupiedVehicleSeat(source) if playerSeat ~= 0 and playerSeat ~= 1 then outputChatBox("You can't switch the radio station URL.", source, 255, 255, 255) return end for seat = 0, seats do local occupant = occupants[seat] if occupant and getElementType(occupant) == "player" then g_VehicleList[veh].radioStation = url g_VehicleList[veh].changedBy = getPlayerName(source) if g_VehicleList[veh].radio == true then triggerClientEvent("onServerRadioURLChange", root, g_VehicleList[veh].radioStation, veh, g_VehicleList[veh].volume) end local r, g, b = getPlayerNametagColor(source) colorHex = string.format("%02X%02X%02X", r, g, b) outputChatBox("#" .. colorHex .. "" .. getPlayerName(source) .. " #FFFFFFhas changed the radio station.", occupant, 0, 0, 0, true) outputConsole(getPlayerName(source) .. " has changed the radio station on his vehicle to: " .. url, occupant) end end outputServerLog(getPlayerName(source) .. " has changed the radio station on his vehicle to: " .. url) end end Link to comment
Castillo Posted January 21, 2014 Share Posted January 21, 2014 g_VehicleList = {} local radioStreams = 0 local defaultRadio = "http://212.117.39.164:8000/" local shortcuts = { [ "lilwayne" ] = "http://1in.kz/s/music/1310701564_lil-wayne-ft-lil-b-grove-st-party.mp3", } addEventHandler("onResourceStart", resourceRoot, function() for i,veh in ipairs(getElementsByType("vehicle")) do g_VehicleList[veh] = { } g_VehicleList[veh].radio = false g_VehicleList[veh].radioStation = defaultRadio g_VehicleList[veh].volume = 1.0 end end ) addEventHandler("onPlayerJoin", root, function() for i,veh in ipairs(getElementsByType("vehicle")) do if g_VehicleList[veh] ~= nil then if g_VehicleList[veh].radio == true then triggerClientEvent(source, "onServerToggleRadio", root, true, g_VehicleList[veh].radioStation, veh, g_VehicleList[veh].volume) end end end end ) addEventHandler("onVehicleExplode", root, function() if g_VehicleList[source] ~= nil then if g_VehicleList[source].radio == true then triggerClientEvent("onServerToggleRadio", root, false, nil, source) g_VehicleList[source].radio = false destroyElement(g_VehicleList[source].radioMarker) killTimer(g_VehicleList[source].idleTimer) if radioStreams ~= 0 then radioStreams = radioStreams - 1 end end end end ) addEventHandler("onElementDestroy", root, function() if g_VehicleList[source] ~= nil then if g_VehicleList[source].radio == true then triggerClientEvent("onServerToggleRadio", root, false, nil, source) g_VehicleList[source].radio = false destroyElement(g_VehicleList[source].radioMarker) killTimer(g_VehicleList[source].idleTimer) if radioStreams ~= 0 then radioStreams = radioStreams - 1 end end end end ) addEvent("onPlayerToggleRadio", true) addEventHandler("onPlayerToggleRadio", root, function() if source and getElementType(source) == "player" then toggleRadio(source) end end ) function toggleRadio(player) local veh = getPedOccupiedVehicle(player) if veh then local occupants = getVehicleOccupants(veh) local seats = getVehicleMaxPassengers(veh) local playerSeat = getPedOccupiedVehicleSeat(player) if playerSeat ~= 0 and playerSeat ~= 1 then outputChatBox("You can't switch the radio.", player, 255, 255, 255) return end if g_VehicleList[veh] == nil then g_VehicleList[veh] = { } g_VehicleList[veh].radio = false g_VehicleList[veh].radioStation = defaultRadio g_VehicleList[veh].volume = 1.0 end if g_VehicleList[veh].radio == false then if not get("toggleAntifloodTick") or not get("streamLimit") or not get("radioEnabledIdleTime") then return end local settingToggleAntifloodTick = get("toggleAntifloodTick") local settingStreamLimit = get("streamLimit") local idleTime = get("radioEnabledIdleTime") if g_VehicleList[veh].lastTick and (getTickCount() - g_VehicleList[veh].lastTick) <= settingToggleAntifloodTick then return end if radioStreams >= settingStreamLimit then outputChatBox("The limit of streams has reached (" .. settingStreamLimit .. ")", player, 255, 255, 255) return end local x, y, z = getElementPosition(veh) g_VehicleList[veh].radio = true g_VehicleList[veh].lastTick = getTickCount() g_VehicleList[veh].turnedOnBy = getPlayerName(player) g_VehicleList[veh].radioMarker = createMarker(x, y, z, "corona", 0.05, 255, 0, 0) attachElements(g_VehicleList[veh].radioMarker, veh) g_VehicleList[veh].idleTimer = setTimer(radioIdleTimer, idleTime, 0, veh) radioStreams = radioStreams + 1 outputServerLog(getPlayerName(player) .. " has turned the radio on in his vehicle (streams: " .. radioStreams .. ")") for seat = 0, seats do local occupant = occupants[seat] if occupant and getElementType(occupant) == "player" then triggerClientEvent("onServerToggleRadio", root, true, g_VehicleList[veh].radioStation, veh, g_VehicleList[veh].volume) local r, g, b = getPlayerNametagColor(player) colorHex = string.format("%02X%02X%02X", r, g, b) outputChatBox("#" .. colorHex .. "" .. getPlayerName(player) .. " #696969Rádio: [#00ff00ON#696969]", occupant, 0, 0, 0, true) end end else g_VehicleList[veh].radio = false destroyElement(g_VehicleList[veh].radioMarker) killTimer(g_VehicleList[veh].idleTimer) radioStreams = radioStreams - 1 outputServerLog(getPlayerName(player) .. " has turned the radio off in his vehicle (streams: " .. radioStreams .. ")") for seat = 0, seats do local occupant = occupants[seat] if occupant and getElementType(occupant) == "player" then triggerClientEvent("onServerToggleRadio", root, false, nil, veh, g_VehicleList[veh].volume) local r, g, b = getPlayerNametagColor(player) colorHex = string.format("%02X%02X%02X", r, g, b) outputChatBox("#" .. colorHex .. "" .. getPlayerName(player) .. " #696969Rádio: [#ff0000OFF#696969]", occupant, 0, 0, 0, true) end end end end end function radioIdleTimer(veh) if not get("radioIdlePlayerDistanceCheck") then return end local settingDist = get("radioIdlePlayerDistanceCheck") if veh then if g_VehicleList[veh] ~= nil then if g_VehicleList[veh].radio == true then local playerInRange = false local vx, vy, vz = getElementPosition(veh) for i,player in ipairs(getElementsByType("player")) do local px, py, pz = getElementPosition(player) local distance = getDistanceBetweenPoints3D(vx, vy, vz, px, py, pz) if distance ~= false and distance < settingDist then playerInRange = true end end if playerInRange == false then triggerClientEvent("onServerToggleRadio", root, false, nil, veh) g_VehicleList[veh].radio = false destroyElement(g_VehicleList[veh].radioMarker) killTimer(g_VehicleList[veh].idleTimer) if radioStreams ~= 0 then radioStreams = radioStreams - 1 end outputServerLog("An " .. getVehicleName(veh) .. "'s radio has been idled (streams: " .. radioStreams .. ")") end end end end end addEvent("onPlayerRadioVolumeChange", true) addEventHandler("onPlayerRadioVolumeChange", root, function(currentVol, volumeUp) local veh = getPedOccupiedVehicle(source) if veh then local playerSeat = getPedOccupiedVehicleSeat(source) if playerSeat == 0 or playerSeat == 1 then if volumeUp == true then g_VehicleList[veh].volume = currentVol + 0.05 if g_VehicleList[veh].volume >= 1.00 then g_VehicleList[veh].volume = 1.00 end else g_VehicleList[veh].volume = currentVol - 0.05 if g_VehicleList[veh].volume <= 0.00 then g_VehicleList[veh].volume = 0.00 end end triggerClientEvent("onServerVolumeChangeAccept", root, veh, g_VehicleList[veh].volume) end end end ) function cmdChangeRadioURL(source, commandName, url) if not url then outputChatBox("Usage: /setradio newurl", source, 255, 255, 255) return end if ( shortcuts [ url ] ) then url = shortcuts [ url ] end local veh = getPedOccupiedVehicle(source) if veh then local occupants = getVehicleOccupants(veh) local seats = getVehicleMaxPassengers(veh) if g_VehicleList[veh] == nil then local x, y, z = getElementPosition(veh) g_VehicleList[veh] = { } g_VehicleList[veh].radio = true g_VehicleList[veh].lastTick = getTickCount() g_VehicleList[veh].radioStation = defaultRadio g_VehicleList[veh].volume = 1000.0 g_VehicleList[veh].radioMarker = createMarker(x, y, z, "corona", 0.1, 255, 0, 0) attachElements(g_VehicleList[veh].radioMarker, veh) g_VehicleList[veh].idleTimer = setTimer(radioIdleTimer, idleTime, 0, veh) end local playerSeat = getPedOccupiedVehicleSeat(source) if playerSeat ~= 0 and playerSeat ~= 1 then outputChatBox("You can't switch the radio station URL.", source, 255, 255, 255) return end for seat = 0, seats do local occupant = occupants[seat] if occupant and getElementType(occupant) == "player" then g_VehicleList[veh].radioStation = url g_VehicleList[veh].changedBy = getPlayerName(source) if g_VehicleList[veh].radio == true then triggerClientEvent("onServerRadioURLChange", root, g_VehicleList[veh].radioStation, veh, g_VehicleList[veh].volume) end local r, g, b = getPlayerNametagColor(source) colorHex = Link to comment
Mateuswiesner Posted January 22, 2014 Author Share Posted January 22, 2014 The music is not playing... But when I use the command, the car radio links (lights the red light on the car) When I do the command appears well "Mateuswiesner has changed the radio station" I've tested other radios! Link to comment
Castillo Posted January 22, 2014 Share Posted January 22, 2014 Which part is not working? can you play normally like you used to without shortcuts? Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now