[STANDALONE] Pepper Spray

A script by Eviate

No reviews yet.
[STANDALONE] Pepper Spray main image

Full Description

Pepper Spray Script and Addon Weapon

Are you looking to introduce pepper spray to the arsenal of your police department, or add a new unique weapon to your server? Look no further! This script includes a new addon-weapon, which can be used just like any other existing weapon. The script detects whenever you hit another player with the pepper spray, and applies a configurable effect to the player which temporarily paralyses the target.

:movie_camera: Detailed Preview: Youtube

:shopping_cart: Get it here: gamzkystore.com

:question: Support: Discord

Features

  • This is a standalone script and it does not require any other scripts in order to run. A job-check for esx and qbcore/qbox is included, which checks if a player is police before applying the pepper spray effect.
  • An unencrypted addon-weapon by the name of weapon_pepperspray is included in the files.
  • The pepper spray effect is configurable, as well as the total effect time.
  • The maximum range and angle w.r.t. the target can be configured, at which a target can be pepper sprayed.
  • Optimized to run at 0 ms when the script is idle, and a maximum of 0.03 ms when the pepper spray effect is applied.
  • If you use skinchanger, you can add pieces of clothing which give you immunity to the pepper spray effect. Other scripts handling player skins can also be implemented, as the corresponding function is accessible.
  • The normal version is encrypted, but key functions are still accessible via bridge code (see code snippets below).

The code snippets below are accessible in the encrypted version:

Config
Config = {}

-- If debug mode is enabled, you can use /pepperspray_effect to test out the pepper-spray effect
Config.Debug = false

-- The hash of the pepper-spray weapon
Config.PepperSprayWeaponHash = `weapon_pepperspray`

-- The keybind which on which the script will detect if the player is spraying, (24	= INPUT_ATTACK = LEFT MOUSE BUTTON)
Config.SprayDetectionKey = 24

-- These keys are disabled if the player is sprayed
Config.DisabledKeysWhenSprayed = { 24, 25, 22, 37, 73 } -- Attack, aim, jump, weapon wheel, X (see https://docs.fivem.net/docs/game-references/controls/ if you want to change these)

-- Configure the animation when someone is sprayed
Config.Animation = {
    Dict = 'switch@trevor@floyd_crying',
    Name = 'console_end_loop_floyd',
}

-- The time in milliseconds the spray-effect will last
Config.SprayEffectTimer = 10000

-- The main and extra timecycle modifier when someone is sprayed
Config.MainTimeCycle = 'drunk'
Config.ExtraTimeCycle = 'rply_vignette'

-- The maximum distance at which someone can get sprayed
Config.MaxmimumSprayDistance = 5.0

-- The maximum angle at which someone can get sprayed w.r.t. the players back, this ensure you cannot spray someone if you are not facing them, setting to zero allows you to also spray people from behind
Config.MaxmimumSprayAngle = 80

-- If you use the skinchanger script, you can add clothes below which make you immune to pepper-spray
-- If you dont the skinchanger script, you will have to edit the function Functions.DoesPedHaveImmuneClothes() in the bridge script before you can use this feature
Config.ImmuneClothes = {
    ['male'] = {
        ['helmet_1'] = { 18, 50, 51, 52, 53 },
        ['glasses_1'] = { 26 },
        ['mask_1'] = { 9, 10 },
    },
    ['female'] = {
        ['helmet_1'] = { 18, 50, 51, 52, 53 },
        ['glasses_1'] = { 26 },
        ['mask_1'] = { 9, 10 },
    }
}
Accessible Client Bridge Functions
Functions = {}

-- If this function returns true, the player will receive the pepper-spray effect
-- If this function returns false, the player will not receive the pepper-spray effect or the pepper-spray effect will be canceled
Functions.CanPlayerBeSprayed = function()
    local ped = PlayerPedId()
    local isDead = IsPedDeadOrDying(ped, true)
    local isPedInAnyVehicle = IsPedInAnyVehicle(ped, false)

    return (not isDead and not isPedInAnyVehicle)
end

-- Check if the ped has clothes which are immune to pepper-spray, like glasses or masks.
Functions.DoesPedHaveImmuneClothes = function()
    local immuneClothes = false

    -- This code below only works with skinchanger, but you can change it to the clothing script you are using
    if (GetResourceState('skinchanger') ~= 'started') then
        return immuneClothes
    end

    local skinReceived = false
    while (not skinReceived) do
        Wait(0)

        TriggerEvent('skinchanger:getSkin', function(skin)
            local gender = 'male'
            if (skin.sex == 1) then gender = 'female' end
            local clothesToCheck = Config.ImmuneClothes[gender]

            for clothing, component in pairs(skin) do
                if (clothesToCheck[clothing] ~= nil) then
                    for _, value in ipairs(clothesToCheck[clothing]) do
                        if (value == component) then
                            immuneClothes = true
                            break
                        end
                    end
                end
            end

            -- Ensure the function waits for the event handler above to finish
            skinReceived = true
        end)
    end

    return immuneClothes
end

Functions.OnPlayerSprayed = function()
    -- This function is triggered right before a player gets sprayed, you can execute any additional code you want here
end
Accessible Server Bridge Functions
local ESX = nil
local QBCore = nil

-- Select the correct framework
CreateThread(function()
    if (GetResourceState('es_extended') == 'started') then
        ESX = exports['es_extended']:getSharedObject()
    elseif (GetResourceState('qb-core') == 'started') then
        QBCore = exports['qb-core']:GetCoreObject()
    end
end)

Functions = {}

-- This function is executed before a player applies the spray-effect to another player. In this case configured to only work if the player has the police-job
Functions.CanPlayerApplySprayEffect = function(source)
    local xPlayer = nil
    if (ESX ~= nil) then
        xPlayer = ESX.GetPlayerFromId(source)
    elseif (QBCore ~= nil) then
        Player = QBCore.Functions.GetPlayer(source)
    end

    -- If neither framework is detected, we will allow the player to apply the spray-effect
    if (xPlayer == nil) then
        return true
    end

    if (xPlayer.job.name == 'police') then
        return true
    else
        return false
    end
end
Code is accessible No, but core functions are accessible
Subscription-based No
Lines (approximately) 331
Requirements None
Support Yes