boro Posted May 11, 2013 Share Posted May 11, 2013 Hi all i have script for destroy vehicle when player leave vehicle .. It work fine but when player quit from server and is in car then car dont be destroyed or if is player in car and is killed then car still dont are deleted why ? Please help function removeHelmetOnExit ( vehicle, seat ) if ( getElementModel ( vehicle ) == 579 or 494 or 424 or 589 or 469 or 500 or 504 or 497 or 434 or 490 or 489 or 474 or 461 or 521 or 470 or 495 or 601 or 548 or 487 ) then if checkEmpty( vehicle ) then local seats = getVehicleMaxPassengers(vehicle) destroyElement(vehicle) end end end addEventHandler ( "onPlayerVehicleExit", getRootElement(), removeHelmetOnExit ) function checkEmpty( vehicle ) local passengers = getVehicleMaxPassengers( vehicle ) if type( passengers ) == 'number' then for seat = 0, passengers do if getVehicleOccupant( vehicle, seat ) then return false end end end return true end Link to comment
boro Posted May 11, 2013 Author Share Posted May 11, 2013 yes i try this too but it still dont work function removeHelmetOnExit ( vehicle, seat ) if ( getElementModel ( vehicle ) == 579 or 494 or 424 or 589 or 469 or 500 or 504 or 497 or 434 or 490 or 489 or 474 or 461 or 521 or 470 or 495 or 601 or 548 or 487 ) then if checkEmpty( vehicle ) then local seats = getVehicleMaxPassengers(vehicle) destroyElement(vehicle) outputChatBox ( "#FF0000Your car has been #00FF00Destroyed, use f4 or go to the safe zone for new car", source, 255, 255, 255, true ) end end end addEventHandler ( "onPlayerVehicleExit", getRootElement(), removeHelmetOnExit ) function checkEmpty( vehicle ) local passengers = getVehicleMaxPassengers( vehicle ) if type( passengers ) == 'number' then for seat = 0, passengers do if getVehicleOccupant( vehicle, seat ) then return false end end end return true end function quitPlayer ( vehicle, seat ) if ( getElementModel ( vehicle ) == 579 or 494 or 424 or 589 or 469 or 500 or 504 or 497 or 434 or 490 or 489 or 474 or 461 or 521 or 470 or 495 or 601 or 548 or 487 ) then if checkEmpty( vehicle ) then local seats = getVehicleMaxPassengers(vehicle) destroyElement(vehicle) end end end addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer ) Link to comment
DiSaMe Posted May 11, 2013 Share Posted May 11, 2013 Event "onPlayerQuit" doesn't have any vehicle parameters. Link to comment
boro Posted May 11, 2013 Author Share Posted May 11, 2013 hmm i repair it and still dont work function removeHelmetOnExit ( vehicle, seat ) if ( getElementModel ( vehicle ) == 579 or 494 or 424 or 589 or 469 or 500 or 504 or 497 or 434 or 490 or 489 or 474 or 461 or 521 or 470 or 495 or 601 or 548 or 487 ) then if checkEmpty( vehicle ) then local seats = getVehicleMaxPassengers(vehicle) destroyElement(vehicle) outputChatBox ( "#FF0000Your car has been #00FF00Destroyed, use f4 or go to the safe zone for new car", source, 255, 255, 255, true ) end end end addEventHandler ( "onPlayerVehicleExit", getRootElement(), removeHelmetOnExit ) function checkEmpty( vehicle ) local passengers = getVehicleMaxPassengers( vehicle ) if type( passengers ) == 'number' then for seat = 0, passengers do if getVehicleOccupant( vehicle, seat ) then return false end end end return true end function quitPlayer ( ) if ( getElementModel ( vehicle ) == 579 or 494 or 424 or 589 or 469 or 500 or 504 or 497 or 434 or 490 or 489 or 474 or 461 or 521 or 470 or 495 or 601 or 548 or 487 ) then if checkEmpty( vehicle ) then local seats = getVehicleMaxPassengers(vehicle) destroyElement(vehicle) end end end addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer ) Link to comment
boro Posted May 11, 2013 Author Share Posted May 11, 2013 ah yes now it work ty function quitPlayer ( ) for k, vehicle in pairs(getElementsByType("vehicle")) do if ( getElementModel ( vehicle ) == 579 or 494 or 424 or 589 or 469 or 500 or 504 or 497 or 434 or 490 or 489 or 474 or 461 or 521 or 470 or 495 or 601 or 548 or 487 ) then if checkEmpty( vehicle ) then local seats = getVehicleMaxPassengers(vehicle) destroyElement(vehicle) end end end end addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer ) Link to comment
3NAD Posted May 11, 2013 Share Posted May 11, 2013 I didn't try it. IDs = { 579, 494, 424, 589, 469, 500, 504, 497, 434, 490, 489, 474, 461, 521, 470, 495, 601, 548, 487 } function quitPlayer ( ) for k, vehicle in pairs ( getElementsByType ( "vehicle" ) ) do if IDs [ getElementModel ( vehicle ) ] then if checkEmpty ( vehicle ) then destroyElement ( vehicle ) end end end end addEventHandler ( "onPlayerQuit", root, quitPlayer ) checkEmpty = function ( vehicle ) if #getVehicleOccupants ( vehicle ) == 0 then return true else return false end end Link to comment
فاّرس Posted May 11, 2013 Share Posted May 11, 2013 Humm , the best is make table, try this, local vehicles = {"579","494","424","589","469","500","504","497","434","490","489","474","461","521","470","495","601","548","497"} function quitPlayer() if checkEmpty( vehicle ) then local seats = getVehicleMaxPassengers(vehicle) if (isElement(vehicles)) then destroyElement(vehicles) end end end addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer ) Link to comment
Tete omar Posted May 11, 2013 Share Posted May 11, 2013 I didn't try it. IDs = { 579, 494, 424, 589, 469, 500, 504, 497, 434, 490, 489, 474, 461, 521, 470, 495, 601, 548, 487 } function quitPlayer ( ) for k, vehicle in pairs ( getElementsByType ( "vehicle" ) ) do if IDs [ getElementModel ( vehicle ) ] then if checkEmpty ( vehicle ) then destroyElement ( vehicle ) end end end end addEventHandler ( "onPlayerQuit", root, quitPlayer ) checkEmpty = function ( vehicle ) if #getVehicleOccupants ( vehicle ) == 0 then return true else return false end end IDs = { 579, 494, 424, 589, 469, 500, 504, 497, 434, 490, 489, 474, 461, 521, 470, 495, 601, 548, 487 } function quitPlayer ( ) for k, vehicle in ipairs ( getElementsByType ( "vehicle" ) ) do if IDs [ getElementModel ( vehicle ) ] then if checkEmpty ( vehicle ) then destroyElement ( vehicle ) end end end end addEventHandler ( "onPlayerQuit", root, quitPlayer ) checkEmpty = function ( vehicle ) if #getVehicleOccupants ( vehicle ) == 0 then return true else return false end end Link to comment
3NAD Posted May 11, 2013 Share Posted May 11, 2013 IDs = { 579, 494, 424, 589, 469, 500, 504, 497, 434, 490, 489, 474, 461, 521, 470, 495, 601, 548, 487 } function quitPlayer ( ) for k, vehicle in ipairs ( getElementsByType ( "vehicle" ) ) do if IDs [ getElementModel ( vehicle ) ] then if checkEmpty ( vehicle ) then destroyElement ( vehicle ) end end end end addEventHandler ( "onPlayerQuit", root, quitPlayer ) checkEmpty = function ( vehicle ) if #getVehicleOccupants ( vehicle ) == 0 then return true else return false end end Could you tell me, what did you do ? Link to comment
boro Posted May 11, 2013 Author Share Posted May 11, 2013 this is good for this but ty my old script work fine local IDs = { 579, 494, 424, 589, 469, 500, 504, 497, 434, 490, 489, 474, 461, 521, 470, 495, 601, 548, 487 } function quitPlayer ( ) for k, vehicle in pairs ( getElementsByType ( "vehicle" ) ) do if IDs [ getElementModel ( vehicle ) ] then if checkEmpty ( vehicle ) then destroyElement ( vehicle ) end end end end addEventHandler ( "onPlayerQuit", root, quitPlayer ) checkEmpty = function ( vehicle ) if #getVehicleOccupants ( vehicle ) == 0 then return true else return false end end Link to comment
Tete omar Posted May 11, 2013 Share Posted May 11, 2013 Could you tell me, what did you do ? Could you tell me why are you looping pairs? Link to comment
iPrestege Posted May 11, 2013 Share Posted May 11, 2013 @ 3NAD and Tete The table is wrong . Link to comment
Tete omar Posted May 11, 2013 Share Posted May 11, 2013 @ 3NAD and TeteThe table is wrong . which table Link to comment
فاّرس Posted May 11, 2013 Share Posted May 11, 2013 Humm , the best is make table,try this, local vehicles = {"579","494","424","589","469","500","504","497","434","490","489","474","461","521","470","495","601","548","497"} function quitPlayer() if checkEmpty( vehicle ) then local seats = getVehicleMaxPassengers(vehicle) if (isElement(vehicles)) then destroyElement(vehicles) end end end addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer ) I think this is true. Link to comment
3NAD Posted May 11, 2013 Share Posted May 11, 2013 which table Our replies has the same Table Link to comment
Tete omar Posted May 11, 2013 Share Posted May 11, 2013 The 'IDs' table . What do you think wrong in this table which table Our replies has the same Table okay? Link to comment
iPrestege Posted May 11, 2013 Share Posted May 11, 2013 Enad table was wrong the table should be : local IDs = { [411] = true, [429] = true } Link to comment
Tete omar Posted May 11, 2013 Share Posted May 11, 2013 Enad table was wrong the table should be : local IDs = { [411] = true, [429] = true } Nah, 3nad just forgot to loop them with ipairs because no need for pairs unless table contains pairs, 3nad's code will work 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