Fabio(GNR) Posted December 25, 2010 Share Posted December 25, 2010 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 The error it gives is: ( on startup ) Script error: Then expected near = ( at the > in code ) help please. Link to comment
Castillo Posted December 25, 2010 Share Posted December 25, 2010 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
Fabio(GNR) Posted December 25, 2010 Author Share Posted December 25, 2010 (edited) your_code Thanks it starts now gonna test it btw really fast response EDIT: After some minor changes, it works thanks alot!! Edited December 25, 2010 by Guest Link to comment
Castillo Posted December 25, 2010 Share Posted December 25, 2010 i'm bored and i won't go to sleep thats why fast reply Link to comment
Fabio(GNR) Posted December 25, 2010 Author Share Posted December 25, 2010 i'm bored and i won't go to sleep thats why fast reply haha its 1 pm at me in holland well its good you help people Link to comment
Aibo Posted December 25, 2010 Share Posted December 25, 2010 this way server will have only 1 car for all players. Link to comment
Castillo Posted December 25, 2010 Share Posted December 25, 2010 yeah, aiboforcen its right, lol. you should make some other check like element data. Link to comment
Fabio(GNR) Posted December 25, 2010 Author Share Posted December 25, 2010 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
Castillo Posted December 25, 2010 Share Posted December 25, 2010 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
Aibo Posted December 25, 2010 Share Posted December 25, 2010 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
Castillo Posted December 25, 2010 Share Posted December 25, 2010 what do you mean by "1 vehicle" ? my code should add a element data to that player only, his was working for everyone. Link to comment
Fabio(GNR) Posted December 25, 2010 Author Share Posted December 25, 2010 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
Aibo Posted December 25, 2010 Share Posted December 25, 2010 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
Fabio(GNR) Posted December 25, 2010 Author Share Posted December 25, 2010 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 Link to comment
Castillo Posted December 25, 2010 Share Posted December 25, 2010 my bad, i'm sleepy (i should go to sleep ) 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