Skip to content

Commit

Permalink
code cleanup \nadded tests
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Nov 19, 2022
1 parent d68f9f6 commit c8ceb3e
Show file tree
Hide file tree
Showing 11 changed files with 511 additions and 463 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# knxr-antitroll

![Image](https://i.imgur.com/ugH2X8D.png)

## Features
- Admin Command to Toggle antitroll: /troll <id>
- AntiVDM
- Disable DriveBy
- Disable Punching / Disable Punching Damage

## Installation
- Downloaded!
- Move it to your Resources folder.
- Have Fun! :D
# knxr-antitroll

![Image](https://i.imgur.com/ugH2X8D.png)

## Features
- Admin Command to Toggle antitroll: /troll <id>
- AntiVDM
- Disable DriveBy
- Disable Punching / Disable Punching Damage

## Installation
- Downloaded!
- Move it to your Resources folder.
- Have Fun! :D
233 changes: 117 additions & 116 deletions client/cl_functions.lua
Original file line number Diff line number Diff line change
@@ -1,117 +1,118 @@
local isTimerInstance = false
function setUiShow(bool)
SendNUIMessage({
type = "show",
show = bool
})
end

function updateUiTime(timeLeft)
SendNUIMessage({
type = "update",
minleft = timeLeft
})
end

function updateTimeToDatabase(overrideTime)
TriggerServerEvent("knxr-antitroll:updateTime", overrideTime or timeLeft)
end

function startTimer()
local interval = timeToSafe

updateTimeToDatabase()

CreateThread(function()
isTimerInstance = true
while hasProtection do

if interval == timeToSafe or timeLeft <= 0 then
interval = 0
setUiShow(true)
updateTimeToDatabase()
end

interval = interval + 1

if timeLeft <= 0 then
stopAntiTroll()
isTimerInstance = false
return
end

timeLeft = timeLeft - 1


updateUiTime(timeLeft)
Wait(1000 * 60)
end
end)
end

function startAntiTroll()
if not isTimerInstance then
startTimer()
end
setUiShow(true)

-- Anti VDM
if Config.DisableVDM then
SetWeaponDamageModifier(-1553120962, 0.0)
end

-- Anti Driveby
if not Config.DriveBy then
SetPlayerCanDoDriveBy(PlayerId(), false)
end

if Config.DisablePunching then
CreateThread(function()
while hasProtection do
Wait(5)
DisableControlAction(0, 140, true)
DisableControlAction(0, 141, true)
DisableControlAction(0, 142, true)
end
end)
end

if Config.DisableShooting then
CreateThread(function()
while hasProtection do
Wait(5)
DisablePlayerFiring(player, true)
end
end)
end

if Config.DisablePunchingDamage then
SetWeaponDamageModifier(-1569615261, 0.0)
end
end

function stopAntiTroll()
hasProtection = false
timeLeft = 0

-- Anti VDM
if Config.DisableVDM then
SetWeaponDamageModifier(-1553120962, 1.0)
end

-- Anti Driveby
if not Config.DriveBy then
SetPlayerCanDoDriveBy(PlayerId(), true)
end

if Config.DisablePunching then
EnableControlAction(0, 140, true)
EnableControlAction(0, 141, true)
EnableControlAction(0, 142, true)
end

if Config.DisablePunchingDamage then
SetWeaponDamageModifier(-1569615261, 1.0)
end
setUiShow(false)
local isTimerInstance = false

function setUiShow(bool)
SendNUIMessage({
type = "show",
show = bool
})
end

function updateUiTime(timeLeft)
SendNUIMessage({
type = "update",
minleft = timeLeft
})
end

function updateTimeToDatabase(overrideTime)
TriggerServerEvent("knxr-antitroll:updateTime", overrideTime or timeLeft)
end

function startTimer()
local interval = timeToSafe

updateTimeToDatabase()

CreateThread(function()
isTimerInstance = true
while hasProtection do

if interval == timeToSafe or timeLeft <= 0 then
interval = 0
setUiShow(true)
updateTimeToDatabase()
end

interval = interval + 1

if timeLeft <= 0 then
stopAntiTroll()
isTimerInstance = false
return
end

timeLeft = timeLeft - 1


updateUiTime(timeLeft)
Wait(1000 * 60)
end
end)
end

function startAntiTroll()
if not isTimerInstance then
startTimer()
end
setUiShow(true)

-- Anti VDM
if Config.DisableVDM then
SetWeaponDamageModifier(-1553120962, 0.0)
end

-- Anti Driveby
if not Config.DriveBy then
SetPlayerCanDoDriveBy(PlayerId(), false)
end

if Config.DisablePunching then
CreateThread(function()
while hasProtection do
Wait(5)
DisableControlAction(0, 140, true)
DisableControlAction(0, 141, true)
DisableControlAction(0, 142, true)
end
end)
end

if Config.DisableShooting then
CreateThread(function()
while hasProtection do
Wait(5)
DisablePlayerFiring(player, true)
end
end)
end

if Config.DisablePunchingDamage then
SetWeaponDamageModifier(-1569615261, 0.0)
end
end

function stopAntiTroll()
hasProtection = false
timeLeft = 0

-- Anti VDM
if Config.DisableVDM then
SetWeaponDamageModifier(-1553120962, 1.0)
end

-- Anti Driveby
if not Config.DriveBy then
SetPlayerCanDoDriveBy(PlayerId(), true)
end

if Config.DisablePunching then
EnableControlAction(0, 140, true)
EnableControlAction(0, 141, true)
EnableControlAction(0, 142, true)
end

if Config.DisablePunchingDamage then
SetWeaponDamageModifier(-1569615261, 1.0)
end
setUiShow(false)
end
72 changes: 36 additions & 36 deletions client/cl_main.lua
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
-- old esx Support
if not ESX then
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
while ESX == nil do
Citizen.Wait(0)
end
end

hasProtection = false
timeLeft = 0

-- STATIC VARIABLES
timeToSafe = Config.TimeToSave

RegisterNetEvent("knxr-antitroll:toggle", function(toggle, timeOverride)
hasProtection = toggle or not hasProtection
timeLeft = timeOverride or Config.HowLong

if hasProtection then
startAntiTroll()
else
stopAntiTroll()
updateTimeToDatabase(0)
end
end)

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded',function(xPlayer, isNew, skin)
TriggerServerEvent("knxr-antitroll:onjoin", isNew)
end)

AddEventHandler("onResourceStart", function(resourceName)
if resourceName == GetCurrentResourceName() then
TriggerServerEvent("knxr-antitroll:onjoin", false)
end
-- old esx Support
if not ESX then
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
while ESX == nil do
Citizen.Wait(0)
end
end

hasProtection = false
timeLeft = 0

-- STATIC VARIABLES
timeToSafe = Config.TimeToSave

RegisterNetEvent("knxr-antitroll:toggle", function(toggle, timeOverride)
hasProtection = toggle or not hasProtection
timeLeft = timeOverride or Config.HowLong

if hasProtection then
startAntiTroll()
else
stopAntiTroll()
updateTimeToDatabase(0)
end
end)

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded',function(xPlayer, isNew, skin)
TriggerServerEvent("knxr-antitroll:onjoin", isNew)
end)

AddEventHandler("onResourceStart", function(resourceName)
if resourceName == GetCurrentResourceName() then
TriggerServerEvent("knxr-antitroll:onjoin", false)
end
end)
26 changes: 13 additions & 13 deletions config.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Config = {}

Config.AdminCommand = "troll" -- The Name of the Admin Command
Config.Rang = "admin" -- The Rang needed for the Admin Command

Config.HowLong = 60 -- How Long the Player should have antitroll on
Config.TimeToSave = 5 -- How often the time should be saved in the Database

-- SETTING FOR PLAYERS WITH ANTITROLL ON
Config.DisableVDM = true -- Disables damage from cars while the player still has Troll Protection. (Players still get demage off the ground)
Config.DriveBy = false -- Activates / Deactivates Drivebys
Config.DisableShooting = false -- Disables Shooting
Config.DisablePunching = true -- Disables hitting for players still in troll protect mode
Config = {}

Config.AdminCommand = "troll" -- The Name of the Admin Command
Config.Rang = "admin" -- The Rang needed for the Admin Command

Config.HowLong = 60 -- How Long the Player should have antitroll on
Config.TimeToSave = 5 -- How often the time should be saved in the Database

-- SETTING FOR PLAYERS WITH ANTITROLL ON
Config.DisableVDM = true -- Disables damage from cars while the player still has Troll Protection. (Players still get demage off the ground)
Config.DriveBy = false -- Activates / Deactivates Drivebys
Config.DisableShooting = false -- Disables Shooting
Config.DisablePunching = true -- Disables hitting for players still in troll protect mode
Config.DisablePunchingDamage = true -- Disables the Damage other would get with Fists when they get Punshed
Loading

0 comments on commit c8ceb3e

Please sign in to comment.