amm2100 Posted July 11, 2015 Share Posted July 11, 2015 (edited) function spawncar( thePlayer ) destroyElement( vechical ) local x,y,z = getElementPosition( thePlayer ) local vechical = createVehicle( 468, x, y, z ) warpPedIntoVehicle ( thePlayer, vechical ) attachElements( vehical, thePlayer ) local PlayerBike = getElementAttachedTo ( thePlayer ) for k,v in pairs(PlayerBike) do destroyElement( source ) end end addCommandHandler( "create", spawncar) I need when the player call the function again the 1st Vehicle Destroy 1st I try to destroy the vehicle 2nd I try to attach the vehicle to the player and then destroy all the Attached Element to PLayer But it doesn't work the vehicle didn't destroy and I got error on Console that the table have boolean Edited July 16, 2015 by Guest Link to comment
Calculador Posted July 11, 2015 Share Posted July 11, 2015 function spawncar( thePlayer ) destroyElement( vechical ) local x,y,z = getElementPosition( thePlayer ) local vechical = createVehicle( 468, x, y, z ) warpPedIntoVehicle ( thePlayer, vechical ) attachElements( vehical, thePlayer ) local PlayerBike = getElementAttachedTo ( thePlayer ) for k,v in pairs(PlayerBike) do destroyElement( source ) end end addCommandHandler( "create", spawncar) I need when the player call the function again the 1st Vehicle Destroy 1st I try to destroy the vehicle 2nd I try to attach the vehicle to the player and then destroy all the Attached Element to PLayer But it doesn't work the vehicle didn't destroy and I got error on Console that the table have boolean The error is in "attachElements", is "vechical", you put "vehical". function spawncar( thePlayer ) destroyElement( vechical ) local x,y,z = getElementPosition( thePlayer ) local vechical = createVehicle( 468, x, y, z ) warpPedIntoVehicle ( thePlayer, vechical ) attachElements( vechical , thePlayer ) local PlayerBike = getElementAttachedTo ( thePlayer ) for k,v in pairs(PlayerBike) do destroyElement( source ) end end addCommandHandler( "create", spawncar) Test it. Link to comment
amm2100 Posted July 11, 2015 Author Share Posted July 11, 2015 I stick with The Car with your Script Link to comment
Calculador Posted July 12, 2015 Share Posted July 12, 2015 I stick with The Car with your Script Mmmh. What do you want exactly? Link to comment
amm2100 Posted July 12, 2015 Author Share Posted July 12, 2015 I want when the Player Spawn another car , the 1st Car Destroy Link to comment
GTX Posted July 12, 2015 Share Posted July 12, 2015 Make vechical variable global. local vechical function spawncar( thePlayer ) if isElement(vechical) then destroyElement( vechical ) end local x,y,z = getElementPosition( thePlayer ) local vechical = createVehicle( 468, x, y, z ) warpPedIntoVehicle ( thePlayer, vechical ) attachElements( vechical , thePlayer ) local PlayerBike = getElementAttachedTo ( thePlayer ) for k,v in pairs(PlayerBike) do destroyElement( source ) end end addCommandHandler( "create", spawncar) But then you need to put it in a table as it might interfere because then you're overwritting a variable over variable. You could destroy other's people vehicle then. This should work I think: local vechical = {} function spawncar( thePlayer ) if isElement(vechical[thePlayer]) then destroyElement( vechical[thePlayer] ) end local x,y,z = getElementPosition( thePlayer ) local vechical[thePlayer] = createVehicle( 468, x, y, z ) warpPedIntoVehicle ( thePlayer, vechical[thePlayer] ) end addCommandHandler( "create", spawncar) Link to comment
amm2100 Posted July 12, 2015 Author Share Posted July 12, 2015 local vechical = {} function spawncar( thePlayer ) if isElement(vechical[thePlayer]) then destroyElement( vechical[thePlayer] ) end local x,y,z = getElementPosition( thePlayer ) local vechical[thePlayer] = createVehicle( 468, x, y, z ) warpPedIntoVehicle ( thePlayer, vechical[thePlayer] ) end addCommandHandler( "create", spawncar) [01:16:42] SCRIPT ERROR: myserver\script.lua:85: unexpected symbol near '[' [01:16:42] ERROR: Loading script failed: myserver\script.lua:85: unexpected symbol near '[' Link to comment
GTX Posted July 12, 2015 Share Posted July 12, 2015 local vechical = {} function spawncar( thePlayer ) if isElement(vechical[thePlayer]) then destroyElement( vechical[thePlayer] ) end local x,y,z = getElementPosition( thePlayer ) vechical[thePlayer] = createVehicle( 468, x, y, z ) warpPedIntoVehicle ( thePlayer, vechical[thePlayer] ) end addCommandHandler( "create", spawncar) Link to comment
amm2100 Posted July 14, 2015 Author Share Posted July 14, 2015 Thank You very Much GTX 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