Jump to content

AntiHorn Resource [Intended for Race servers]


unknooooown

Recommended Posts

Noticed a few people on a race server the other day talk about how annoying it is when people race with H pressed down, spamming the horn. I decided to make a small resource that kicks a player if he/her holds H down for 10 secs.

The amount of time allowed can be changed in the script.

Just wanted to share in case someone need it :)

https://community.multitheftauto.com/index.php?p=resources&s=details&id=3508

If any changes to this resource is needed, please let me know here, on IRC or on the forums. Please note that this resource was scripting in a few minutes and is only intended to take care of the vehicle horn issue.

Should there be any problems then please report them to me asap so I can fix it.

------------------------------------------------------------

This script can take care of players that keep pressing the horn down during a race.

Noticed that a few race servers needed a script to kick players abusing the vehicle horn.

It is possible to change both the allowed horn time and the kick message inside the file 'antiHorn.lua'

Default Time: 10 seconds

Default Message: "Abusing Vehicle Horn"

------------------------------------------------------------

To make the resource work, please add this following line to your admin ACL.:

Example:

------------------------------------------------------------

Your 'acl.xml' file can be found in:

MTA San Andreas 1.2\server\mods\deathmatch\acl.xml

Link to comment

Here is a small script I made for this awhile ago. It detects both if a player has been holding the horn for a long time and tapping the horn a bunch. It will kick the player if they abuse the horn to a certain extent - but will forgive the player little by little over time.

  
-- 
--  CLIENTSIDE 
-- 
local lastHornState, lastHornStateChange, hornViolations = getControlState("horn"), 0, 0 
  
-- This function processes the horn antispam for the local player 
local function processHornAntispam() 
    if not isPedInVehicle(localPlayer) then 
        return 
    end 
     
    if getControlState("horn") then 
        if not lastHornState then 
            -- If the horn has been pressed within the last 300 ms, increment the counter. 
            if getTickCount() - lastHornStateChange <= 300 then 
                hornViolations = hornViolations + 0.5 
            end 
            lastHornState = true 
            lastHornStateChange = getTickCount() 
        else 
            -- If the player has hit the horn for more than 4 seconds, increment the counter. 
            if getTickCount() - lastHornStateChange >= 4000 then 
                hornViolations = hornViolations + 1 
                lastHornStateChange = getTickCount() 
            end 
        end 
    else 
        if lastHornState then 
            lastHornState = false 
            lastHornStateChange = getTickCount() 
        else 
            -- If the player has been good for the last 10 seconds, decrement the counter 
            if getTickCount() - lastHornStateChange >= 10000 then 
                hornViolations = hornViolations - 1 
                lastHornStateChange = getTickCount() 
            end 
        end 
    end 
     
    -- If the player has 4 violations, kick them. 
    if hornViolations >= 4 then 
        hornViolations = 0 -- Reset counter to zero, so the kick event is not triggered every render (in case the server fails to kick the client). 
        triggerServerEvent("clientHornAntispamTriggered", localPlayer) 
    end 
end 
addEventHandler("onClientRender", root, processHornAntispam) 
  
-- 
--  SERVERSIDE 
-- 
local function onHornAntispamTriggered() 
    if source ~= client then return end 
     
    kickPlayer(source, "Please refrain from spamming the horn!") 
end 
addEvent("clientHornAntispamTriggered", true) 
addEventHandler("clientHornAntispamTriggered", root, onHornAntispamTriggered) 
  

Sorry to spoil this Wafamde :}

Link to comment

Here is a version that just mutes the horn for 60 seconds.

  
-- 
--  CLIENTSIDE 
-- 
local lastHornState, lastHornStateChange, hornViolations, isHornMuted = getControlState("horn"), 0, 0, false 
  
-- This function processes the horn antispam for the local player 
local function processHornAntispam() 
    if not isPedInVehicle(localPlayer) then 
        return 
    end 
     
    -- If the horn is muted, manually set the control state of the horn to false. 
    if isHornMuted then 
        setControlState("horn", false) 
        if getTickCount() - lastHornStateChange >= 60000 then 
            isHornMuted = false 
        end 
        return 
    end 
     
    if getControlState("horn") then 
        if not lastHornState then 
            -- If the horn has been pressed within the last 300 ms, increment the counter. 
            if getTickCount() - lastHornStateChange <= 300 then 
                hornViolations = hornViolations + 0.5 
            end 
            lastHornState = true 
            lastHornStateChange = getTickCount() 
        else 
            -- If the player has hit the horn for more than 4 seconds, increment the counter. 
            if getTickCount() - lastHornStateChange >= 4000 then 
                hornViolations = hornViolations + 1 
                lastHornStateChange = getTickCount() 
            end 
        end 
    else 
        if lastHornState then 
            lastHornState = false 
            lastHornStateChange = getTickCount() 
        else 
            -- If the player has been good for the last 10 seconds, decrement the counter 
            if getTickCount() - lastHornStateChange >= 10000 then 
                hornViolations = hornViolations - 1 
                lastHornStateChange = getTickCount() 
            end 
        end 
    end 
     
    -- If the player has 4 violations, mute the horn. 
    if hornViolations >= 4 then 
        isHornMuted = true 
    end 
end 
addEventHandler("onClientRender", root, processHornAntispam) 
  

Link to comment
Anyway antihorn looks annoying, you turn off speakers and problem solved.

And cannot listen to music, or to some certain sounds you may need...

Nah, antihorn isn't annoying. It's cool as

.

Horns are played once the map starts, that can't definitly annoy you...

Link to comment
Horns are played once the map starts, that can't definitly annoy you...

This is most true. Other than map starts, honking isn't used too much or at all

Just disable the control when the map is starting clientside...

'onClientMapStarting' -> toggleControl('horn', false)

That's the whole script. No need to re-enable honking once the race has started because the race gamemode is smart enough to toggleAllControls anyway :P

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...