Jump to content

[Help] (Done)


amm2100

Recommended Posts

  
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 by Guest
Link to comment
  
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

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

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