that_safeAttack is a FiveM script designed to prevent accidental punches and attacks between players. The script ensures that a player can only punch or attack if they are purposefully aiming at someone by holding the right-click button. This helps maintain a more controlled and intentional gameplay experience.
Forum that_safeAttack
Credits to mrm-SafePunch for the concept
- Blocks unintentional punches and attacks.
- Can be configured to allow attacks only when unarmed or when aiming with a weapon.
- Customizable whitelist/blacklist for specific weapons.
- Easy to install and configure with no dependencies.
- Download the script.
- Drag and drop the script into your FiveM server resources folder.
- Add ensure that_safeAttack to your server configuration file, in any order with other scripts. Except if calling api from any script, it must be after this script is ensured
Config.UnarmedOnly = true – Ensures player is unarmed to attack. Set to false to require aiming with a weapon.
Config.ArmedWeaponList – List of weapons to be whitelisted or blacklisted.
Config.ArmedWeaponListBlacklisted = false – Determines if the Config.ArmedWeaponList is a blacklist (true) or whitelist (false).
TriggerEvent('that_safeAttack:attackStateChange', disable) – Called every time the attack state changes.
TriggerEvent('that_safeAttack:attackFailed') – Called every time the attack fails.
exports['that_safeAttack']:isDisabled() – Returns whether the attack is disabled or not.
You may change the script name; events and exports will still work, but you must update the API calls accordingly.
For example if script name is changed to 'safeAttack' so when calling the api you should use TriggerEvent('safeAttack:attackStateChange', disable) and exports['safeAttack']:isDisabled().
AddEventHandler('that_safeAttack:attackStateChange', function(disable)
if disable then
-- do something
else
-- do something else
end
end)AddEventHandler("that_safeAttack:attackFailed", function()
-- do something
-- TriggerEvent('esx:showNotification', "You cannot attack")
end)Citizen.CreateThread(function()
while true do
if exports['that_safeAttack']:isDisabled() then
-- do something
else
-- do something else
end
Wait(1)
end
end)