Jump to content

[Problem] Disco Lights Script


PanBob

Recommended Posts

The console pops up: WARNING: discoswiatla/server.lua:26: Bad argument @ 'setVehicleHeadLightColor' [Expected vehicle at argument 1]

server.lua:

local discoTimer = {}
local discoState = {}

function vehicleLights( player, command, lig1, lig2, lig3 )
  lig1 = lig1 or math.random( 0, 255 )
  lig2 = lig2 or math.random( 0, 255 )
  lig3 = lig3 or math.random( 0, 255 )
 
    local vehicle = getPedOccupiedVehicle( player )
    if ( vehicle ) then
        setVehicleHeadLightColor( vehicle, lig1, lig2, lig3 )
        outputChatBox("Your Car Have now another Light!", player, 0, 255, 0 )
    else
        outputChatBox("you must have a vehicle for doing this!", player, 255, 0, 0 )
    end
end
addCommandHandler("lights",vehicleLights) -- Change your VehicleLights

function Disco(player,command)
    local vehicle = getPedOccupiedVehicle(player)
  if (vehicle) then
    if discoState[player] == false then
      discoState[player] = true
      discoTimer[player] = setTimer(
              function ( playerVehicle )
                  setVehicleHeadLightColor( playerVehicle, math.random(0,255), math.random(0,255), math.random(0,255) )
              end
          , 100, 0, vehicle )
          outputChatBox( "!!Disco-Fever!!", player, 0, 255, 0 )
    else
      if discoTimer[player] then
        killTimer( discoTimer[player] )
          discoTimer[player] = nil
        discoState[player] = false
        setVehicleHeadLightColor( vehicle, 255, 255, 255 )
      end
    end
    else
        outputChatBox( "!!You have to sit in a Car/Bike!!", player, 255, 0, 0 )
    end
end
addCommandHandler("disco",Disco)--Disco ((((:))))

function reset(player, command )
    local vehicle = getPedOccupiedVehicle(player)
    local r,g,b = getVehicleHeadLightColor(vehicle)
    if (vehicle) then
    if not (r==255) and not (g==255) and not (b==255) then
    setVehicleHeadLightColor( vehicle, 255,255,255)
    end
end
end
addCommandHandler("reset",reset)

function setStateOnStart()
  for _, players in ipairs( getElementsByType( "player" ) ) do
    discoState[players] = false
  end
end
addEventHandler( "onResourceStart", getResourceRootElement( getThisResource() ), setStateOnStart );

function setStateOnJoin()
  discoState[source] = false
end
addEventHandler( "onPlayerJoin", getRootElement(), setStateOnJoin )

function removeStateOnQuit()
  discoState[source] = nil
end
addEventHandler( "onPlayerQuit", getRootElement(), setStateOnJoin )

Link to comment
2 hours ago, NeXuS™ said:

Can you put the code between <> tags?

Oh... sorry.

here:

local discoTimer = {}
local discoState = {}

function vehicleLights( player, command, lig1, lig2, lig3 )
  lig1 = lig1 or math.random( 0, 255 )
  lig2 = lig2 or math.random( 0, 255 )
  lig3 = lig3 or math.random( 0, 255 )
  
    local vehicle = getPedOccupiedVehicle( player )
    if ( vehicle ) then
        setVehicleHeadLightColor( vehicle, lig1, lig2, lig3 )
        outputChatBox("Your Car Have now another Light!", player, 0, 255, 0 )
    else
        outputChatBox("you must have a vehicle for doing this!", player, 255, 0, 0 )
    end
end
addCommandHandler("lights",vehicleLights) -- Change your VehicleLights

