Guest Posted August 9, 2008 Posted August 9, 2008 I'm trying to script that when a vehicle hits water it respawns but it ain't working. What it does is that when it checks if the vehicles are in the water it still respawns everything and I can't find the problem Here's the code: function onResourceStartHandler(source) setTimer(spawnVehicleInWater, 6000, 0) end function spawnVehicleInWater() vehicles = getElementsByType("vehicle") for vehicleKey, vehicleValue in ipairs(vehicles) do local x,y,z = getElementPosition(vehicleValue) local level = getWaterLevel(x, y, z) local id = getVehicleID(vehicleValue) if not id == 447 or id == 460 or id == 472 or id == 473 or id == 493 or id == 595 or id == 480 or id == 430 or id == 453 or id == 452 or id == 446 or id == 454 then if level then level = z - level if level <= 0 then triggerServerEvent("vehiclerespawn", getRootElement(), vehicleValue) end end end end end addEventHandler("onClientResourceStart",getRootElement(), onResourceStartHandler) Anyone able to help me ? Thanks in Advance
Remp Posted August 9, 2008 Posted August 9, 2008 this line will cause problems if not id == 447 or id == 460 or id == 472 or id == 473 or id == 493 or id == 595 or id == 480 or id == 430 or id == 453 or id == 452 or id == 446 or id == 454 then not exactly sure what you want to do, but if you want it to stop those ids respawning then youd use if id~=447 and id~= 460 and id~=472... alternatively if you want to only allow those ids to respawn use if id==447 or id==460 or id==472...
icedsun Posted August 9, 2008 Posted August 9, 2008 Ugh, I can't stand when people don't parse their conditions inside ( )'s... especially when it's a massively long list of conditions like you have! Please, for the love of Bob: if(conditions) then Then again, I have OCD.
haybail Posted August 10, 2008 Posted August 10, 2008 and theres an example you might like to use as well: policeVehicles = { [598]=true,[596]=true,[597]=true,[599]=true } policeSkins = { [280]=true,[281]=true,[282]=true,[283]=true,[284]=true,[285]=true,[286]=true } function enterVehicle ( player, seat, jacked ) --when a player enters a vehicle if ( policeVehicles[getVehicleID(source)] ) and ( not policeSkins[getPlayerSkin(player)] ) then --if the vehicle is one of 4 police cars, and the skin is not a police skin cancelEvent() outputChatBox ( "Only policeman can enter police cars!", player ) --and tell the player why end end addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle ) --add an event for onPlayerEnterVehicle meaning u can do it like this also: nocars = { [447] = true, [460] = true, [472] = true } if not nocars[id] then if level z etc... Ugh, I can't stand when people don't parse their conditions inside ( )'s... especially when it's a massively long list of conditions like you have! Please, for the love of Bob: if(conditions) thenThen again, I have OCD.
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