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

refactor: massive rebuild for bpt_menu #598

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
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
1,573 changes: 546 additions & 1,027 deletions server-data/resources/[bpt_addons]/bpt_menu/client/main.lua

Large diffs are not rendered by default.

192 changes: 105 additions & 87 deletions server-data/resources/[bpt_addons]/bpt_menu/client/other.lua
Original file line number Diff line number Diff line change
@@ -1,118 +1,136 @@
local function startPointing(plyPed)
ESX.Streaming.RequestAnimDict('anim@mp_point', function()
SetPedConfigFlag(plyPed, 36, 1)
TaskMoveNetworkByName(plyPed, 'task_mp_pointing', 0.5, 0, 'anim@mp_point', 24)
RemoveAnimDict('anim@mp_point')
end)
local function startPointing(ped)
LoadAnimDict('anim@mp_point')
SetPedConfigFlag(ped, 36, true)
TaskMoveNetworkByName(ped, 'task_mp_pointing', 0.5, false, 'anim@mp_point', 24)
RemoveAnimDict('anim@mp_point')
end

local function stopPointing()
RequestTaskMoveNetworkStateTransition(plyPed, 'Stop')
local function stopPointing(ped)
RequestTaskMoveNetworkStateTransition(ped, 'Stop')
SetPedConfigFlag(ped, 36, false)
ClearPedSecondaryTask(ped)
end

function ResetOtherAnimsVals()
PlayerVars.pointing = false

if not IsPedInjured(plyPed) then
ClearPedSecondaryTask(plyPed)
if PlayerVars.handsUp then
PlayerVars.handsUp = false
end
end

SetPedConfigFlag(plyPed, 36, 0)
ClearPedSecondaryTask(plyPed)
if Config.Framework == 'esx' then
AddEventHandler('esx:onPlayerDeath', ResetOtherAnimsVals)
end

