Quantcast

Author Topic: [LUA]Light of cars  (Read 6973 times)

0 Members and 1 Guest are viewing this topic.

Offline Gat

  • Honourable
  • *****
  • Gat bat mat sat sad fat cat dat Nat chat rat
[LUA]Light of cars
« 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
« Last Edit: March 30, 2018, 11:52:17 am by Gat »

Offline Phantom

  • Start to accept and move on
  • Group: San Andreas Worker's Party
  • In-Game Name: Phantom
Re: [LUA]Light of cars
« Reply #1 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
« Last Edit: March 30, 2018, 07:52:46 am by Phantom »

Re: [LUA]Light of cars
« Reply #2 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

Offline Gat

  • Honourable
  • *****
  • Gat bat mat sat sad fat cat dat Nat chat rat
Re: [LUA]Light of cars
« Reply #3 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
« Last Edit: March 30, 2018, 11:32:20 am by Gat »

Offline Gat

  • Honourable
  • *****
  • Gat bat mat sat sad fat cat dat Nat chat rat
Re: [LUA]Light of cars
« Reply #4 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]
« Last Edit: March 30, 2018, 11:33:12 am by Gat »

Offline Gat

  • Honourable
  • *****
  • Gat bat mat sat sad fat cat dat Nat chat rat
Re: [LUA]Light of cars
« Reply #5 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
« Last Edit: March 30, 2018, 03:20:41 pm by Gat »

Offline ForLaX

  • 128 BPM
  • Group: ForLaX
Re: [LUA]Light of cars
« Reply #6 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.
« Last Edit: April 09, 2018, 11:28:59 am by ForLaX »

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal