Jump to content

Check if Vehicle Under Water, And Blow


Recommended Posts

ive recently converted an old DD map i made (in MTA Race) to a Full blown Vehicle CTF Map.

ive had to put in another .lua script so vehicles can respawn in it....

function respawnExplodedVehicle() 
   setTimer(respawnVehicle, 6000, 1, source) 
end 
  
addEventHandler("onVehicleExplode", getRootElement(), respawnExplodedVehicle) 

Problem is, Its a map with 2 AirCraft Carriers.... and if the Planes land in the water without Exploding, they dont respawn....

was kind of a sad map when all the vehicles were at the bottom of the ocean and everyone had to swim between the Aircraft carriers....

So, can anyone show me what to add to get it to check if a vehicle is underwater, and respawn it? thanks.

-Dan

Link to comment

Well, its 4 air craft carriers on the ocean, and thats really it, no underwater unless your swimming.

As for checking weather a Z axis is under water level or whatever..... im guessing i should just rim code out of the race gamemode? like its water killer, and change it to Blow vehicle if unoccupied?

Link to comment

Ok, Dumb question.....

How the Hell do i make this a Server Side Peice of code?, and also, So it dosent check for the vehicle i am in, but Unoccupied ones instead?

setTimer(checkWater, 5000, 0) 
  
function checkWater() 
    local vID = getVehicleID ( g_Vehicle ) 
    if ( vID == 539 or vID == 460 or vID == 417 or vID == 447 or vID == 472 or vID == 473 or vID == 493 or vID == 595 or vID == 484 or vID == 430 or vID == 453 or vID == 452 or vID == 446 or vID == 454 ) then return; end 
    local x, y, z = getElementPosition(g_Me) 
    local waterZ = getWaterLevel(x, y, z) 
    if waterZ and z < waterZ - 1.5 then 
        --setElementHealth(g_Me, 0) 
        blowVehicle ( g_Vehicle, true ) 
    end 
end 

Link to comment
function checkWater() 
    for _, veh in pairs( getElementsByType( "vehicle" ) ) do 
        if not getVehicleOccupant( veh ) then 
            local vehID = getVehicleID( veh ) 
            if vehID == 539 or vehID == 460 ........ then 
                local waterZ = getWaterLevel( getElementPosition( veh ) ) 
                if waterZ and waterZ > z then 
                    blowVehicle( veh ) 
                end 
            end 
        end 
    end 
end 

NOTE: NOT TESTED!

Link to comment

I might have missed somthing when putting the code together....

ive checked /debugscript 3

and no errors loading the map, no errors when vehicles are in the water.... just no errors :-s

function respawnExplodedVehicle() 
   setTimer(respawnVehicle, 6000, 1, source) 
end 
  
addEventHandler("onVehicleExplode", getRootElement(), respawnExplodedVehicle) 
  
setTimer(checkWater, 5000, 0) 
  
--[[function checkWater() 
    local vID = getVehicleID ( g_Vehicle ) 
    if ( vID == 539 or vID == 460 or vID == 417 or vID == 447 or vID == 472 or vID == 473 or vID == 493 or vID == 595 or vID == 484 or vID == 430 or vID == 453 or vID == 452 or vID == 446 or vID == 454 ) then return; end 
    local x, y, z = getElementPosition(g_Me) 
    local waterZ = getWaterLevel(x, y, z) 
    if waterZ and z < waterZ - 1.5 then 
        --setElementHealth(g_Me, 0) 
        blowVehicle ( g_Vehicle, true ) 
    end 
end]]-- 
  
  
function checkWater() 
    for _, veh in pairs( getElementsByType( "vehicle" ) ) do 
        if not getVehicleOccupant( veh ) then 
            local vehID = getVehicleID( veh ) 
            if vehID == 539 or vehID == 460 or vehID == 417 or vehID == 447 or vehID == 472 or vehID == 473 or vehID == 493 or vehID == 595 or vehID == 484 or vehID == 430 or vehID == 453 or vehID == 452 or vehID == 446 or vehID == 454 then 
                local waterZ = getWaterLevel( getElementPosition( veh ) ) 
                if waterZ and waterZ > z then 
                    blowVehicle( veh ) 
                end 
            end 
        end 
    end 
end 

Link to comment

Well, seeing how this has all been pretty much fail from the beginning, im thinking the System were going about is Wrong.

So, what im now gonna ask about is, Any ideas on a good Vehicle Respawn system that can run Serverside....

It would have to respawn after the vehicle is Exploded (that bit allready works)

And also, If the vehicle ends up in the water, and seeing as the ideas that we have had so far havnt worked, What about a 30 second timer From exit of vehicle, till the vehicle is respawned., timer would have to be cancelled if somone else got into the vehicle tho.

??

Link to comment

All my scripting abilities are full of Guesswork and Ripping code from other scripts.

From what i understand from another script, the timer should start on recource load as it is, and run on a loop, well, thats what it does in all other scripts ive written in this manner.

As for adding Outputs.... If i knew how, i would. but frankly, Guesswork and Ripping code from other gamemodses / scripts is the only way i know how to script, it was the same for me on mIRC, (which i was a lot better at) but i still dont understand LUA enough to be able to do complex things like that, and Most of the Wiki pages show Examples that either make no sence, or have Nothing to do with what i am attempting.

Link to comment

add outputChatBox() messages inside the function to see where it is failing, for example

function checkWater() 
    outputChatBox("checkWater called") 
    for _, veh in pairs( getElementsByType( "vehicle" ) ) do 
        outputChatBox("loop all the vehicles") 
        if not getVehicleOccupant( veh ) then 
            outputChatBox("empty vehicle") 
            local vehID = getVehicleID( veh ) 
            ... 

then judging by which messages get output you can track down the error

id also suggest reading this http://development.mtasa.com/index.php?title=Debugging

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