function Disco(player,command)
    local vehicle = getPedOccupiedVehicle(player)
  if (vehicle) then
    if discoState[player] == false then
      discoState[player] = true
      discoTimer[player] = setTimer( 
              function ( playerVehicle )
                  setVehicleHeadLightColor( playerVehicle, math.random(0,255), math.random(0,255), math.random(0,255) )
              end
          , 100, 0, vehicle )
          outputChatBox( "!!Disco-Fever!!", player, 0, 255, 0 )
    else
      if discoTimer[player] then
        killTimer( discoTimer[player] )
          discoTimer[player] = nil
        discoState[player] = false
        setVehicleHeadLightColor( vehicle, 255, 255, 255 )
      end
    end
    else
        outputChatBox( "!!You have to sit in a Car/Bike!!", player, 255, 0, 0 )
    end
end
addCommandHandler("disco",Disco)--Disco ((((:))))

function reset(player, command )
    local vehicle = getPedOccupiedVehicle(player)
    local r,g,b = getVehicleHeadLightColor(vehicle)
    if (vehicle) then
    if not (r==255) and not (g==255) and not (b==255) then
    setVehicleHeadLightColor( vehicle, 255,255,255)
    end
end
end
addCommandHandler("reset",reset)

function setStateOnStart()
  for _, players in ipairs( getElementsByType( "player" ) ) do
    discoState[players] = false
  end
end
addEventHandler( "onResourceStart", getResourceRootElement( getThisResource() ), setStateOnStart );

function setStateOnJoin()
  discoState[source] = false
end
addEventHandler( "onPlayerJoin", getRootElement(), setStateOnJoin )

function removeStateOnQuit()
  discoState[source] = nil
end
addEventHandler( "onPlayerQuit", getRootElement(), setStateOnJoin )

Link to comment
local discoTimer = {}
local discoState = {}

function vehicleLights( player, command, lig1, lig2, lig3 )
  lig1 = lig1 or math.random( 0, 255 )
  lig2 = lig2 or math.random( 0, 255 )
  lig3 = lig3 or math.random( 0, 255 )
  
	local vehicle = getPedOccupiedVehicle( player )
	if ( vehicle ) then
		setVehicleHeadLightColor( vehicle, lig1, lig2, lig3 )
		outputChatBox("Your Car Have now another Light!", player, 0, 255, 0 )
	else
		outputChatBox("you must have a vehicle for doing this!", player, 255, 0, 0 )
	end
end
addCommandHandler("lights",vehicleLights) -- Change your VehicleLights

function Disco(player,command)
	local vehicle = getPedOccupiedVehicle(player)
  if (vehicle) then
    if discoState[player] == false then
      discoState[player] = true
      discoTimer[player] = setTimer( 
			  function ( playerVehicle )
				  setVehicleHeadLightColor( playerVehicle, math.random(0,255), math.random(0,255), math.random(0,255) )
			  end
		  , 100, 0, vehicle )
		  outputChatBox( "!!Disco-Fever!!", player, 0, 255, 0 )
    else
      if discoTimer[player] then
        killTimer( discoTimer[player] )
	      discoTimer[player] = nil
        discoState[player] = false
        setVehicleHeadLightColor( vehicle, 255, 255, 255 )
      end
    end
	else
		outputChatBox( "!!You have to sit in a Car/Bike!!", player, 255, 0, 0 )
	end
end
addCommandHandler("disco",Disco)--Disco ((((:))))

function reset(player, command )
	local vehicle = getPedOccupiedVehicle(player)
	local r,g,b = getVehicleHeadLightColor(vehicle)
	if (vehicle) then
    if not (r==255) and not (g==255) and not (b==255) then
	setVehicleHeadLightColor( vehicle, 255,255,255)
	end
end
end
addCommandHandler("reset",reset)

function setStateOnStart()
  for _, players in ipairs( getElementsByType( "player" ) ) do
    discoState[players] = false
  end
end
addEventHandler( "onResourceStart", getResourceRootElement( getThisResource() ), setStateOnStart );

function setStateOnJoin()
  discoState[source] = false
end
addEventHandler( "onPlayerJoin", getRootElement(), setStateOnJoin )

function removeStateOnQuit()
  discoState[source] = nil
end
addEventHandler( "onPlayerQuit", getRootElement(), setStateOnJoin )

 

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