Skip to content

Commit 3dd0c4e

Browse files
committed
Make sure that element is not attached already + GLUE_ALLOW_DETACHING_VEHICLES_AS_A_DRIVER
1 parent a9abf10 commit 3dd0c4e

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

[gameplay]/glue/config/ShVehicleAttachConfig.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ GLUE_SHOW_ONE_TIME_HINT = true -- whether player should receive one-time (till r
5353

5454
GLUE_ALLOW_ATTACH_TOGGLING = true -- should players be able to control attach lock on their vehicle (as a driver)
5555
GLUE_ALLOW_DETACHING_ELEMENTS = true -- should players be able to detach already attached elements (as a driver)
56+
GLUE_ALLOW_DETACHING_VEHICLES_AS_A_DRIVER = true -- should vehicle driver be able to detach vehicle which is attached to his own (this is default behavior for helicopters)
5657

57-
GLUE_ATTACH_DETACH_KEY = "X" -- used to attach/detach yourself/vehicle
58-
GLUE_ATTACH_TOGGLE_KEY = "C" -- only relevant if GLUE_ALLOW_ATTACH_TOGGLING is set to true; specifies whether players can disable attaching to vehicle which are driver of
59-
GLUE_DETACH_ELEMENTS_KEY = "B" -- only relevant if GLUE_ALLOW_DETACHING_ELEMENTS is set to true; controls whether vehicle driver is able to detach elements currently attached to vehicle
58+
GLUE_ATTACH_DETACH_KEY = "X" -- used to attach/detach yourself/vehicle/nearby vehicle (for helicopters)
59+
GLUE_ATTACH_TOGGLE_KEY = "C" -- only relevant if GLUE_ALLOW_ATTACH_TOGGLING is set to true; key used for toggling attach lock
60+
GLUE_DETACH_ELEMENTS_KEY = "B" -- only relevant if GLUE_ALLOW_DETACHING_ELEMENTS is set to true; key used for detaching all elements attached to vehicle
6061

6162
GLUE_ATTACH_DETACH_DELAY = 300 -- how often player can attach/detach yourself/vehicle
6263
GLUE_ATTACH_TOGGLE_DELAY = 300 -- only relevant if GLUE_ALLOW_ATTACH_TOGGLING is set to true; how often player can toggle vehicle attach lock

[gameplay]/glue/logic/CVehicleAttach.lua

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ local function handleGlueAttachAndDetach()
1313
local playerVehicleToDetach = playerVehicle
1414
local playerVehicleType = getVehicleType(playerVehicle)
1515
local playerVehicleHelicopter = (playerVehicleType == "Helicopter")
16+
local playerHelicopterAttachedVehicle = getAttachedVehicle(playerVehicle)
1617

17-
if (playerVehicleHelicopter) then
18-
local playerHelicopterAttachedVehicle = getAttachedVehicle(playerVehicle)
19-
20-
if (playerHelicopterAttachedVehicle) then
21-
playerVehicleToDetach = playerHelicopterAttachedVehicle
22-
end
18+
if (playerHelicopterAttachedVehicle) then
19+
playerVehicleToDetach = playerHelicopterAttachedVehicle
2320
end
2421

2522
if (playerVehicleToDetach) then

[gameplay]/glue/logic/ShVehicleAttach.lua

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ function canPlayerAttachElementToVehicle(playerElement, attachElement, attachToE
2323
return false
2424
end
2525

26+
local attachElementAlreadyAttached = isElementAttached(attachElement)
27+
28+
if (attachElementAlreadyAttached) then
29+
return false
30+
end
31+
2632
local attachToElementVehicleType = isElementType(attachToElement, "vehicle")
2733

2834
if (not attachToElementVehicleType) then
@@ -207,15 +213,17 @@ function canPlayerDetachElementFromVehicle(playerElement, detachElement)
207213
return false
208214
end
209215

210-
local vehicleAttachToType = getVehicleType(attachToElement)
211-
local vehicleAttachToHelicopter = (vehicleAttachToType == "Helicopter")
216+
if (not GLUE_ALLOW_DETACHING_VEHICLES_AS_A_DRIVER) then
217+
local vehicleAttachToType = getVehicleType(attachToElement)
218+
local vehicleAttachToHelicopter = (vehicleAttachToType == "Helicopter")
212219

213-
if (not vehicleAttachToHelicopter) then
214-
local vehicleController = getVehicleController(detachElement)
215-
local vehicleDetachToDriver = (playerElement == vehicleController)
220+
if (not vehicleAttachToHelicopter) then
221+
local vehicleController = getVehicleController(detachElement)
222+
local vehicleDetachToDriver = (playerElement == vehicleController)
216223

217-
if (not vehicleDetachToDriver) then
218-
return false
224+
if (not vehicleDetachToDriver) then
225+
return false
226+
end
219227
end
220228
end
221229
end

0 commit comments

Comments
 (0)