SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 01/11/2019, 10:46 AM   #1
Uberanwar
Gangsta
 
Uberanwar's Avatar
 
Join Date: May 2012
Location: Malaysia
Posts: 892
Reputation: 63
Question Bike up arrow spam

How do I prevent players to spam up arrow to accelerate the speed of their motorbike? It is known that spamming up arrow button will accelerate motorbike speed, and I would like it so that it will make their bike slower instead to prevent abuse

Last edited by Uberanwar; 03/11/2019 at 06:53 PM.
Uberanwar is offline   Reply With Quote
Old 01/11/2019, 10:59 AM   #2
Proxus
Huge Clucker
 
Proxus's Avatar
 
Join Date: May 2018
Location: United Kingdom
Posts: 432
Reputation: 20
Default Re: Bike up arrow spam

Quote:
Originally Posted by Uberanwar View Post
How do I prevent players to spam up arrow to accelerate the speed of their motorbike? It is known that spamming up arrow button will accelerate motorbike speed, and I would like it so that it will make their bike slower instead to prevent abuse
I've made this (untested as I can't test right now, sorry!)

It checks if the vehicle id of the player is a bike, and then checks if 2 seconds have passed since pressing the up key last. If they spam it, it freezes the player and then unfreezes them (as I made the script but missed the part where you asked for slowing it down.

Code:
new SpeedUpCooldown[MAX_PLAYERS];

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(GetPlayerState == 2)
    {
        if (((newkeys & KEY_UP) && !(oldkeys & KEY_UP)))
        {
            switch(GetPlayerVehicleID(playerid)) 
            {
                case 448, 461, 462, 463, 468, 471, 481, 509, 510, 521, 522, 581, 586:
                {
                    new currentTime = gettime();
                    if currentTime < (SpeedUpCooldown[playerid] + 2) // change this depending on how long you want to prevent spam for
                    {
                        TogglePlayerControllable(playerid, 0);
                        SetTimerEx("PlayerCanControl", 100, false, "i", playerid);
                    }

                    SpeedUpCooldown[playerid] = gettime();
                }
            }
        }   
    }

    return 1;
}

forward PlayerCanControl(playerid);
public PlayerCanControl(playerid)
{
    TogglePlayerControllable(playerid, 1);

    return 1;
}
If you want to slow the player down, consider using:
https://wiki.sa-mp.com/wiki/SetVehicleVelocity

Code:
SetVehicleVelocity(GetPlayerVehicleID(playerid), x, y, z); // change x y z
__________________
Developer @ Trucknation
"Never tell people how to do things. Tell them what to do and they will surprise you with their ingenuity"


IMPORTANT LINKS
An upcoming mix of trucking & light roleplay

Looking for a mapper interested in mapping for a trucking/light roleplay server that has knowledge on how to use Texture Studio. PM me on the forums or on Discord (Discord server: Click Me)
Proxus is offline   Reply With Quote
Old 01/11/2019, 03:51 PM   #3
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,739
Reputation: 585
Default Re: Bike up arrow spam

Quote:
Originally Posted by Proxus View Post
I've made this (untested as I can't test right now, sorry!)

It checks if the vehicle id of the player is a bike, and then checks if 2 seconds have passed since pressing the up key last. If they spam it, it freezes the player and then unfreezes them (as I made the script but missed the part where you asked for slowing it down.

Code:
new SpeedUpCooldown[MAX_PLAYERS];

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(GetPlayerState == 2)
    {
        if (((newkeys & KEY_UP) && !(oldkeys & KEY_UP)))
        {
            switch(GetPlayerVehicleID(playerid)) 
            {
                case 448, 461, 462, 463, 468, 471, 481, 509, 510, 521, 522, 581, 586:
                {
                    new currentTime = gettime();
                    if currentTime < (SpeedUpCooldown[playerid] + 2) // change this depending on how long you want to prevent spam for
                    {
                        TogglePlayerControllable(playerid, 0);
                        SetTimerEx("PlayerCanControl", 100, false, "i", playerid);
                    }

                    SpeedUpCooldown[playerid] = gettime();
                }
            }
        }   
    }

    return 1;
}

forward PlayerCanControl(playerid);
public PlayerCanControl(playerid)
{
    TogglePlayerControllable(playerid, 1);

    return 1;
}
If you want to slow the player down, consider using:
https://wiki.sa-mp.com/wiki/SetVehicleVelocity

Code:
SetVehicleVelocity(GetPlayerVehicleID(playerid), x, y, z); // change x y z
That's not how the glitch works, KEY_UP and KEY_DOWN are the directional keys (W and S, used for acceleration and brakes). Those are not the buttons you do the glitch with, you need to check for KEY_ANALOG_UP (lean forward for vehicles).
Also the delay is tricky and needs to be something like 100ms or less, the button is usually spammed as fast as humanly possible to keep the character in a specific position of the "lean forward animation" which speeds up the bike. With a controller this can be done completely undetected since you can just hold it in a specific spot and SAMP doesn't call OnPlayerKeyStateChange for that.

