Jump to content

Car Indicator's help ?


Tadpole

Recommended Posts

So I'm making this script to make the rear lights flash on command and i keep gritting Bad Argument @ getPedOccupiedVehicle - line 2 Ive tryed every thing i can think of to fix it and i admit failure >.> help me please? ^^

function flashl ( sourcePlayer )
local theVehicle = getPedOccupiedVehicle ( sourcePlayer )
if ( theVehicle ) then
setVehicleLightState ( theVehicle, 3, 0 )
setVehicleLightState ( theVehicle, 3, 1 )
end
end
function flashr ( sourcePlayer )
local theVehicle = getPedOccupiedVehicle ( sourcePlayer )
if ( theVehicle ) then
setVehicleLightState ( theVehicle, 2, 0 )
setVehicleLightState ( theVehicle, 2, 1 )
end
end
function carflashl ()
setTimer ( flashl, 1000, 10 )
end
function carflashr ()
setTimer ( flashr, 1000, 10 )
end
addCommandHandler("lf", carflashl)
addCommandHandler("rf", carflashr)

Link to comment

You need to pass the sourcePlayer argument to flash1/flash2 functions. You currently call the timer functions by command so change it to

function flashl ( sourcePlayer )
local theVehicle = getPedOccupiedVehicle ( sourcePlayer )
if ( theVehicle ) then
setVehicleLightState ( theVehicle, 3, 0 )
setVehicleLightState ( theVehicle, 3, 1 )
end
end
function flashr ( sourcePlayer )
local theVehicle = getPedOccupiedVehicle ( sourcePlayer )
if ( theVehicle ) then
setVehicleLightState ( theVehicle, 2, 0 )
setVehicleLightState ( theVehicle, 2, 1 )
end
end
function carflashl (thePlayer)
setTimer ( flashl, 1000, 10,thePlayer )
end
function carflashr (thePlayer)
setTimer ( flashr, 1000, 10 ,thePlayer)
end
addCommandHandler("lf", carflashl)
addCommandHandler("rf", carflashr)

Link to comment

If it's client-side script you will fail because command handler doesn't pass player/ped element to functions. If it's server-side I don't see anything wrong and will test this code when I wake up if you'll still have problem with this.

Link to comment

Well i Recoded it to Client-side and it got rid of my error but now it just isint turning off the light when i type in the command :o

new code's

function flashl ( source )
local theVehicle = getVehicleOccupant ( theVehicle, 0 )
if ( theVehicle ) then
setVehicleLightState ( theVehicle, 3, 0 )
setVehicleLightState ( theVehicle, 3, 1 )
end
end
function flashr ( source )
local theVehicle = getVehicleOccupant ( theVehicle, 0 )
if ( theVehicle ) then
setVehicleLightState ( theVehicle, 2, 0 )
setVehicleLightState ( theVehicle, 2, 1 )
end
end
function carflashl (source)
setTimer ( flashl, 1000, 10 )
end
function carflashr (source)
setTimer ( flashr, 1000, 10 )
end
addCommandHandler("lf", carflashl)
addCommandHandler("rf", carflashr)

Link to comment

- What is theVehicle in your code (eg. line 2, in getVehicleOccupant call)?

- Are you sure theVehicle a vehicle element?

- Why do you use getVehicleOccupant (get the driver of theVehicle) and use setVehicleLightState on the driver?

Link to comment
- What is theVehicle in your code (eg. line 2, in getVehicleOccupant call)?

- Are you sure theVehicle a vehicle element?

- Why do you use getVehicleOccupant (get the driver of theVehicle) and use setVehicleLightState on the driver?

well i guess i made a mistake when codeing it i didnt realize i was useing setVehicleLightState on the driver but now i do so i can recode it now and fix my noobish mistakes :)

Link to comment

This code is server-side and should work:

function flashl ( player )
local theVehicle = getPedOccupiedVehicle( player )
if ( theVehicle and getVehicleOccupant( theVehicle ) == player ) then -- this will also check if player is the driver
local state = getVehicleLightState( theVehicle, 3 );
setVehicleLightState ( theVehicle, 3, (state == 0) and 1 or 0 )
end
end
function flashr ( player )
local theVehicle = getPedOccupiedVehicle( player )
if ( theVehicle and getVehicleOccupant( theVehicle ) == player ) then -- this will also check if player is the driver
local state = getVehicleLightState( theVehicle, 2 );
setVehicleLightState ( theVehicle, 2, (state == 0) and 1 or 0 )
end
end
function carflashl ( player )
setTimer ( flashl, 1000, 10, player )
end
function carflashr ( player )
setTimer ( flashr, 1000, 10, player )
end
addCommandHandler("lf", carflashl)
addCommandHandler("rf", carflashr)

Link to comment
- What is theVehicle in your code (eg. line 2, in getVehicleOccupant call)?

- Are you sure theVehicle a vehicle element?

- Why do you use getVehicleOccupant (get the driver of theVehicle) and use setVehicleLightState on the driver?

well i guess i made a mistake when codeing it i didnt realize i was useing setVehicleLightState on the driver but now i do so i can recode it now and fix my noobish mistakes :)

Next time just make sure you check what the source of your event/command is and what the functions you use return. That can save you a lot of hassle and perhaps save from using unnecessary variables.

Link to comment
- What is theVehicle in your code (eg. line 2, in getVehicleOccupant call)?

- Are you sure theVehicle a vehicle element?

- Why do you use getVehicleOccupant (get the driver of theVehicle) and use setVehicleLightState on the driver?

well i guess i made a mistake when codeing it i didnt realize i was useing setVehicleLightState on the driver but now i do so i can recode it now and fix my noobish mistakes :)

Next time just make sure you check what the source of your event/command is and what the functions you use return. That can save you a lot of hassle and perhaps save from using unnecessary variables.

Actually, source is not passed to the command handler function but events. Even though, NEVER use source in the parameters list because function will get confused and you will get unexpected results.

Link to comment
I'm busy atm. with a resource that will contain this. And it will be better then the source you got! (And it will have some more options! But i don't tell them :P )

Im gonna have to update mine alot tho atleast so u can see the blinker in the daytime and to toggle it on and off so i can git rid of the command..but it works for now :D

Link to comment
I'm busy atm. with a resource that will contain this. And it will be better then the source you got! (And it will have some more options! But i don't tell them :P )

Im gonna have to update mine alot tho atleast so u can see the blinker in the daytime and to toggle it on and off so i can git rid of the command..but it works for now :D

The mine allready works, and blings also and you can turn it on and off in daytime!!!! Only got some key probs with the flashers now (warning flashers)

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