Vehicle will always go forward
#1

Hey,

1. I want to make a script that players will be in vehicle and the vehicle will always go forward
but they will can control him with the keys A-D to go right and left.

2. I want to disable in vehicle the button S (backward).

How can I do it?
thx.
Reply
#2

I am not quite sure you can do that. I mean, I suppose that you could teleport the player with the vehicle to their same location whenever they press S which will keep them in place, but that is not sure to work.

Give it a shot, I would like to know how it works.

Also, I don't think you can force the vehicle to move forward at all times.
Reply
#3

This could be possible by turning off vehicle engine and using function SetVehicleVelocity to push vehicle forward. Since the engine is turned off, the player wont be able to move forward, but I can't tell you if he can use the breaks while the car is turned off.
Reply
#4

Quote:
Originally Posted by CmZxC
Посмотреть сообщение
This could be possible by turning off vehicle engine and using function SetVehicleVelocity to push vehicle forward. Since the engine is turned off, the player wont be able to move forward, but I can't tell you if he can use the breaks while the car is turned off.
how I need to to use vehicle velocity to get the vehicle go forward? that what I search for the function SetVehicleVelocity(.....
Reply
#5

pawn Код:
new bool:ForwardSwitch = false;
new Float:multiplier = 0.2;

CMD:speed(playerid, params[])
{
    new Float:tmpFloat = floatstr(params);
    if(tmpFloat <= 0 || tmpFloat >= 2)
        multiplier = 0.2;
    else
        multiplier = tmpFloat;
    return 1;
}

CMD:test(playerid, params[])
{
    if(ForwardSwitch)
        ForwardSwitch = false;
    else
        ForwardSwitch = true;

    return 1;
}

public OnPlayerUpdate(playerid)
{
    if(ForwardSwitch == true && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new Float:x1,Float:y1,Float:z1;
        new Float:x2,Float:y2,Float:z2;
        GetVehiclePos(GetPlayerVehicleID(playerid), x1, y1, z1);
        GetXYInFrontOfPlayer(playerid, x2, y2, z2, 1);

        x1=(x2-x1)*multiplier;
        y1=(y2-y1)*multiplier;
        z1=(z2-z1)*multiplier;

        SetVehicleVelocity(GetPlayerVehicleID(playerid), x1, y1, z1);


    }
    return 1;
}

stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, &Float:z, Float:distance)
{   // Created by ******

    new Float:a;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, a);
    if (GetPlayerVehicleID(playerid))
    {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}
That is yours starting point...The bigger the multiplier, faster vehicle will go...
Reply
#6

Quote:
Originally Posted by Hirsw0w
Посмотреть сообщение
Hey,

1. I want to make a script that players will be in vehicle and the vehicle will always go forward
but they will can control him with the keys A-D to go right and left.
That would be called cruise control, to be honest this is old and works not very well, but It's a good reference to understand how to create it https://sampforum.blast.hk/showthread.php?tid=131591
Quote:
Originally Posted by Hirsw0w
Посмотреть сообщение
2. I want to disable in vehicle the button S (backward).

How can I do it?
thx.
Not possible ( actually you can cancel the vehicle going backward by checking the facing angle and velocity, but can't actually disable S button)
Reply
#7

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
That would be called cruise control, to be honest this is old and works not very well, but It's a good reference to understand how to create it https://sampforum.blast.hk/showthread.php?tid=131591
Cruise control is to keep current speed, as i understood he need vehicle to drive forward for itself all the time. (Probably some kind of mini game with avoiding obstacles or something like that...)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)