KingMofo Posted December 10, 2009 Share Posted December 10, 2009 Hello, I am trying to find a function to use for automatically destroying the unoccupied vehicles left by the player. I'm not really sure of a way to go about doing this. Could someone give me some advice or maybe an example? I'd really appreciate it. Also, how would i add a space in a commandhandler? For example: addCommandHandler ("do now", blah, blah) So now i go to console and try "do now" but it doesn't work. I've tried doing _ as a space but that doesn't work either. If anyone can help me on this i'd be so happy! Link to comment
50p Posted December 10, 2009 Share Posted December 10, 2009 https://forum.multitheftauto.com/viewtop ... 91&t=25032 https://wiki.multitheftauto.com/wiki/Main_Page https://wiki.multitheftauto.com/wiki/Scr ... troduction I'm in a rush.. all I can say is READ wik and LEARN Lua. You come here from space asking for something that is too hard for you without much scripting knowledge. I assure you, spend a few days on reading and learning and you'll become much better scripter who can script a lot because Lua is very easy to learn especially if you have good resource (which you have). - https://wiki.multitheftauto.com/wiki/OnVehicleExit - to start timer to destroy vehicle - https://wiki.multitheftauto.com/wiki/OnVehicleEnter - to stop the timer if running already to prevent from destroying vehicle when player is inside - https://wiki.multitheftauto.com/wiki/SetTimer - to start timer - https://wiki.multitheftauto.com/wiki/DestroyElement - to "destroy" vehicle element (get rid of vehicle from the server) - https://wiki.multitheftauto.com/wiki/SetElementHealth - if you don't want to remove vehicle from server, use this to change vehicles health to 0 to explode it Link to comment
KingMofo Posted December 24, 2009 Author Share Posted December 24, 2009 https://forum.multitheftauto.com/viewtopic.php?f=91&t=25032https://wiki.multitheftauto.com/wiki/Main_Page https://wiki.multitheftauto.com/wiki/Scr ... troduction I'm in a rush.. all I can say is READ wik and LEARN Lua. You come here from space asking for something that is too hard for you without much scripting knowledge. I assure you, spend a few days on reading and learning and you'll become much better scripter who can script a lot because Lua is very easy to learn especially if you have good resource (which you have). - https://wiki.multitheftauto.com/wiki/OnVehicleExit - to start timer to destroy vehicle - https://wiki.multitheftauto.com/wiki/OnVehicleEnter - to stop the timer if running already to prevent from destroying vehicle when player is inside - https://wiki.multitheftauto.com/wiki/SetTimer - to start timer - https://wiki.multitheftauto.com/wiki/DestroyElement - to "destroy" vehicle element (get rid of vehicle from the server) - https://wiki.multitheftauto.com/wiki/SetElementHealth - if you don't want to remove vehicle from server, use this to change vehicles health to 0 to explode it Thank you 50p, this really did get me started. I already have a bit of knowledge with LUA. I managed to auto destroy vehicles when someone has left the vehicle for 30seconds via setTimer. I'm having a big problem though. If the player leaves the vehicle, then decides to re-enter the vehicle, it still destroys it. Also, if someone exits the vehicle as a passenger, it destroys the drivers vehicle. I have tried using getPedOccupiedVehicleSeat but that doesn't seem to work. Here is the code i'm using. Client: function onVehExit () local localPlayer = getLocalPlayer() local vehCheck = isPedInVehicle (localPlayer) local theVehicle = getPedOccupiedVehicle (vehCheck) if theVehicle == source then return else triggerServerEvent ("vehExit", source) end end addEventHandler ("onClientVehicleStartExit", getRootElement(), onVehExit) addEventHandler ("onClientVehicleStartEnter", getRootElement(), onVehExit) Server: function leftOverVehicles() local theSeat = getPedOccupiedVehicleSeat (source) if theSeat == 0 then setTimer (destroyElement, 30000, 1, source) else end end addEvent ("vehExit", true) addEventHandler ("vehExit", getRootElement(), leftOverVehicles) Maybe someone can point out if i'm doing something wrong? P.S - Sorry for replying so late, 50p. Link to comment
manuelhimmler Posted December 24, 2009 Share Posted December 24, 2009 Use this code in serverside script, I would never use script with deleting something clientside because it maybe gets unsynchron: function destroyVehicle(vehicle) local check=false for i,player in ipairs(getElementsByType("player")) do if getPlayerOccupiedVehicle(player)==vehicle then check=true end end if check==false then destroyElement(vehicle) end end function exitVehicle(vehicle) setTimer(destroyVehicle,30000,1,vehicle) end addEventHandler("onPlayerVehicleExit",getRootElement(),exitVehicle) Link to comment
robhol Posted December 24, 2009 Share Posted December 24, 2009 While you're learning MTA scripting, you might also find this: http://robhol.net/guide/basics helpful. Link to comment
KingMofo Posted December 24, 2009 Author Share Posted December 24, 2009 Thank you manuelhimmler, that worked flawlessly! You don't know how much time i've spent trying to get it right, so i am very grateful. Thank you for that link robhol, i have already visited that a few times and found it extremely helpful, thank you. 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