CreateThread(function()
while true do
Wait(0)
DisableControlAction(1, Config.Controls.Crouch.keyboard, true)
RegisterCommand('+handsup', function()
local playerPed = PlayerPedId()

if IsDisabledControlJustReleased(1, Config.Controls.Crouch.keyboard) and IsInputDisabled(2) then
local plyPed = PlayerPedId()
if not PlayerVars.isDead and IsPedOnFoot(playerPed) then
if PlayerVars.pointing then
PlayerVars.pointing = false
end

if (DoesEntityExist(plyPed)) and (not IsEntityDead(plyPed)) and (IsPedOnFoot(plyPed)) then
Player.crouched = not Player.crouched
PlayerVars.handsUp = not PlayerVars.handsUp

if Player.crouched then
ESX.Streaming.RequestAnimSet('move_ped_crouched', function()
SetPedMovementClipset(plyPed, 'move_ped_crouched', 0.25)
RemoveAnimSet('move_ped_crouched')
end)
else
ResetPedMovementClipset(plyPed, 0)
end
end
if PlayerVars.handsUp then
LoadAnimDict('random@mugging3')
TaskPlayAnim(playerPed, 'random@mugging3', 'handsup_standing_base', 8.0, -8.0, -1, 49, 0.0, false, false, false)
RemoveAnimDict('random@mugging3')
else
StopAnimTask(playerPed, 'random@mugging3', 'handsup_standing_base', -4.0)
end
end
end, false)

if IsControlJustReleased(1, Config.Controls.HandsUP.keyboard) and IsInputDisabled(2) then
local plyPed = PlayerPedId()
RegisterCommand('-handsup', function() end, false)

if (DoesEntityExist(plyPed)) and not (IsEntityDead(plyPed)) and (IsPedOnFoot(plyPed)) then
if Player.pointing then
Player.pointing = false
end
RegisterKeyMapping('+handsup', 'Lever les mains', 'KEYBOARD', Config.Controls.HandsUP.keyboard)
TriggerEvent('chat:removeSuggestion', '/+handsup')
TriggerEvent('chat:removeSuggestion', '/-handsup')

Player.handsUp = not Player.handsUp
RegisterCommand('+fingerpoint', function()
local playerPed = PlayerPedId()

if Player.handsUp then
ESX.Streaming.RequestAnimDict('random@mugging3', function()
TaskPlayAnim(plyPed, 'random@mugging3', 'handsup_standing_base', 8.0, -8, -1, 49, 0, 0, 0, 0)
RemoveAnimDict('random@mugging3')
end)
else
ClearPedSecondaryTask(plyPed)
end
end
if not PlayerVars.isDead and IsPedOnFoot(playerPed) then
if PlayerVars.handsUp then
PlayerVars.handsUp = false
end

if IsControlJustReleased(1, Config.Controls.Pointing.keyboard) and IsInputDisabled(2) then
local plyPed = PlayerPedId()

if (DoesEntityExist(plyPed)) and (not IsEntityDead(plyPed)) and (IsPedOnFoot(plyPed)) then
if Player.handsUp then
Player.handsUp = false
end
PlayerVars.pointing = not PlayerVars.pointing

Player.pointing = not Player.pointing
if PlayerVars.pointing then
startPointing(playerPed)
else
stopPointing(playerPed)
end
end
end, false)

RegisterCommand('-fingerpoint', function() end, false)

RegisterKeyMapping('+fingerpoint', 'Pointer du doigt', 'KEYBOARD', Config.Controls.Pointing.keyboard)
TriggerEvent('chat:removeSuggestion', '/+fingerpoint')
TriggerEvent('chat:removeSuggestion', '/-fingerpoint')

CreateThread(function()
while true do
Wait(0)
local playerPed = PlayerPedId()

if Player.pointing then
startPointing(plyPed)
DisableControlAction(0, Config.Controls.Crouch.keyboard, true)

if IsDisabledControlJustReleased(0, Config.Controls.Crouch.keyboard) and IsUsingKeyboard(2) then
if DoesEntityExist(playerPed) and not IsEntityDead(playerPed) and IsPedOnFoot(playerPed) then
PlayerVars.crouched = not PlayerVars.crouched

if PlayerVars.crouched then
LoadAnimSet('move_ped_crouched')
SetPedMovementClipset(playerPed, 'move_ped_crouched', 0.5)
RemoveAnimSet('move_ped_crouched')
else
stopPointing(plyPed)
ResetPedMovementClipset(playerPed, 0.5)
end
end
end

if Player.crouched or Player.handsUp or Player.pointing then
if not IsPedOnFoot(PlayerPedId()) then
ResetPedMovementClipset(plyPed, 0)
if PlayerVars.crouched or PlayerVars.handsUp or PlayerVars.pointing then
if not IsPedOnFoot(playerPed) then
ResetPedMovementClipset(playerPed, 0.5)
stopPointing()
Player.crouched, Player.handsUp, Player.pointing = false, false, false
elseif Player.pointing then
local ped = PlayerPedId()
local camPitch = GetGameplayCamRelativePitch()

if camPitch < -70.0 then
camPitch = -70.0
elseif camPitch > 42.0 then
camPitch = 42.0
end

camPitch = (camPitch + 70.0) / 112.0

local camHeading = GetGameplayCamRelativeHeading()
local cosCamHeading = Cos(camHeading)
local sinCamHeading = Sin(camHeading)
PlayerVars.crouched = false
PlayerVars.pointing = false

if camHeading < -180.0 then
camHeading = -180.0
elseif camHeading > 180.0 then
camHeading = 180.0
if PlayerVars.handsUp then
PlayerVars.handsUp = false
end
else
if PlayerVars.pointing then
local camPitch = GetGameplayCamRelativePitch()
camPitch = (camPitch < -70.0 and -70.0) or (camPitch > 42.0 and 42.0) or camPitch
camPitch = (camPitch + 70.0) / 112.0

local camHeading = GetGameplayCamRelativeHeading()
local cosCamHeading, sinCamHeading = math.cos(camHeading * (math.pi / 180.0)), math.sin(camHeading * (math.pi / 180.0))

camHeading = (camHeading < -180.0 and -180.0) or (camHeading > 180.0 and 180.0) or camHeading
camHeading = (camHeading + 180.0) / 360.0

local coords = GetOffsetFromEntityInWorldCoords(playerPed, vec3((cosCamHeading * -0.2) - (sinCamHeading * (0.4 * camHeading + 0.3)), (sinCamHeading * -0.2) + (cosCamHeading * (0.4 * camHeading + 0.3)), 0.6))
local shapeTestHandle = StartShapeTestCapsule(coords - vec3(0.0, 0.0, 0.2), coords + vec3(0.0, 0.0, 0.2), 0.4, 95, playerPed, 7)

local shapeTestStatus, hit, endCoords, surfaceNormal, entityHit = GetShapeTestResult(shapeTestHandle)
while shapeTestStatus == 1 do
Wait(0)
shapeTestStatus, hit, endCoords, surfaceNormal, entityHit = GetShapeTestResult(shapeTestHandle)
end

SetTaskMoveNetworkSignalFloat(playerPed, 'Pitch', camPitch)
SetTaskMoveNetworkSignalFloat(playerPed, 'Heading', (camHeading * -1.0) + 1.0)
SetTaskMoveNetworkSignalBool(playerPed, 'isBlocked', shapeTestStatus == 2 and hit == 1)
SetTaskMoveNetworkSignalBool(playerPed, 'isFirstPerson', GetCamViewModeForContext(GetCamActiveViewModeContext()) == 4)
end

camHeading = (camHeading + 180.0) / 360.0
local coords = GetOffsetFromEntityInWorldCoords(ped, (cosCamHeading * -0.2) - (sinCamHeading * (0.4 * camHeading + 0.3)), (sinCamHeading * -0.2) + (cosCamHeading * (0.4 * camHeading + 0.3)), 0.6)
local rayHandle, blocked = GetShapeTestResult(StartShapeTestCapsule(coords.x, coords.y, coords.z - 0.2, coords.x, coords.y, coords.z + 0.2, 0.4, 95, ped, 7))

SetTaskMoveNetworkSignalFloat(ped, 'Pitch', camPitch)
SetTaskMoveNetworkSignalFloat(ped, 'Heading', (camHeading * -1.0) + 1.0)
SetTaskMoveNetworkSignalBool(ped, 'isBlocked', blocked)
SetTaskMoveNetworkSignalBool(ped, 'isFirstPerson', N_0xee778f8c7e1142e2(N_0x19cafa3c87f7c2ff()) == 4)
end
end
end
Expand Down
147 changes: 147 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_menu/client/showName.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
local GTComponents = {
GAMER_NAME = 0,
CREW_TAG = 1,
healthArmour = 2,
BIG_TEXT = 3,
AUDIO_ICON = 4,
MP_USING_MENU = 5,
MP_PASSIVE_MODE = 6,
WANTED_STARS = 7,
MP_DRIVER = 8,
MP_CO_DRIVER = 9,
MP_TAGGED = 10,
GAMER_NAME_NEARBY = 11,
ARROW = 12,
MP_PACKAGES = 13,
INV_IF_PED_FOLLOWING = 14,
RANK_TEXT = 15,
MP_TYPING = 16,
MP_BAG_LARGE = 17,
MP_TAG_ARROW = 18,
MP_GANG_CEO = 19,
MP_GANG_BIKER = 20,
BIKER_ARROW = 21,
MC_ROLE_PRESIDENT = 22,
MC_ROLE_VICE_PRESIDENT = 23,
MC_ROLE_ROAD_CAPTAIN = 24,
MC_ROLE_SARGEANT = 25,
MC_ROLE_ENFORCER = 26,
MC_ROLE_PROSPECT = 27,
MP_TRANSMITTER = 28,
MP_BOMB = 29
}

activeTags = {}
activeTagsMutex = {}

CreateThread(function()
local playerId = PlayerId()
local GetPlayerPed = GetPlayerPed
local GetPlayerServerId = GetPlayerServerId
local GetPlayerName = GetPlayerName

local function sanitizeString(s)
if type(s) ~= "string" then return "" end
local res = s:gsub("[^\32-\126]", "")
:gsub('[<>]', '')
:gsub('~.*~', '')

if res:len() < s:len() then
local trimmedRes = res:gsub("%s", "")

if trimmedRes == "" then
return trimmedRes
end
end

return res
end

local activeTagsMutex = activeTagsMutex

while true do
if PlayerVars.showName then
local activeTagsByPlayerId = {}

for i = #activeTagsMutex, 1, -1 do
local tag = activeTagsMutex[i]

if tag then
if IsMpGamerTagActive(tag.handle) then
activeTagsByPlayerId[tag.playerId] = true
else
table.remove(activeTagsMutex, i)
end
end
end

do
local activePlayers = GetActivePlayers()

for i = 1, #activePlayers do
local targetPlayer = activePlayers[i]

if targetPlayer ~= playerId then
if not activeTagsByPlayerId[targetPlayer] then
local targetPed = GetPlayerPed(targetPlayer)

if targetPed > 0 then
local targetPlayerServerId = GetPlayerServerId(targetPlayer)
local sanitizedName = sanitizeString(GetPlayerName(targetPlayer))
local renderedText = ("[%d] %s"):format(targetPlayerServerId, sanitizedName == "" and "Inconnu" or sanitizedName)
local tagHandle = CreateFakeMpGamerTag(targetPed, renderedText, false, false, "", 0)

activeTagsMutex[#activeTagsMutex + 1] = {
handle = tagHandle,
playerId = targetPlayer
}
end
end
end
end
end

local _activeTags = {}

for i = 1, #activeTagsMutex do
local tagMutex = activeTagsMutex[i]
_activeTags[i] = tagMutex
end

activeTags = _activeTags
end

Wait(PlayerVars.showName and 100 or 200)
end
end)

CreateThread(function()
SetMpGamerTagsUseVehicleBehavior(false)
SetMpGamerTagsVisibleDistance(424.0)

local GetPlayerPed = GetPlayerPed
local MumbleIsPlayerTalking = MumbleIsPlayerTalking

while true do
if PlayerVars.showName then
for i = 1, #activeTags do
local tag = activeTags[i]
local targetPed = GetPlayerPed(tag.playerId)

if targetPed > 0 then
local tagHandle = tag.handle
SetMpGamerTagVisibility(tagHandle, GTComponents["GAMER_NAME"], true)
SetMpGamerTagVisibility(tagHandle, GTComponents["healthArmour"], true)
SetMpGamerTagVisibility(tagHandle, GTComponents["AUDIO_ICON"], MumbleIsPlayerTalking(tag.playerId))

SetMpGamerTagAlpha(tagHandle, GTComponents["healthArmour"], 255)

SetMpGamerTagAlpha(tagHandle, GTComponents["AUDIO_ICON"], 255)
SetMpGamerTagColour(tagHandle, GTComponents["AUDIO_ICON"], 118)
end
end
end

Wait(PlayerVars.showName and 0 or 200)
end
end)
Loading
Loading