International Gaming Community

Outside IGC => Scripting => Topic started by: Gat on March 29, 2018, 11:25:18 pm

Title: [LUA]Light of cars
Post by: Gat on March 29, 2018, 11:25:18 pm
Enable or disable vehicles lights by pressing "L" button
Code: (server) [Select]
local p = getVehicleController( source )
function lights()
   if isPedInVehicle(source) then --if player in car then
   --get the car of the controller, lets call it gat
   gat = getPedOccupiedVehicle(source)
         if (gat) then --check if gat is here (the vehicle)
           if ( getVehicleOverrideLights ( gat ) ~= 2 ) then --check if lights arent on
          setVehicleOverrideLights ( gat, 2 ) --set it on
          else
              setVehicleOverrideLights ( gat, 1 ) --set it off if it already on
           end
        end
   end
end
bindKey(p, "l", "down", lights) --bind this function in L button to trigger it.
--or
addCommandHandler("lights", lights) -- trigger it by /lights
Another way
Code: (server) [Select]
local p = getVehicleController(source)
addCommandHandler("lights",
--or
bindKey(p, "l", "down",
function()
   if isPedInVehicle(source) then --if player in car then
   --get the car of the controller, lets call it gat
   local gat = getPedOccupiedVehicle(source)
         if ( gat ) then --check if gat is here (the Vehicle)
           if ( getVehicleOverrideLights ( gat ) == 0 ) or ( getVehicleOverrideLights ( playerVehicle ) == 1 ) then --check if lights arent on
          setVehicleOverrideLights ( gat, 2 ) --set it on
          else
              setVehicleOverrideLights ( gat, 1 ) --set it off if it already on
           end
        end
   end
end
)
https://forum.igcrpg.com/?topic=4064.msg23978#new
Just practice to myself :)
@Phantom
Title: Re: [LUA]Light of cars
Post by: Phantom on March 30, 2018, 04:30:28 am
Cool, So you're saying we can use this script to switch on/off vehicle Head Lights? @Gat
Title: Re: [LUA]Light of cars
Post by: External on March 30, 2018, 10:52:39 am
Quote
bindKey(gat, "l", "down", lights) --bind this function in L button to trigger it.
bindKey(gat)?
first argument is a player not a vehicle
Title: Re: [LUA]Light of cars
Post by: Gat on March 30, 2018, 11:16:04 am
Cool, So you're saying we can use this script to switch on/off vehicle Head Lights? @Gat
Yes @Phantom
Title: Re: [LUA]Light of cars
Post by: Gat on March 30, 2018, 11:29:39 am
bindKey(gat)?
first argument is a player not a vehicle
Oh sorry i thought gat is the vairable for who control the car, thnx @External [Edited]
Title: Re: [LUA]Light of cars
Post by: Gat on March 30, 2018, 02:57:53 pm
@External my old tuts were when i was newbie in scripting, but now ik how to work well with lua and fix errors, inside i have some of worked scripts
Title: Re: [LUA]Light of cars
Post by: ForLaX on April 09, 2018, 09:58:33 am
Spoiler: show
Enable or disable vehicles lights by pressing "L" button
Code: (server) [Select]
local p = getVehicleController( source )
function lights()
   if isPedInVehicle(source) then --if player in car then
   --get the car of the controller, lets call it gat
   gat = getPedOccupiedVehicle(source)
         if (gat) then --check if gat is here (the vehicle)
           if ( getVehicleOverrideLights ( gat ) ~= 2 ) then --check if lights arent on
          setVehicleOverrideLights ( gat, 2 ) --set it on
          else
              setVehicleOverrideLights ( gat, 1 ) --set it off if it already on
           end
        end
   end
end
bindKey(p, "l", "down", lights) --bind this function in L button to trigger it.
--or
addCommandHandler("lights", lights) -- trigger it by /lights
Another way
Code: (server) [Select]
local p = getVehicleController(source)
addCommandHandler("lights",
--or
bindKey(p, "l", "down",
function()
   if isPedInVehicle(source) then --if player in car then
   --get the car of the controller, lets call it gat
   local gat = getPedOccupiedVehicle(source)
         if ( gat ) then --check if gat is here (the Vehicle)
           if ( getVehicleOverrideLights ( gat ) == 0 ) or ( getVehicleOverrideLights ( playerVehicle ) == 1 ) then --check if lights arent on
          setVehicleOverrideLights ( gat, 2 ) --set it on
          else
              setVehicleOverrideLights ( gat, 1 ) --set it off if it already on
           end
        end
   end
end
)
https://forum.igcrpg.com/?topic=4064.msg23978#new
Just practice to myself :)

Or just this.
Code: (lua) [Select]
--Client side
function lightss()
if (not isPedInVehicle(localPlayer)) then
return false
end
local veh = getPedOccupiedVehicle(localPlayer)
if (getVehicleOverrideLights(veh) ~= 2) then
        setVehicleOverrideLights(veh, 2)
    else
        setVehicleOverrideLights(veh, 1)
    end
end
addCommandHandler("lights", lights)

Your client script has some issues for eg.
'bindKey(p, "l", "down", lights)' just use 'bindKey("l", "down", lights)' and
'local p = getVehicleController( source )' what if the player isn't in a vehicle, the debug would get spammy as hell also which source? You don't even have an event that has the veh as source, same for 'isPedInVehicle(source)' . I tested your script in the localhost and it didn't worked You can check mt version up, it's simple and doing the job. Will check the server side too later.
SimplePortal 2.3.7 © 2008-2024, SimplePortal