DazzaJay Posted January 17, 2008 Share Posted January 17, 2008 i found in my random stuffing around a vehicle lights toggle in fr.lua. so i decided to copy those lines out into thier own script so it runs all the time..... problem is, ive boned it up somewhere..... and without knowing a thing about LUA, what have i done wrong...... when i load the script i get the error "WARNING: vehiclelights.lua: Bad argument @ 'bindKey' - Line: 8 local root = getRootElement () local thisResourceRoot = getResourceRootElement(getThisResource()) function thisResourceStart () outputChatBox ( "Headlight Switch loaded! Press L to toggle your car lights on / off!" ) local players = getElementsByType ( "player" ) for k,v in ipairs(players) do bindKey ( v, "l", "down", "Lights on/off", toggleVehicleLights ) end end function playerJoin () outputChatBox ( "You can press L to toggle your car lights on / off!", source ) bindKey ( source, "l", "down", toggleVehicleLights, "Lights on/off" ) end addEventHandler ( "onResourceStart", thisResourceRoot, thisResourceStart ) addEventHandler ( "onPlayerJoin", root, playerJoin ) function toggleVehicleLights ( player, key, state ) if ( getPlayerOccupiedVehicleSeat ( player ) == 0 ) then local veh = getPlayerOccupiedVehicle ( player ) if ( getVehicleOverrideLights ( veh ) ~= 2 ) then setVehicleOverrideLights ( veh, 2 ) else setVehicleOverrideLights ( veh, 1 ) end end end Link to comment
CJGrove Posted January 17, 2008 Share Posted January 17, 2008 Got the same thing with my edit from FR. Link to comment
DazzaJay Posted January 17, 2008 Author Share Posted January 17, 2008 my guess is that im missing somthing..... and if you copyd the same lines, then we are both missing somthing.... Link to comment
CJGrove Posted January 17, 2008 Share Posted January 17, 2008 I think its the fault of previeuw 2 at first it worked fine.... Link to comment
DazzaJay Posted January 17, 2008 Author Share Posted January 17, 2008 its possible, i just went in to test if it worked in the original fr.lua file... and i got this on load.... WARNING: fr.lua: Bad argument @ 'bindKey' - Line: 8 WARNING: fr.lua: Bad argument @ 'bindKey' - Line: 9 so, if DP2 has that broken, then its possible that the script is fine.. but DP2 isnt? Link to comment
[email protected] Posted January 17, 2008 Share Posted January 17, 2008 bindKey ( v, "l", "down", "Lights on/off", toggleVehicleLights ) The syntax of that function is incorrect, the bindKey() function takes the arguments as follows: bindKey ( player thePlayer, string key, string keyState, function handlerFunction, [ var arguments, ... ] ) Therefore, you should change the code in the codeblock to: bindKey ( v, "l", "down", toggleVehicleLights, "Lights on/off" ) And yes, this was also wrong in fr.lua (look at the one in your playerjoin event function, that one is correct). Link to comment
DazzaJay Posted January 18, 2008 Author Share Posted January 18, 2008 Wow, thanks for that! it works well now! Link to comment
[email protected] Posted January 18, 2008 Share Posted January 18, 2008 Wow, thanks for that! it works well now! You may also have a look at http://development.mtasa.com for the correct function specifications Link to comment
DazzaJay Posted January 20, 2008 Author Share Posted January 20, 2008 and for anyone else who wants this pointless script.... this is the vehiclelights.jua file local root = getRootElement () local thisResourceRoot = getResourceRootElement(getThisResource()) function thisResourceStart () outputChatBox ( "Headlight Switch loaded! Press L to toggle your car lights on / off!" ) local players = getElementsByType ( "player" ) for k,v in ipairs(players) do bindKey ( v, "l", "down", toggleVehicleLights, "Lights on/off" ) end end function playerJoin () outputChatBox ( "You can press L to toggle your car lights on / off!", source ) bindKey ( source, "l", "down", toggleVehicleLights, "Lights on/off" ) end addEventHandler ( "onResourceStart", thisResourceRoot, thisResourceStart ) addEventHandler ( "onPlayerJoin", root, playerJoin ) function toggleVehicleLights ( player, key, state ) if ( getPlayerOccupiedVehicleSeat ( player ) == 0 ) then local veh = getPlayerOccupiedVehicle ( player ) if ( getVehicleOverrideLights ( veh ) ~= 2 ) then setVehicleOverrideLights ( veh, 2 ) else setVehicleOverrideLights ( veh, 1 ) end end end this is the meta.xml <meta> <script src="vehiclelights.lua" /> <info author="Ripped from fr by DazzaJay" /> </meta> put them two files into vehiclelights.zip file and place in your servers \mods\deathmatch\resources\ folder. To have this start when the server is loaded.... put this in your mtaserver.conf <resource src="vehiclelights" startup="1" protected="0"/> ----------------------------------------------------------- If you want the ability to Lock / unlock your cars doors, use this vehiclelights.lua file instead of the one above.... local root = getRootElement () local thisResourceRoot = getResourceRootElement(getThisResource()) function thisResourceStart () outputChatBox ( "Headlight Switch loaded! Press L to toggle your car lights on / off!" ) local players = getElementsByType ( "player" ) for k,v in ipairs(players) do bindKey ( v, "k", "down", toggleVehicleLock, "Lock/unlock door" ) bindKey ( v, "l", "down", toggleVehicleLights, "Lights on/off" ) end end function playerJoin () outputChatBox ( "You can press L to toggle your car lights on / off!", source ) bindKey ( source, "l", "down", toggleVehicleLights, "Lights on/off" ) bindKey ( source, "k", "down", toggleVehicleLock, "Lock/unlock door" ) end addEventHandler ( "onResourceStart", thisResourceRoot, thisResourceStart ) addEventHandler ( "onPlayerJoin", root, playerJoin ) function toggleVehicleLights ( player, key, state ) if ( getPlayerOccupiedVehicleSeat ( player ) == 0 ) then local veh = getPlayerOccupiedVehicle ( player ) if ( getVehicleOverrideLights ( veh ) ~= 2 ) then setVehicleOverrideLights ( veh, 2 ) else setVehicleOverrideLights ( veh, 1 ) end end end function toggleVehicleLock ( player, key, state ) if ( getPlayerOccupiedVehicleSeat ( player ) == 0 ) then local veh = getPlayerOccupiedVehicle ( player ) if ( isVehicleLocked ( veh ) ) then setVehicleLocked ( veh, false ) else setVehicleLocked ( veh, true ) end end end Link to comment
Recommended Posts