Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update recoil.lua (removing loop usage, add weapon shake) #445

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 86 additions & 117 deletions client/recoil.lua
Original file line number Diff line number Diff line change
@@ -1,120 +1,89 @@
local recoils = {
-- Handguns
[`weapon_pistol`] = 0.3,
[`weapon_pistol_mk2`] = 0.5,
[`weapon_combatpistol`] = 0.2,
[`weapon_appistol`] = 0.3,
[`weapon_stungun`] = 0.1,
[`weapon_pistol50`] = 0.6,
[`weapon_snspistol`] = 0.2,
[`weapon_heavypistol`] = 0.5,
[`weapon_vintagepistol`] = 0.4,
[`weapon_flaregun`] = 0.9,
[`weapon_marksmanpistol`] = 0.9,
[`weapon_revolver`] = 0.6,
[`weapon_revolver_mk2`] = 0.6,
[`weapon_doubleaction`] = 0.3,
[`weapon_snspistol_mk2`] = 0.3,
[`weapon_raypistol`] = 0.3,
[`weapon_ceramicpistol`] = 0.3,
[`weapon_navyrevolver`] = 0.3,
[`weapon_gadgetpistol`] = 0.3,
[`weapon_pistolxm3`] = 0.4,

-- Submachine Guns
[`weapon_microsmg`] = 0.5,
[`weapon_smg`] = 0.4,
[`weapon_smg_mk2`] = 0.1,
[`weapon_assaultsmg`] = 0.1,
[`weapon_combatpdw`] = 0.2,
[`weapon_machinepistol`] = 0.3,
[`weapon_minismg`] = 0.1,
[`weapon_raycarbine`] = 0.3,
[`weapon_tecpistol`] = 0.3,

-- Shotguns
[`weapon_pumpshotgun`] = 0.4,
[`weapon_sawnoffshotgun`] = 0.7,
[`weapon_assaultshotgun`] = 0.4,
[`weapon_bullpupshotgun`] = 0.2,
[`weapon_musket`] = 0.7,
[`weapon_heavyshotgun`] = 0.2,
[`weapon_dbshotgun`] = 0.7,
[`weapon_autoshotgun`] = 0.2,
[`weapon_pumpshotgun_mk2`] = 0.4,
[`weapon_combatshotgun`] = 0.0,

-- Assault Rifles
[`weapon_assaultrifle`] = 0.5,
[`weapon_assaultrifle_mk2`] = 0.2,
[`weapon_carbinerifle`] = 0.3,
[`weapon_carbinerifle_mk2`] = 0.1,
[`weapon_advancedrifle`] = 0.1,
[`weapon_specialcarbine`] = 0.2,
[`weapon_bullpuprifle`] = 0.2,
[`weapon_compactrifle`] = 0.3,
[`weapon_specialcarbine_mk2`] = 0.2,
[`weapon_bullpuprifle_mk2`] = 0.2,
[`weapon_militaryrifle`] = 0.0,
[`weapon_heavyrifle`] = 0.3,
[`weapon_tacticalrifle`] = 0.2,

-- Light Machine Guns
[`weapon_mg`] = 0.1,
[`weapon_combatmg`] = 0.1,
[`weapon_gusenberg`] = 0.1,
[`weapon_combatmg_mk2`] = 0.1,

-- Sniper Rifles
[`weapon_sniperrifle`] = 0.5,
[`weapon_heavysniper`] = 0.7,
[`weapon_marksmanrifle`] = 0.3,
[`weapon_remotesniper`] = 1.2,
[`weapon_heavysniper_mk2`] = 0.6,
[`weapon_marksmanrifle_mk2`] = 0.3,
[`weapon_precisionrifle`] = 0.3,

-- Heavy Weapons
[`weapon_rpg`] = 0.0,
[`weapon_grenadelauncher`] = 1.0,
[`weapon_grenadelauncher_smoke`] = 1.0,
[`weapon_minigun`] = 0.1,
[`weapon_firework`] = 0.3,
[`weapon_railgun`] = 2.4,
[`weapon_hominglauncher`] = 0.0,
[`weapon_compactlauncher`] = 0.5,
[`weapon_rayminigun`] = 0.3,
local weapons = {
['WEAPON_FLAREGUN'] = {recoil = 0.9, shake = 0.04},
['WEAPON_PISTOL'] = {recoil = 0.3, shake = 0.06},
['WEAPON_PISTOL_MK2'] = {recoil = 0.3, shake = 0.03},
['WEAPON_COMBATPISTOL'] = {recoil = 0.3, shake = 0.03},
['WEAPON_APPISTOL'] = {recoil = 0.38, shake = 0.35},
['WEAPON_PISTOL50'] = {recoil = 0.57, shake = 0.05},
['WEAPON_VINTAGEPISTOL'] = {recoil = 0.4, shake = 0.025},
['WEAPON_HEAVYPISTOL'] = {recoil = 0.4, shake = 0.04},
['WEAPON_STUNGUN'] = {recoil = 0.1, shake = 0.01},
['WEAPON_SNSPISTOL'] = {recoil = 0.2, shake = 0.02},
['WEAPON_SNSPISTOL_MK2'] = {recoil = 0.25, shake = 0.035},
['WEAPON_MARKSMANPISTOL'] = {recoil = 0.9, shake = 0.04},
['WEAPON_MACHINEPISTOL'] = {recoil = 0.3, shake = 0.04},
['WEAPON_REVOLVER'] = {recoil = 0.6, shake = 0.05},
['WEAPON_REVOLVER_MK2'] = {recoil = 0.65, shake = 0.055},
['WEAPON_MINISMG'] = {recoil = 0.2, shake = 0.03},
['WEAPON_MICROSMG'] = {recoil = 0.2, shake = 0.05},
['WEAPON_SMG'] = {recoil = 0.1, shake = 0.065},
['WEAPON_SMG_MK2'] = {recoil = 0.1, shake = 0.075},
['WEAPON_ASSAULTSMG'] = {recoil = 0.1, shake = 0.050},
['WEAPON_ASSAULTRIFLE'] = {recoil = 0.2, shake = 0.07},
['WEAPON_ASSAULTRIFLE_MK2'] = {recoil = 0.2, shake = 0.072},
['WEAPON_CARBINERIFLE'] = {recoil = 0.2, shake = 0.06},
['WEAPON_CARBINERIFLE_MK2'] = {recoil = 0.1, shake = 0.065},
['WEAPON_ADVANCED_RIFLE'] = {recoil = 0.1, shake = 0.06},
['WEAPON_COMPACTRIFLE'] = {recoil = 0.3, shake = 0.03},
['WEAPON_COMBATMG'] = {recoil = 0.1, shake = 0.08},
['WEAPON_COMBATMG_MK2'] = {recoil = 0.1, shake = 0.085},
['WEAPON_COMBATPDW'] = {recoil = 0.2, shake = 0.05},
['WEAPON_BULLPUPRIFLE'] = {recoil = 0.2, shake = 0.05},
['WEAPON_BULLPUPRIFLE_MK2'] = {recoil = 0.25, shake = 0.045},
['WEAPON_PUMPSHOTGUN'] = {recoil = 0.4, shake = 0.07},
['WEAPON_PUMPSHOTGUN_MK2'] = {recoil = 0.4, shake = 0.095},
['WEAPON_SAWNOFFSHOTGUN'] = {recoil = 0.7, shake = 0.06},
['WEAPON_ASSAULTSHOTGUN'] = {recoil = 0.4, shake = 0.12},
['WEAPON_BULLPUPSHOTGUN'] = {recoil = 0.2, shake = 0.08},
['WEAPON_SPECIALCARBINE'] = {recoil = 0.2, shake = 0.06},
['WEAPON_SPECIALCARBINE_MK2'] = {recoil = 0.25, shake = 0.085},
['WEAPON_DOUBLEACTION'] = {recoil = 0.4, shake = 0.025},
['WEAPON_HEAVYSHOTGUN'] = {recoil = 0.2, shake = 0.13},
['WEAPON_DBSHOTGUN'] = {recoil = 0.7, shake = 0.04},
['WEAPON_AUTOSHOTGUN'] = {recoil = 0.2, shake = 0.04},
}

CreateThread(function()
while true do
local ped = PlayerPedId()
if IsPedShooting(ped) and not IsPedDoingDriveby(ped) then
local _, weap = GetCurrentPedWeapon(ped)
if recoils[weap] and recoils[weap] ~= 0 then
local tv = 0
if GetFollowPedCamViewMode() ~= 4 then
repeat
Wait(0)
local p = GetGameplayCamRelativePitch()
SetGameplayCamRelativePitch(p + 0.1, 0.2)
tv += 0.1
until tv >= recoils[weap]
else
repeat
Wait(0)
local p = GetGameplayCamRelativePitch()
if recoils[weap] > 0.1 then
SetGameplayCamRelativePitch(p + 0.6, 1.2)
tv += 0.6
else
SetGameplayCamRelativePitch(p + 0.016, 0.333)
tv += 0.1
end
until tv >= recoils[weap]
end
for k,v in pairs(weapons) do
weapons[GetHashKey(k)] = v
end

AddEventHandler('CEventGunShot', function (entity, ped, coords)
if PlayerPedId() ~= ped then return end
local ped = PlayerPedId()
if not weapons[GetSelectedPedWeapon(ped)] then return end
local tv = 0
local p
local cfg = weapons[GetSelectedPedWeapon(ped)]
if cfg.recoil then
if GetFollowPedCamViewMode() ~= 4 then
if cfg.shake then
ShakeGameplayCam('SMALL_EXPLOSION_SHAKE', cfg.shake)
end
repeat
if IsPedInAnyVehicle(ped) then return end
Wait(0)
SetWeaponAnimationOverride(ped, GetHashKey('Default'))
p = GetGameplayCamRelativePitch()
SetGameplayCamRelativePitch(p + 0.1, 0.5)
tv = tv + 0.1
until tv >= cfg.recoil
else
if cfg.shake then
ShakeGameplayCam('SMALL_EXPLOSION_SHAKE', cfg.shake)
end
end
Wait(0)
end
end)
repeat
if IsPedInAnyVehicle(ped) then return end
Wait(0)
SetWeaponAnimationOverride(ped, GetHashKey('FirstPersonAiming'))
p = GetGameplayCamRelativePitch()
if cfg.recoil > 0.1 then
SetGameplayCamRelativePitch(p + 0.6, 1.2)
tv = tv + 0.6
else
SetGameplayCamRelativePitch(p + 0.016, 0.333)
tv = tv + 0.1
end
until tv >= cfg.recoil
end
end
end)
Loading