Jump to content

Radio\server.lua:51: Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got nil]


Recommended Posts

  1.  
    g_VehicleList = {}
    
    local radioStreams = 0
    
    local defaultRadio = "http://listen.shoutcast.com:80/RadioHunter-TheHitzChannel"
    
    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
    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
    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
    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
    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("*[Rádio] O limite de correntes atingiu (" .. 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)
    radioStreams = radioStreams + 1
    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: [#00ff00Ligada#696969]", occupant, 0, 0, 0, true)
    end
    end
    else
    g_VehicleList[veh].radio = false
    radioStreams = radioStreams + 1
    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: [#ff0000Desligada#696969]", occupant, 0, 0, 0, true)
    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("*[Rádio] Use: setradio url", 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 = 1
    end
    local playerSeat = getPedOccupiedVehicleSeat(source)
    if playerSeat ~= 0 and playerSeat ~= 1 then
    outputChatBox("*[Rádio] Você não pode mudar a rádio porquê você é passageiro!", 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) .. " #FFFFFFMudou a Rádio!", occupant, 255, 255, 255, true)
    end
    end
    end
    end
    addCommandHandler("setradio", cmdChangeRadioURL)

     

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