-- Configuración de armas disponibles (debe coincidir con el servidor)
local availableWeapons = {
{id = 22, name = "Pistola", model = 346},
{id = 25, name = "Escopeta", model = 349},
{id = 29, name = "MP5", model = 353},
{id = 31, name = "M4", model = 356}
}
local isSelectingWeapon = false
local currentWeaponIndex = 1
local cameraTarget, weaponObject
-- Mostrar la interfaz de selección de armas
function showWeaponSelection(marker)
if getElementData(localPlayer, "faction") ~= "police" then
outputChatBox("Solo los policías pueden acceder a la armería.", 255, 0, 0)
return
end
isSelectingWeapon = true
showCursor(true)
addEventHandler("onClientRender", root, drawWeaponSelection)
local x, y, z = getElementPosition(marker)
cameraTarget = createObject(1337, x, y, z + 0.5)
setElementAlpha(cameraTarget, 0)
setCameraMatrix(x - 5, y, z + 2, x, y, z)
updateWeaponDisplay()
end
-- Ocultar la interfaz de selección de armas
function hideWeaponSelection()
isSelectingWeapon = false
showCursor(false)
removeEventHandler("onClientRender", root, drawWeaponSelection)
setCameraTarget(localPlayer)
if isElement(cameraTarget) then destroyElement(cameraTarget) end
if isElement(weaponObject) then destroyElement(weaponObject) end
end
-- Actualizar la visualización del arma
function updateWeaponDisplay()
if isElement(weaponObject) then destroyElement(weaponObject) end
local weapon = availableWeapons[currentWeaponIndex]
local x, y, z = getElementPosition(cameraTarget)
weaponObject = createObject(weapon.model, x, y, z)
setElementCollisionsEnabled(weaponObject, false)
end
-- Dibujar la interfaz de selección de armas
function drawWeaponSelection()
local screenW, screenH = guiGetScreenSize()
local weapon = availableWeapons[currentWeaponIndex]
dxDrawRectangle(0, screenH - 100, screenW, 100, tocolor(0, 0, 0, 200))
dxDrawText(weapon.name, 0, screenH - 90, screenW, screenH, tocolor(255, 255,
255), 1.5, "default-bold", "center")
dxDrawText("Presiona ENTER para seleccionar, RETROCESO para salir", 0, screenH
- 40, screenW, screenH, tocolor(255, 255, 255), 1, "default", "center")
dxDrawText("Usa las flechas izquierda y derecha para cambiar de arma", 0,
screenH - 70, screenW, screenH, tocolor(255, 255, 255), 1, "default", "center")
end
-- Manejar las teclas presionadas
function handleKeys(key, press)
if not isSelectingWeapon then return end
if press then
if key == "arrow_l" then
currentWeaponIndex = currentWeaponIndex - 1
if currentWeaponIndex < 1 then currentWeaponIndex = #availableWeapons
end
updateWeaponDisplay()
elseif key == "arrow_r" then
currentWeaponIndex = currentWeaponIndex + 1
if currentWeaponIndex > #availableWeapons then currentWeaponIndex = 1
end
updateWeaponDisplay()
elseif key == "enter" then
triggerServerEvent("onRequestPoliceWeapon", localPlayer,
currentWeaponIndex)
hideWeaponSelection()
elseif key == "backspace" then
hideWeaponSelection()
end
end
end
-- Event handlers
addEventHandler("onClientMarkerHit", root,
function(hitElement, matchingDimension)
if hitElement == localPlayer and matchingDimension then
if getElementData(source, "type") == "policeArmory" then
showWeaponSelection(source)
end
end
end
)
addEventHandler("onClientKey", root, handleKeys)
-- Crear el objeto visual para el marcador
addEventHandler("onClientResourceStart", resourceRoot, function()
setTimer(function()
local markers = getElementsByType("marker")
for _, marker in ipairs(markers) do
if getElementData(marker, "type") == "policeArmory" then
local x, y, z = getElementPosition(marker)
local icon = createObject(2969, x, y, z + 0.5) -- 2969 es un
modelo de arma
setElementCollisionsEnabled(icon, false)
break
end
end
end, 1000, 1) -- Espera 1 segundo para asegurarse de que el marcador se haya
creado
end)