I think it would be better to limit each bike at their actual top speeds regardless of key states, firstly because it's easier to detect and secondly because there are 2 more speed glitches that are not really detectable. That would only allow for faster acceleration but any detection using keys can be circumvented by a gamepad.
NaS is offline   Reply With Quote
Old 01/11/2019, 03:55 PM   #4
Proxus
Huge Clucker
 
Proxus's Avatar
 
Join Date: May 2018
Location: United Kingdom
Posts: 432
Reputation: 20
Default Re: Bike up arrow spam

Quote:
Originally Posted by NaS View Post
That's not how the glitch works, KEY_UP and KEY_DOWN are the directional keys (W and S, used for acceleration and brakes). Those are not the buttons you do the glitch with, you need to check for KEY_ANALOG_UP (lean forward for vehicles).
Also the delay is tricky and needs to be something like 100ms or less, the button is usually spammed as fast as humanly possible to keep the character in a specific position of the "lean forward animation" which speeds up the bike. With a controller this can be done completely undetected since you can just hold it in a specific spot and SAMP doesn't call OnPlayerKeyStateChange for that.

I think it would be better to limit each bike at their actual top speeds, firstly because it's easier to detect and secondly because there are 2 more speed glitches that are not really detectable.
Ah okay, thanks for clarifying.
__________________
Developer @ Trucknation
"Never tell people how to do things. Tell them what to do and they will surprise you with their ingenuity"


IMPORTANT LINKS
An upcoming mix of trucking & light roleplay

Looking for a mapper interested in mapping for a trucking/light roleplay server that has knowledge on how to use Texture Studio. PM me on the forums or on Discord (Discord server: Click Me)
Proxus is offline   Reply With Quote
Old 01/11/2019, 04:35 PM   #5
Unte99
Gangsta
 
Unte99's Avatar
 
Join Date: Jul 2010
Location: Lithuania
Posts: 627
Reputation: 65
Default Re: Bike up arrow spam

Quote:
Originally Posted by NaS View Post
That's not how the glitch works, KEY_UP and KEY_DOWN are the directional keys (W and S, used for acceleration and brakes). Those are not the buttons you do the glitch with, you need to check for KEY_ANALOG_UP (lean forward for vehicles).
Also the delay is tricky and needs to be something like 100ms or less, the button is usually spammed as fast as humanly possible to keep the character in a specific position of the "lean forward animation" which speeds up the bike. With a controller this can be done completely undetected since you can just hold it in a specific spot and SAMP doesn't call OnPlayerKeyStateChange for that.

I think it would be better to limit each bike at their actual top speeds regardless of key states, firstly because it's easier to detect and secondly because there are 2 more speed glitches that are not really detectable. That would only allow for faster acceleration but any detection using keys can be circumvented by a gamepad.

That would be better but it would still be problematic with the free-fall of bikes.
Unte99 is offline   Reply With Quote
Old 01/11/2019, 06:53 PM   #6
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 375
Reputation: 92
Default Re: Bike up arrow spam

Quote:
Originally Posted by Unte99 View Post
That would be better but it would still be problematic with the free-fall of bikes.
Dont calculate the height (Z)
__________________
Lokii is offline   Reply With Quote
Old 01/11/2019, 07:30 PM   #7
Unte99
Gangsta
 
Unte99's Avatar
 
Join Date: Jul 2010
Location: Lithuania
Posts: 627
Reputation: 65
Default Re: Bike up arrow spam

Quote:
Originally Posted by Lokii View Post
Dont calculate the height (Z)
What does that change?
Unte99 is offline   Reply With Quote
Old 01/11/2019, 07:34 PM   #8
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 375
Reputation: 92
Default Re: Bike up arrow spam

Quote:
Originally Posted by Unte99 View Post
What does that change?
it will not calculate the height speed so you wont have problems with free fall
__________________
Lokii is offline   Reply With Quote
Old 01/11/2019, 08:01 PM   #9
Markski
Big Clucker
 
Markski's Avatar
 
Join Date: Apr 2015
Location: La Plata, Argentina
Posts: 121
Reputation: 43
Default Re: Bike up arrow spam

Quote:
Originally Posted by Lokii View Post
it will not calculate the height speed so you wont have problems with free fall
No, what he's saying is this will stop players from changing the angle of their bike while freefalling or jumping, as those are the same keys used for the up arrow bug.

Furthermore I'd argue checking for an up keystroke every 2 seconds is too agressive, by the nature of the bug 1 second should more than suffice.
Markski is offline   Reply With Quote
Old 03/11/2019, 06:52 PM   #10
Uberanwar
Gangsta
 
Uberanwar's Avatar
 
Join Date: May 2012
Location: Malaysia
Posts: 892
Reputation: 63
Default Re: Bike up arrow spam

Thank you for the replies.
Uberanwar is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[HELP] bmx,bike,mountain bike problem Luca12 Scripting Help 2 23/10/2016 11:02 PM
RED ARROW. budelis Scripting Help 9 08/12/2012 07:28 PM
Arrow Red_Dragon. Scripting Help 5 07/11/2012 05:41 PM
[FilterScript] Spam Prevention System (Anti Spam) Luka P. Filterscripts 9 14/09/2011 12:56 PM
arrow. davelord Help Archive 6 20/04/2011 08:16 PM


All times are GMT. The time now is 06:09 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.