Tadpole Posted August 11, 2009 Share Posted August 11, 2009 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
Lordy Posted August 11, 2009 Share Posted August 11, 2009 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
Tadpole Posted August 11, 2009 Author Share Posted August 11, 2009 Okay i done as u said Lordy and this time i got bad Ped pointer at getPedOccupiedVehicle line 2 i tryed changeing it from sourcePlayer to thePlayer and it still gives me bad arrguments Link to comment
50p Posted August 11, 2009 Share Posted August 11, 2009 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
Tadpole Posted August 11, 2009 Author Share Posted August 11, 2009 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 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
50p Posted August 11, 2009 Share Posted August 11, 2009 - 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
Tadpole Posted August 11, 2009 Author Share Posted August 11, 2009 - 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
50p Posted August 11, 2009 Share Posted August 11, 2009 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
Vercetti1010 Posted August 11, 2009 Share Posted August 11, 2009 - 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
Tadpole Posted August 11, 2009 Author Share Posted August 11, 2009 Yes that worked thanks 50p now i see all the stuff i didnt put in and maybe ill have a new understanding on it @Vercetti: ill try to remember that i'll try to pay more attention to what im doing next time Link to comment
50p Posted August 11, 2009 Share Posted August 11, 2009 - 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
DutchCaffeine Posted August 11, 2009 Share Posted August 11, 2009 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 ) Link to comment
Tadpole Posted August 12, 2009 Author Share Posted August 12, 2009 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 ) 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 Link to comment
DutchCaffeine Posted August 12, 2009 Share Posted August 12, 2009 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 ) 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 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
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