Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- GTA V Lua Script
- --
- -- === MAIN ===
- --
- -- Advanced Exit Vehicle
- -- Author: Baaa
- -- ver. 1.1 (05.20.2015)
- --
- -- === DESCRIPTION ===
- --
- -- This script allows you to leave the vehicle...
- -- 1. ...through a passenger door.
- -- 2. ...with engine on and the door opened and the radio working
- -- 3. ...usual way (full exit), i.e. close the door and engine off.
- -- 4. ...with alarm set (turns off when the player is getting in the car)
- -- 5. ...with doors locked (for all except player). Security is important. Don't give your car to those pedestrian theves! :D
- -- 6. ...with anchor set if the vehicle is a boat. So your boat will never float away. (note: seems not works properly for now)
- --
- -- What the purpose of this script?
- -- To make just simple exit vehicle with few features not realized in SP GTA V and without any 'useless' stuff.
- -- Not all of the ppl want to use big plugins with tons of features. So this is simple as shit.
- --
- -- What the difference from similar plugins?
- -- Better method of getting and blocking the 'exit vehicle' event. Optimized code. Better perfomance. Some other features.
- --
- -- Supports gamepad.
- --
- -- === CONTROLS ===
- --
- -- 'exit vehicle' key -- Exit vehicle with engine on and the driver door opened.
- --
- -- Left Shift + 'exit vehicle' -- Exit vehicle through a passenger door with engine on and the door opened.
- -- LB + 'exit vehicle' -- Exit vehicle through a passenger door with engine on and the door opened.
- -- RB + 'exit vehicle' -- Shuffle to a passenger seat
- --
- -- Long press makes "full exit", i.e. turns off engine and closes the door (in both cases)
- --
- -- All keys customizable. See below.
- --
- -- === VARIABLES ===
- -- You can configure this.
- --
- -- Additional key to:
- -- exit
- local kb_key = 16 -- Keyboard key to exit vehicle through a passenger door. Def. 16 (Shiftkey).
- local gpad_key = 69 -- Gamepad key to exit vehicle through a passenger door. Def. 69 (RB).
- -- shuffle to next seat:
- local shuf_kb_key = 17 -- Keyboard key to move to next seat. Def. 17 (ControlKey).
- local shuf_gpad_key = 68 -- Gamepad key to move to next seat. Def. 68 (LB).
- --
- -- Vars
- local alarm = true -- Set alarm on the car after "full exit" or not. Def. true
- local lockdoors = 4 -- Lock the vehicle doors after "full exit" or not. See the flags below. Def. 4
- -- the flags you can change:
- -- 1 - stay unlocked
- -- 2 - full lock
- -- 4 - lock but can break (steal the car)
- local totallock = false -- Locks the doors even for player. Def. false
- -- If you wanna check is the vehicle locks or not after "full exit" set it to true.
- -- So the vehicle will be locked even for you. And you'll be not able to open the doors (if lockdoors set to 2).
- local anchor = true -- Put the boat on the anchor after "full exit" or not. Def. true
- -- Seems not works properly.
- -- The text for each event
- local alarm_text = "Alarm is set" -- Def. "Alarm is set"
- local lockdoors_text = "Doors are locked" -- Def. "Doors are locked"
- local anchor_text = "Anchor is dropped" -- Def. "Anchor is dropped"
- local unalarm_text = "Alarm is off" -- Def. "Alarm is off"
- local unlockdoors_text = "Doors are open" -- Def. "Doors are open"
- local unanchor_text = "Anchor is rised" -- Def. "Anchor is rised"
- -- === INSTALLATION ===
- --
- -- You'll need this:
- -- 1. Script Hook V. http://www.dev-c.com/gtav/scripthookv
- -- 2. LUA Plugin for Script Hook V. http://gtaforums.com/topic/789139-vrelhook-lua-plugin-for-script-hook-v
- --
- -- Put the script here: %GAME_DIRECTORY%\scripts\addins\
- --
- -- === CHANGELOG ===
- --
- -- 1.1 - Some optimizations.
- -- - Added features: setting alarm, locking the doors, putting the boat on anchor, shuffle to the next seat.
- --
- -- 1.0 - Initial release.
- --
- -- === NOTES ===
- --
- -- You are FREE to copy, translate (rewrite in another language),
- -- or distribute this code in any way, shape, or form!
- ------------------------------------------------------------------
- -- TODO:
- -- * Make wheels to stay turned
- --
- --
- -------------------------------------------------------------------
- -- DO NOT EDIT BELOW IF YOU REALLY DON'T KNOW WHAT ARE YOU DOING --
- -------------------------------------------------------------------
- local aev = {}
- local ver = '1.1'
- local thedate = '05.20.2015'
- local pid = 0
- local pvid = 0
- local timer = 0
- local maxtimer = 10 -- How long (ticks) to hold 'exit vehicle' button
- local msgtimer = 100
- local maxmsgtimer = 100
- local event_exit = false
- local key_pressed = false
- local add_key = false
- local vehicles = {}
- local showmsg_anchor = 0
- local showmsg_alarm = 0
- local showmsg_lock = 0
- local function getpvid(vid, array)
- for i, data in ipairs(array) do
- if(vid == data) then
- return i
- end
- end
- return -1
- end
- local function removenonexistv(array)
- for i, data in ipairs(array) do
- if(ENTITY.GET_ENTITY_MODEL(data) <= 0) then
- table.remove(array, i)
- end
- end
- end
- local function iscar(vid)
- if (VEHICLE.IS_THIS_MODEL_A_CAR(ENTITY.GET_ENTITY_MODEL(vid))) then
- return true
- end
- return false
- end
- local function isboat(vid)
- if (VEHICLE.IS_THIS_MODEL_A_BOAT(ENTITY.GET_ENTITY_MODEL(vid))) then
- return true
- end
- return false
- end
- function aev.drawmsg(msg, x, y, r, g, b)
- UI.SET_TEXT_FONT(7)
- UI.SET_TEXT_SCALE(0.5, 0.6)
- UI.SET_TEXT_COLOUR(r, g, b, 255)
- UI.SET_TEXT_WRAP(0.0, 1.0)
- UI.SET_TEXT_CENTRE(true)
- UI.SET_TEXT_DROPSHADOW(2, 2, 0, 0, 0)
- UI.SET_TEXT_EDGE(1, 0, 0, 0, 205)
- UI._SET_TEXT_ENTRY("STRING")
- UI._ADD_TEXT_COMPONENT_STRING(msg)
- UI._DRAW_TEXT(y, x)
- end
- function aev.tick()
- -------------------------------------------------
- -- DRAW TEXT
- -------------------------------------------------
- if (msgtimer < maxmsgtimer) then
- msgtimer = msgtimer + 1
- if ((msgtimer >= maxmsgtimer)) then
- msgtimer = maxmsgtimer
- end
- if (showmsg_anchor == 1) then
- aev.drawmsg(anchor_text, 0.9, 0.5, 255, 55, 55)
- return 0
- elseif (showmsg_anchor == 2) then
- aev.drawmsg(unanchor_text, 0.9, 0.5, 55, 255, 55)
- return 0
- end
- if (showmsg_alarm == 1) then
- aev.drawmsg(alarm_text, 0.9, 0.5, 255, 55, 55)
- elseif (showmsg_alarm == 2) then
- aev.drawmsg(unalarm_text, 0.9, 0.5, 55, 255, 55)
- end
- if (showmsg_lock == 1) then
- aev.drawmsg(lockdoors_text, 0.945, 0.5, 255, 55, 55)
- elseif (showmsg_lock == 2) then
- aev.drawmsg(unlockdoors_text, 0.945, 0.5, 55, 255, 55)
- end
- end
- -------------------------------------------------
- -- DRAW TEXT
- -------------------------------------------------
- -- Check the key pressed.
- -- Here I should use IS_CONTROL_JUST_PRESSED but it seems IS_CONTROL_PRESSED hooks the key much faster.
- -- And I noticed there is a chance that IS_CONTROL_JUST_PRESSED could not trigger.
- -- Also we need to check IS_DISABLED_CONTROL_PRESSED once.
- if (CONTROLS.IS_CONTROL_PRESSED(2, 75) or CONTROLS.IS_DISABLED_CONTROL_PRESSED(2, 75)) then
- if (event_exit) then
- -------------------------------------------------------
- -- Start timer and check every tick is the key released
- timer = timer + 1
- --print(timer)
- if (timer < maxtimer) then
- return 0
- end
- -------------------------------------------------------
- -- Key is still pressed
- key_pressed = true
- aev.exitv(true, add_key)
- return 0
- end
- -- Prevent extra exit event
- if (key_pressed) then
- return 0
- end
- -- We need just one key press
- key_pressed = true
- pid = PLAYER.PLAYER_PED_ID()
- -- CURRENT VEHICLE
- pvid = PED.GET_VEHICLE_PED_IS_IN(pid, false)
- -- Is player in the vehicle already
- if (pvid <= 0) then
- -- 1 TIME TASK --
- -----------------------------------------
- pvid = PED.GET_VEHICLE_PED_IS_USING(pid)
- -- Is player interact with a vehicle now
- if (pvid <= 0) then
- return 0
- end
- -----------------------------------------
- -- Clear DB from nonexistent vehicles
- removenonexistv(vehicles)
- -----------------------------------------------------
- -- Is it a vehicle we did "full exit" once. "Clear" that vehicle.
- if (#vehicles > 0) then
- local vid = getpvid(pvid, vehicles)
- if (vid > 0) then
- -- Is the vehicle a boat
- if (isboat(pvid)) then
- if (anchor) then
- VEHICLE.SET_BOAT_ANCHOR(pvid, false)
- showmsg_anchor = 2
- msgtimer = 0
- end
- table.remove(vehicles, vid)
- return 0
- end
- showmsg_anchor = 0
- -- Remove vehicle from db
- table.remove(vehicles, vid)
- if (totallock) then
- return 0
- end
- if (alarm) then
- VEHICLE.SET_VEHICLE_ALARM(pvid, false)
- showmsg_alarm = 2
- msgtimer = 0
- end
- if (lockdoors > 1) then
- VEHICLE.SET_VEHICLE_DOORS_LOCKED(pvid, 1)
- showmsg_lock = 2
- msgtimer = 0
- end
- --VEHICLE.STEER_UNLOCK_BIAS(pvid, true) -- unlock steer if i'll find the way to lock it
- end
- end
- -----------------------------------------------------
- return 0
- end
- -- We need to check additional key as fast as possible.
- -----------------------------------------------------
- if (get_key_pressed(shuf_kb_key) or CONTROLS.IS_CONTROL_PRESSED(2, shuf_gpad_key)) then
- CONTROLS.DISABLE_CONTROL_ACTION(2, 75, 0)
- AI.TASK_SHUFFLE_TO_NEXT_VEHICLE_SEAT(pid, pvid)
- return 0
- end
- if (get_key_pressed(kb_key) or CONTROLS.IS_CONTROL_PRESSED(2, gpad_key)) then
- add_key = true
- end
- -----------------------------------------------------
- -- Is player a driver
- if (VEHICLE.GET_PED_IN_VEHICLE_SEAT(pvid, -1) ~= pid) then
- add_key = false
- return 0
- end
- -- Blocking 'exit vehicle' action
- -- Note: it blocks action just once.
- CONTROLS.DISABLE_CONTROL_ACTION(2, 75, 0)
- -- Reset the timer just in case
- timer = 0
- -- Start exit event
- event_exit = true
- return 0
- end
- if (key_pressed) then
- key_pressed = not key_pressed
- return 0
- end
- -------------------------
- -- THE KEY IS RELEASED --
- -------------------------
- if (not event_exit) then
- return 0
- end
- aev.exitv(false, add_key)
- pvid = PED.GET_VEHICLE_PED_IS_IN(pid, true)
- if (lockdoors > 1) then
- VEHICLE.SET_VEHICLE_DOORS_LOCKED(pvid, 1)
- removenonexistv(vehicles)
- if (#vehicles > 0) then
- local vid = getpvid(pvid, vehicles)
- if (vid > 0) then
- table.remove(vehicles, vid)
- end
- end
- return 0
- end
- if (anchor or alarm) then
- removenonexistv(vehicles)
- if (#vehicles > 0) then
- pvid = PED.GET_VEHICLE_PED_IS_IN(pid, true)
- local vid = getpvid(pvid, vehicles)
- if (vid > 0) then
- table.remove(vehicles, vid)
- end
- end
- end
- end
- function aev.exitv(pressed, addkey)
- event_exit = false
- timer = 0
- -- Is additional key pressed
- if (addkey) then
- add_key = false
- if (pressed) then
- AI.TASK_LEAVE_VEHICLE(pid, pvid, 262144)
- --------------------------------------------
- -- ADD LAST CAR TO A DB
- -- Last used vehicle
- pvid = PED.GET_VEHICLE_PED_IS_IN(pid, true)
- local isaboat = isboat(pvid)
- if (not iscar(pvid)) then
- if (not isaboat) then
- return 0
- end
- end
- if (anchor or alarm or (lockdoors > 1)) then
- removenonexistv(vehicles)
- if (getpvid(pvid, vehicles) <= 0) then
- table.insert(vehicles, pvid)
- end
- end
- -------------------------------------------
- if (isaboat) then
- if (anchor) then
- VEHICLE.SET_BOAT_ANCHOR(pvid, true)
- showmsg_anchor = 1
- msgtimer = 0
- end
- return 0
- end
- showmsg_anchor = 0
- if (alarm) then
- VEHICLE.SET_VEHICLE_ALARM(pvid, true)
- showmsg_alarm = 1
- msgtimer = 0
- end
- if (lockdoors > 1) then
- VEHICLE.SET_VEHICLE_DOORS_LOCKED(pvid, lockdoors)
- showmsg_lock = 1
- msgtimer = 0
- end
- return 0
- end
- AI.TASK_LEAVE_VEHICLE(pid, pvid, 262400)
- -- Make engine on
- while (pvid ~= 0) do
- VEHICLE.SET_VEHICLE_ENGINE_ON(pvid, true, true)
- wait(0)
- pvid = PED.GET_VEHICLE_PED_IS_IN(pid, false)
- end
- return 0
- end
- if (pressed) then
- AI.TASK_LEAVE_VEHICLE(pid, pvid, 0)
- --------------------------------------------
- -- ADD LAST CAR TO A DB
- pvid = PED.GET_VEHICLE_PED_IS_IN(pid, true)
- local isaboat = isboat(pvid)
- if (not iscar(pvid)) then
- if (not isaboat) then
- return 0
- end
- end
- if (anchor or alarm or (lockdoors > 1)) then
- -- Clear DB from non exist vehicle
- removenonexistv(vehicles)
- if (getpvid(pvid, vehicles) <= 0) then
- table.insert(vehicles, pvid)
- end
- end
- -------------------------------------------
- if (isaboat) then
- if (anchor) then
- VEHICLE.SET_BOAT_ANCHOR(pvid, true)
- showmsg_anchor = 1
- msgtimer = 0
- end
- return 0
- end
- showmsg_anchor = 0
- if (alarm) then
- VEHICLE.SET_VEHICLE_ALARM(pvid, true)
- showmsg_alarm = 1
- msgtimer = 0
- end
- if (lockdoors > 1) then
- VEHICLE.SET_VEHICLE_DOORS_LOCKED(pvid, lockdoors)
- showmsg_lock = 1
- msgtimer = 0
- end
- return 0
- end
- AI.TASK_LEAVE_VEHICLE(pid, pvid, 256)
- while (pvid ~= 0) do
- VEHICLE.SET_VEHICLE_ENGINE_ON(pvid, true, true)
- wait(0)
- pvid = PED.GET_VEHICLE_PED_IS_IN(pid, false)
- end
- end
- function aev.init()
- print('*********************')
- print('Advanced Exit Vehicle')
- print('ver. '.. ver ..' ('.. thedate ..')')
- print('by Baaa (c)')
- print('*********************')
- end
- function aev.unload()
- end
- return aev
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement