Jump to content

Then expected near =


Fabio(GNR)

Recommended Posts

I didn't script for a long time, but i tried to create this: At taalismas vehicle_panel players can spawn vehicles forever, so i tried to create a thing that destroys the previous vehicle spawned, please don't get angry because my script isn't good...

Code:

car1 = false 
  
function spawnAcar(carID, playerSource) 
    for i,v in ipairs (disallowedVehicle) do 
        if (v[1] == carID) then 
            outputChatBox("This is disallowed vehicle!",source,255,0,0) 
            return false 
        end 
    end 
    playerX,playerY,playerZ = getElementPosition(source) 
>   if car1 = true then 
    destroyElement ( vehicle )  
    else 
    vehicle = createVehicle ( carID,playerX + 1,playerY +1, playerZ +0.5 ) 
    warpPedIntoVehicle ( source, vehicle ) 
    car1 = true 
end 

correcting me or a better way is helpful :P The error it gives is: ( on startup )

Script error: Then expected near = ( at the > in code ) help please.

Link to comment
car1 = false 
  
function spawnAcar(carID, playerSource) 
    for i,v in ipairs (disallowedVehicle) do 
        if (v[1] == carID) then 
            outputChatBox("This is disallowed vehicle!",source,255,0,0) 
            return false 
        end 
    end 
    playerX,playerY,playerZ = getElementPosition(source) 
    if car1 == true then 
    destroyElement ( vehicle ) 
    else 
    vehicle = createVehicle ( carID,playerX + 1,playerY +1, playerZ +0.5 ) 
    warpPedIntoVehicle ( source, vehicle ) 
    car1 = true 
    end 
end 

Link to comment
this way server will have only 1 car for all players.

lol yeah i found out, how do i make it locally? the script now:

car1 = false 
  
function spawnAcar(carID, playerSource) 
    for i,v in ipairs (disallowedVehicle) do 
        if (v[1] == carID) then 
            outputChatBox("This is disallowed vehicle!",source,255,0,0) 
            return false 
        end 
    end 
    playerX,playerY,playerZ = getElementPosition(source) 
    if car1 == true then 
    destroyElement ( vehicle )  
    vehicle = createVehicle ( carID,playerX +0,playerY +0, playerZ +0.5 ) 
    warpPedIntoVehicle ( source, vehicle ) 
    car1 = true 
     
    else 
    vehicle = createVehicle ( carID,playerX +0,playerY +0, playerZ +0.5 ) 
    warpPedIntoVehicle ( source, vehicle ) 
    car1 = true 
    end 
end 

yeah, aiboforcen its right, lol.

you should make some other check like element data.

im not really good at scripting could you help me with this?

Link to comment
addEventHandler("onPlayerJoin",getRootElement(), 
function () 
setElementData(source,"car1",false) 
end) 
  
function spawnAcar(carID, playerSource) 
    for i,v in ipairs (disallowedVehicle) do 
        if (v[1] == carID) then 
            outputChatBox("This is disallowed vehicle!",source,255,0,0) 
            return false 
        end 
    end 
    playerX,playerY,playerZ = getElementPosition(source) 
    if getElementData(source,"car1") == true then 
    destroyElement ( vehicle ) 
    vehicle = createVehicle ( carID,playerX +0,playerY +0, playerZ +0.5 ) 
    warpPedIntoVehicle ( source, vehicle ) 
    setElementData(source,"car1",false) 
    else 
    vehicle = createVehicle ( carID,playerX +0,playerY +0, playerZ +0.5 ) 
    warpPedIntoVehicle ( source, vehicle ) 
    setElementData(source,"car1",true) 
    end 
end 

Link to comment

it still has only 1 vehicle variable.

vehicles = {} 
  
function spawnAcar(carID, playerSource) 
  for i,v in ipairs (disallowedVehicle) do 
    if (v[1] == carID) then 
      outputChatBox("This is disallowed vehicle!",source,255,0,0) 
      return false 
    end 
  end 
  local playerX,playerY,playerZ = getElementPosition(source) 
  if vehicles[source] and isElement(vehicles[source]) then 
    destroyElement(vehicles[source]) 
  end 
  vehicles[source] = createVehicle(carID, playerX, playerY, playerZ + 0.5) 
  warpPedIntoVehicle(source, vehicles[source]) 
end 

Link to comment
addEventHandler("onPlayerJoin",getRootElement(), 
function () 
setElementData(source,"car1",false) 
end) 
  
function spawnAcar(carID, playerSource) 
    for i,v in ipairs (disallowedVehicle) do 
        if (v[1] == carID) then 
            outputChatBox("This is disallowed vehicle!",source,255,0,0) 
            return false 
        end 
    end 
    playerX,playerY,playerZ = getElementPosition(source) 
    if getElementData(source,"car1") == true then 
    destroyElement ( vehicle ) 
    vehicle = createVehicle ( carID,playerX +0,playerY +0, playerZ +0.5 ) 
    warpPedIntoVehicle ( source, vehicle ) 
    setElementData(source,"car1",false) 
    else 
    vehicle = createVehicle ( carID,playerX +0,playerY +0, playerZ +0.5 ) 
    warpPedIntoVehicle ( source, vehicle ) 
    setElementData(source,"car1",true) 
    end 
end 

thanks but it doesnt work, it still spawn alot of vehicles, deleting the limit

Link to comment

but reference to a vehicle stored in global "vehicle" variable will be gone next time someone spawns another car.

new car will be stored in this variable.

element data does really nothing here. yes it says if certain player has a car spawned, but nothing more.

to elaborate:

player1 spawned a car: player1car1 == true, vehicle = player1's car

player2 spawned a car: player2car1 == true, vehicle = player2's car

player1 spawned another car. guess who's car will be deleted?

Link to comment
it still has only 1 vehicle variable.
vehicles = {} 
  
function spawnAcar(carID, playerSource) 
  for i,v in ipairs (disallowedVehicle) do 
    if (v[1] == carID) then 
      outputChatBox("This is disallowed vehicle!",source,255,0,0) 
      return false 
    end 
  end 
  local playerX,playerY,playerZ = getElementPosition(source) 
  if vehicles[source] and isElement(vehicles[source]) then 
    destroyElement(vehicles[source]) 
  end 
  vehicles[source] = createVehicle(carID, playerX, playerY, playerZ + 0.5) 
  warpPedIntoVehicle(source, vehicles[source]) 
end 

Thanks aiboforcen it works!! And thanks to solidsnake14!! it works now with aiboforcen's script but thank tough solidsnake14 :P

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