Flipi Posted October 19, 2013 Share Posted October 19, 2013 Hi, I have a problem with my script for the vehicle lights (disco light): Error: WARNING: resource\server.lua:11: Bad 'vehicle' pointer @ 'setVehicleHeadLightColor'(1) server-side: local discoTimer = {} local discoState = {} function Disco(player,command) local vehicle = getPedOccupiedVehicle(player) if (vehicle) then if discoState[player] == false then discoState[player] = true discoTimer[player] = setTimer( function () setVehicleOverrideLights(vehicle, 2) setVehicleHeadLightColor(vehicle, math.random(0,255), math.random(0,255), math.random(0,255) ) end, 150, 0, vehicle ) outputChatBox( "* #0080FFDisco light Activado!", player, 255, 255, 255, true ) else outputChatBox( "* #0080FFDisco light Desactivado!", player, 255, 255, 255, true ) if discoTimer[player] then killTimer( discoTimer[player] ) discoState[player] = false setVehicleOverrideLights(vehicle, 1) setVehicleHeadLightColor(vehicle, 255, 255, 255 ) end end else outputChatBox( "* #0080FFNecesitas un vehiculo para usar el comando!", player, 255, 255, 255, true ) end end addCommandHandler("disco",Disco) 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] = false killTimer( discoTimer[player] ) end addEventHandler( "onPlayerQuit", getRootElement(), removeStateOnQuit) Link to comment
Discord Moderators Zango Posted October 19, 2013 Discord Moderators Share Posted October 19, 2013 On line 10, you must declare vehicle as a parameter. function (vehicle) setVehicleOverrideLights(vehicle, 2) setVehicleHeadLightColor(vehicle, math.random(0,255), math.random(0,255), math.random(0,255) ) end, Link to comment
Jaysds1 Posted October 19, 2013 Share Posted October 19, 2013 try this: local discoTimer = {} local discoState = {} function Disco(player,command) local vehicle = getPedOccupiedVehicle(player) if (vehicle) then if discoState[player] == false then discoState[player] = true discoTimer[player] = setTimer( function (vehicle) setVehicleOverrideLights(vehicle, 2) setVehicleHeadLightColor(vehicle, math.random(0,255), math.random(0,255), math.random(0,255) ) end, 150, 0, vehicle ) outputChatBox( "* #0080FFDisco light Activado!", player, 255, 255, 255, true ) else outputChatBox( "* #0080FFDisco light Desactivado!", player, 255, 255, 255, true ) if discoTimer[player] then killTimer( discoTimer[player] ) discoState[player] = false setVehicleOverrideLights(vehicle, 1) setVehicleHeadLightColor(vehicle, 255, 255, 255 ) end end else outputChatBox( "* #0080FFNecesitas un vehiculo para usar el comando!", player, 255, 255, 255, true ) end end addCommandHandler("disco",Disco) function setStateOnStart() for _, players in ipairs( getElementsByType( "player" ) ) do discoState[players] = false end end addEventHandler( "onResourceStart",resourceRoot, setStateOnStart ) function setStateOnJoin() discoState[source] = false end addEventHandler( "onPlayerJoin",root, setStateOnJoin ) function removeStateOnQuit() discoState[source] = false killTimer( discoTimer[player] ) end addEventHandler( "onPlayerQuit", root, removeStateOnQuit) Fixed some other problems in the script. Link to comment
Flipi Posted October 19, 2013 Author Share Posted October 19, 2013 try this:local discoTimer = {} local discoState = {} function Disco(player,command) local vehicle = getPedOccupiedVehicle(player) if (vehicle) then if discoState[player] == false then discoState[player] = true discoTimer[player] = setTimer( function (vehicle) setVehicleOverrideLights(vehicle, 2) setVehicleHeadLightColor(vehicle, math.random(0,255), math.random(0,255), math.random(0,255) ) end, 150, 0, vehicle ) outputChatBox( "* #0080FFDisco light Activado!", player, 255, 255, 255, true ) else outputChatBox( "* #0080FFDisco light Desactivado!", player, 255, 255, 255, true ) if discoTimer[player] then killTimer( discoTimer[player] ) discoState[player] = false setVehicleOverrideLights(vehicle, 1) setVehicleHeadLightColor(vehicle, 255, 255, 255 ) end end else outputChatBox( "* #0080FFNecesitas un vehiculo para usar el comando!", player, 255, 255, 255, true ) end end addCommandHandler("disco",Disco) function setStateOnStart() for _, players in ipairs( getElementsByType( "player" ) ) do discoState[players] = false end end addEventHandler( "onResourceStart",resourceRoot, setStateOnStart ) function setStateOnJoin() discoState[source] = false end addEventHandler( "onPlayerJoin",root, setStateOnJoin ) function removeStateOnQuit() discoState[source] = false killTimer( discoTimer[player] ) end addEventHandler( "onPlayerQuit", root, removeStateOnQuit) Fixed some other problems in the script. I get the same problem: Error: WARNING: resource\server.lua:11: Bad 'element' pointer @ 'setVehicleOverrideLights'(1) WARNING: resource\server.lua:12: Bad 'vehicle' pointer @ 'setVehicleHeadLightColor'(1) Link to comment
Jaysds1 Posted October 19, 2013 Share Posted October 19, 2013 ok, try this: local discoTimer = {} local discoState = {} addCommandHandler("disco", function(source) local vehicle = getPedOccupiedVehicle(source) if not vehicle then outputChatBox( "* #0080FFNecesitas un vehiculo para usar el comando!", source, 255, 255, 255, true ) return end if not discoState[source] then discoState[source] = true discoTimer[source] = setTimer( function (veh) setVehicleOverrideLights(veh, 2) setVehicleHeadLightColor(veh, math.random(0,255), math.random(0,255), math.random(0,255) ) end, 150, 0, vehicle) outputChatBox( "* #0080FFDisco light Activado!", source, 255, 255, 255, true ) else outputChatBox( "* #0080FFDisco light Desactivado!", source, 255, 255, 255, true ) if discoTimer[source] then killTimer( discoTimer[source] ) discoState[source] = false setVehicleOverrideLights(vehicle, 1) setVehicleHeadLightColor(vehicle, 255, 255, 255 ) end end end ) addEventHandler( "onResourceStart",resourceRoot, function() for _, players in ipairs( getElementsByType( "player" ) ) do discoState[players] = false end end ) addEventHandler( "onPlayerJoin",root, function() discoState[source] = false end ) addEventHandler( "onPlayerQuit", root, function() discoState[source] = false killTimer( discoTimer[player] ) end ) Link to comment
Flipi Posted October 19, 2013 Author Share Posted October 19, 2013 ok, try this:local discoTimer = {} local discoState = {} addCommandHandler("disco", function(source) local vehicle = getPedOccupiedVehicle(source) if not vehicle then outputChatBox( "* #0080FFNecesitas un vehiculo para usar el comando!", source, 255, 255, 255, true ) return end if not discoState[source] then discoState[source] = true discoTimer[source] = setTimer( function (veh) setVehicleOverrideLights(veh, 2) setVehicleHeadLightColor(veh, math.random(0,255), math.random(0,255), math.random(0,255) ) end, 150, 0, vehicle) outputChatBox( "* #0080FFDisco light Activado!", source, 255, 255, 255, true ) else outputChatBox( "* #0080FFDisco light Desactivado!", source, 255, 255, 255, true ) if discoTimer[source] then killTimer( discoTimer[source] ) discoState[source] = false setVehicleOverrideLights(vehicle, 1) setVehicleHeadLightColor(vehicle, 255, 255, 255 ) end end end ) addEventHandler( "onResourceStart",resourceRoot, function() for _, players in ipairs( getElementsByType( "player" ) ) do discoState[players] = false end end ) addEventHandler( "onPlayerJoin",root, function() discoState[source] = false end ) addEventHandler( "onPlayerQuit", root, function() discoState[source] = false killTimer( discoTimer[player] ) end ) still receive the same error, this happens when I activate the command and I get disconnected from the server WARNING: resource\server.lua:15: Bad 'element' pointer @ 'setVehicleOverrideLights'(1) WARNING: resource\server.lua:16: Bad 'vehicle' pointer @ 'setVehicleHeadLightColor'(1) Link to comment
Castillo Posted October 19, 2013 Share Posted October 19, 2013 addEventHandler( "onPlayerQuit", root, function() discoState[source] = false killTimer( discoTimer[player] ) end ) You're using 'player' instead of 'source' in discoTimer. Link to comment
Flipi Posted October 19, 2013 Author Share Posted October 19, 2013 addEventHandler( "onPlayerQuit", root, function() discoState[source] = false killTimer( discoTimer[player] ) end ) You're using 'player' instead of 'source' in discoTimer. thanks, I had not noticed Link to comment
Jaysds1 Posted October 19, 2013 Share Posted October 19, 2013 local disco = { timer = {} state = {} } addCommandHandler("disco", function(source) local vehicle = getPedOccupiedVehicle(source) if not vehicle then outputChatBox( "* #0080FFNecesitas un vehiculo para usar el comando!", source, 255, 255, 255, true ) return end if not disco.state[source] then disco.state[source] = true disco.timer[source] = setTimer( function(veh) setVehicleOverrideLights(veh, 2) setVehicleHeadLightColor(veh, math.random(0,255), math.random(0,255), math.random(0,255) ) end, 150, 0, vehicle) outputChatBox( "* #0080FFDisco light Activado!", source, 255, 255, 255, true ) else outputChatBox( "* #0080FFDisco light Desactivado!", source, 255, 255, 255, true ) if disco.timer[source] then killTimer( disco.timer[source] ) disco.state[source] = false setVehicleOverrideLights(vehicle, 1) setVehicleHeadLightColor(vehicle, 255, 255, 255 ) end end end ) addEventHandler( "onResourceStart",resourceRoot, function() for _, players in ipairs( getElementsByType( "player" ) ) do disco.state[players] = false end end ) addEventHandler( "onPlayerJoin",root, function() disco.state[source] = false end ) addEventHandler( "onPlayerQuit", root, function() disco.state[source] = false killTimer( disco.timer[source] ) end ) Link to comment
Flipi Posted October 19, 2013 Author Share Posted October 19, 2013 local disco = { timer = {} state = {} } addCommandHandler("disco", function(source) local vehicle = getPedOccupiedVehicle(source) if not vehicle then outputChatBox( "* #0080FFNecesitas un vehiculo para usar el comando!", source, 255, 255, 255, true ) return end if not disco.state[source] then disco.state[source] = true disco.timer[source] = setTimer( function(veh) setVehicleOverrideLights(veh, 2) setVehicleHeadLightColor(veh, math.random(0,255), math.random(0,255), math.random(0,255) ) end, 150, 0, vehicle) outputChatBox( "* #0080FFDisco light Activado!", source, 255, 255, 255, true ) else outputChatBox( "* #0080FFDisco light Desactivado!", source, 255, 255, 255, true ) if disco.timer[source] then killTimer( disco.timer[source] ) disco.state[source] = false setVehicleOverrideLights(vehicle, 1) setVehicleHeadLightColor(vehicle, 255, 255, 255 ) end end end ) addEventHandler( "onResourceStart",resourceRoot, function() for _, players in ipairs( getElementsByType( "player" ) ) do disco.state[players] = false end end ) addEventHandler( "onPlayerJoin",root, function() disco.state[source] = false end ) addEventHandler( "onPlayerQuit", root, function() disco.state[source] = false killTimer( disco.timer[source] ) end ) thanks !, you help me with this?: local msgs = {'traidor', 'espia', 'malo'} local randomPlayer = getRandomPlayer ( ) function cuest(text,randomPlayer) local text = msgs [ math.random ( 1, #msgs )] if text then outputChatBox ( "* #FFFFFF"..getPlayerName ( randomPlayer ).." #0080FFes el #FF8000"..text.." #0080FFen cubierto!", getRootElement(), 255, 255, 255, true ) end end addCommandHandler ("traidor", cuest) function cuests(message,messageType,randomPlayer) if message == "!traidor" then local text = msgs [ math.random ( 1, #msgs )] outputChatBox ( "* #FFFFFF"..getPlayerName ( randomPlayer ).." #0080FFes el #FF8000"..text.." #0080FFen cubierto!", getRootElement(), 255, 255, 255, true ) end end addEventHandler("onPlayerChat",getRootElement(),cuests) Link to comment
Jaysds1 Posted October 20, 2013 Share Posted October 20, 2013 Not sure if this is what you wanted... try this: local msgs = {'traidor', 'espia', 'malo'} local randomPlayer = getRandomPlayer ( ) addCommandHandler ("traidor", function() local text = msgs [ math.random ( #msgs )] outputChatBox ( "* #FFFFFF"..getPlayerName ( randomPlayer ).." #0080FFes el #FF8000"..text.." #0080FFen cubierto!",root, 255, 255, 255, true ) end ) addEventHandler("onPlayerChat",getRootElement(), function(message,messageType,randomPlayer) if message == "!traidor" then local text = msgs [ math.random ( #msgs )] outputChatBox ( "* #FFFFFF"..getPlayerName ( randomPlayer ).." #0080FFes el #FF8000"..text.." #0080FFen cubierto!", getRootElement(), 255, 255, 255, true ) end end ) Link to comment
Flipi Posted October 20, 2013 Author Share Posted October 20, 2013 Not sure if this is what you wanted... try this:local msgs = {'traidor', 'espia', 'malo'} local randomPlayer = getRandomPlayer ( ) addCommandHandler ("traidor", function() local text = msgs [ math.random ( #msgs )] outputChatBox ( "* #FFFFFF"..getPlayerName ( randomPlayer ).." #0080FFes el #FF8000"..text.." #0080FFen cubierto!",root, 255, 255, 255, true ) end ) addEventHandler("onPlayerChat",getRootElement(), function(message,messageType,randomPlayer) if message == "!traidor" then local text = msgs [ math.random ( #msgs )] outputChatBox ( "* #FFFFFF"..getPlayerName ( randomPlayer ).." #0080FFes el #FF8000"..text.." #0080FFen cubierto!", getRootElement(), 255, 255, 255, true ) end end ) the problem is that I get this error: WARNING: resource\traidor.lua:16: Bad argument @ 'getPlayerName' [Expected element at argument 1, got nil] ERROR: resource\traidor.lua:16: attempt to concatenate a boolean value WARNING: resource\traidor.lua:8: Bad argument @ 'getPlayerName' [Expected element at argument 1, got boolean] ERROR: resource\traidor.lua:8: attempt to concatenate a boolean value local msgs = {'traidor', 'espia', 'malo'} local randomPlayer = getRandomPlayer ( ) addCommandHandler ("traidor", function() local text = msgs [ math.random ( #msgs )] outputChatBox ( "* #FFFFFF"..getPlayerName ( randomPlayer ).." #0080FFes el #FF8000"..text.." #0080FFen cubierto!",root, 255, 255, 255, true ) end ) addEventHandler("onPlayerChat",getRootElement(), function(message,messageType,randomPlayer) if message == "!traidor" then local text = msgs [ math.random ( #msgs )] outputChatBox ( "* #FFFFFF"..getPlayerName ( randomPlayer ).." #0080FFes el #FF8000"..text.." #0080FFen cubierto!", getRootElement(), 255, 255, 255, true ) end end ) Link to comment
Jaysds1 Posted October 20, 2013 Share Posted October 20, 2013 try this: local msgs = {'traidor', 'espia', 'malo'} addCommandHandler ("traidor", function() local text = msgs [ math.random ( #msgs )] local randomPlayer = getRandomPlayer() outputChatBox ( "* #FFFFFF"..getPlayerName ( randomPlayer ).." #0080FFes el #FF8000"..text.." #0080FFen cubierto!",root, 255, 255, 255, true ) end ) addEventHandler("onPlayerChat",getRootElement(), function(message,messageType) if message == "!traidor" then local text = msgs [ math.random ( #msgs )] local randomPlayer = getRandomPlayer() outputChatBox ( "* #FFFFFF"..getPlayerName ( randomPlayer ).." #0080FFes el #FF8000"..text.." #0080FFen cubierto!",root, 255, 255, 255, true ) end end ) Link to comment
Moderators IIYAMA Posted October 20, 2013 Moderators Share Posted October 20, 2013 modification: You don't have to redefine the vehicle when the timer and the function are in the same block. But it is always handy to prevent errors by checking if elements still does exist. disco.timer[source] = setTimer( function() -- veh if isElement(vehicle) then setVehicleOverrideLights(vehicle, 2) setVehicleHeadLightColor(vehicle, math.random(0,255), math.random(0,255), math.random(0,255) ) end end, 150, 0)--vehicle Link to comment
Flipi Posted October 20, 2013 Author Share Posted October 20, 2013 (edited) modification:You don't have to redefine the vehicle when the timer and the function are in the same block. But it is always handy to prevent errors by checking if elements still does exist. disco.timer[source] = setTimer( function() -- veh if isElement(vehicle) then setVehicleOverrideLights(vehicle, 2) setVehicleHeadLightColor(vehicle, math.random(0,255), math.random(0,255), math.random(0,255) ) end end, 150, 0)--vehicle I have an error in this part Error: Warning: resource\server.lua:47: Bad argument @ 'killtimer' [Expected lua-timer at argument 1] local discoTimer = {} local discoState = {} addCommandHandler("disco", function(source) local vehicle = getPedOccupiedVehicle(source) if not vehicle then outputChatBox( "* #0080FFNecesitas un vehiculo para usar el comando!", source, 255, 255, 255, true ) return end if not discoState[source] then discoState[source] = true discoTimer[source] = setTimer( function (veh) setVehicleOverrideLights(veh, 2) setVehicleHeadLightColor(veh, math.random(0,255), math.random(0,255), math.random(0,255) ) end, 150, 0, vehicle) outputChatBox( "* #0080FFDisco light Activado!", source, 255, 255, 255, true ) else outputChatBox( "* #0080FFDisco light Desactivado!", source, 255, 255, 255, true ) if discoTimer[source] then killTimer( discoTimer[source] ) discoState[source] = false setVehicleOverrideLights(vehicle, 1) setVehicleHeadLightColor(vehicle, 255, 255, 255 ) end end end ) addEventHandler( "onResourceStart",resourceRoot, function() for _, players in ipairs( getElementsByType( "player" ) ) do discoState[players] = false end end ) addEventHandler( "onPlayerJoin",root, function() discoState[source] = false end ) addEventHandler( "onPlayerQuit", root, function() discoState[source] = false killTimer( discoTimer[source] ) end ) Edited October 20, 2013 by Guest Link to comment
Flipi Posted October 20, 2013 Author Share Posted October 20, 2013 try this:local msgs = {'traidor', 'espia', 'malo'} addCommandHandler ("traidor", function() local text = msgs [ math.random ( #msgs )] local randomPlayer = getRandomPlayer() outputChatBox ( "* #FFFFFF"..getPlayerName ( randomPlayer ).." #0080FFes el #FF8000"..text.." #0080FFen cubierto!",root, 255, 255, 255, true ) end ) addEventHandler("onPlayerChat",getRootElement(), function(message,messageType) if message == "!traidor" then local text = msgs [ math.random ( #msgs )] local randomPlayer = getRandomPlayer() outputChatBox ( "* #FFFFFF"..getPlayerName ( randomPlayer ).." #0080FFes el #FF8000"..text.." #0080FFen cubierto!",root, 255, 255, 255, true ) end end ) wow thanks !! 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