DazzaJay Posted May 29, 2008 Share Posted May 29, 2008 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
Remp Posted May 29, 2008 Share Posted May 29, 2008 the basic way would be to check the z coord against the water level, assuming there arnt any places in the map on land below water level alternatively you could use testLineAgainstWater Link to comment
DazzaJay Posted May 29, 2008 Author Share Posted May 29, 2008 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
DazzaJay Posted May 29, 2008 Author Share Posted May 29, 2008 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
50p Posted May 29, 2008 Share Posted May 29, 2008 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
DazzaJay Posted May 29, 2008 Author Share Posted May 29, 2008 Thanks 50P, i will try it out after this ep of DS9 and then report if it works or not. Link to comment
DazzaJay Posted May 29, 2008 Author Share Posted May 29, 2008 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 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
Remp Posted May 30, 2008 Share Posted May 30, 2008 getWaterLevel is a client side function Link to comment
DazzaJay Posted May 30, 2008 Author Share Posted May 30, 2008 well, what could i use for a Map over the ocean? im guessing that Water level is 0.0, so any way to make it so it dosent get water level, but instead respawns vehicles under the level of 0.0? Link to comment
Remp Posted May 30, 2008 Share Posted May 30, 2008 just change local waterZ = getWaterLevel( getElementPosition( veh ) ) if waterZ and waterZ > z then blowVehicle( veh ) end to if 0.0 > z then blowVehicle( veh ) end Link to comment
50p Posted May 30, 2008 Share Posted May 30, 2008 getWaterLevel is a client side function When I say not tested, I mean I do what I think should work and I don't check if function exists. Link to comment
DazzaJay Posted May 30, 2008 Author Share Posted May 30, 2008 Tried that also, Still nothing. Link to comment
DazzaJay Posted May 30, 2008 Author Share Posted May 30, 2008 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
Remp Posted May 30, 2008 Share Posted May 30, 2008 you wernt already using it server side...? whats that timer doing in the middle of nowhere, put it in onResourceStart and add chat outputs to see where the function fails Link to comment
DazzaJay Posted May 30, 2008 Author Share Posted May 30, 2008 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
Remp Posted May 30, 2008 Share Posted May 30, 2008 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
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