SA-MP Forums Archive
[Question] stop vehicle - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [Question] stop vehicle (/showthread.php?tid=349508)



topic can delete - mickos - 09.06.2012

topic can delete


Re: [Question] stop vehicle - [KHK]Khalid - 09.06.2012

https://sampwiki.blast.hk/wiki/Function:...erControllable .


Re: [Question] stop vehicle - mickos - 09.06.2012

Hmm not where i looking for, I mean a player press capslock, and than the vehicle stop,


Re: [Question] stop vehicle - [KHK]Khalid - 09.06.2012

TogglePlayerControllable will freeze the player and stop his vehicle (if he's in one). Seems like you want the whole code, don't you?


Edit:

You also may declare a timer (like 500 ms) after you freeze the player (to stop his vehicle) to unfreeze him, if you want only the vehicle to be stopped.

Second-Edit: or just use https://sampwiki.blast.hk/wiki/SetVehicleVelocity


topic can delete - mickos - 09.06.2012

topic can delete


Re: [Question] stop vehicle - [KHK]Khalid - 09.06.2012

read the example in this page.


topic can delete - mickos - 09.06.2012

topic can delete


Re: [Question] stop vehicle - BlackBank - 09.06.2012

Quote:
Originally Posted by HellSphinX
Посмотреть сообщение
TogglePlayerControllable will freeze the player and stop his vehicle (if he's in one). Seems like you want the whole code, don't you?


Edit:

You also may declare a timer (like 500 ms) after you freeze the player (to stop his vehicle) to unfreeze him, if you want only the vehicle to be stopped.

Second-Edit: or just use https://sampwiki.blast.hk/wiki/SetVehicleVelocity
Why you want to use TogglePlayerControllable for it? You know that if you freeze a player, the vehicle is still going forward... So the best way to stop a vehicle, is using SetVehicleVelocity...

EDIT:
Try this code:
pawn Код:
#define FILTERSCRIPT
#include <a_samp>

#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Stop vehicle by Example 0.3");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_CROUCH))
    {
        if(!IsPlayerInAnyVehicle(playerid)) return 1;
        new
            Float:X,
            Float:Y,
            Float:Z,
            VehicleID = GetPlayerVehicleID(playerid);
        GetVehicleVelocity(VehicleID, X, Y, Z);
        SetVehicleVelocity(VehicleID, -X, -Y, -Z);
    }
    return 1;
}
#endif



Re: [Question] stop vehicle - [KHK]Khalid - 09.06.2012

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_CROUCH))
    {
        if(IsPlayerInAnyVehicle(playerid)) // checks if playrid in a vehicle
        {
            new
                Float:x,
                Float:y,
                Float:z,
                playerveh = GetPlayerVehicleID(playerid); // gets the id of the player's vehicle and store it into playerveh so we can use it in Get/SetVehiclePos
                GetVehiclePos(playerveh, x, y, z);
                SetVehiclePos(playerveh, x, y, z + 2.0);
        }
    }
    return 1;
}

Edit:

Quote:
Originally Posted by BlackBank3
Посмотреть сообщение
Why you want to use TogglePlayerControllable for it? You know that if you freeze a player, the vehicle is still going forward... So the best way to stop a vehicle, is using SetVehicleVelocity...
No, the vehicle won't go forward actually it will stop (That's tested).


Re: [Question] stop vehicle - FalconX - 09.06.2012

Quote:
Originally Posted by HellSphinX
Посмотреть сообщение
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_CROUCH))
    {
        if(IsPlayerInAnyVehicle(playerid)) // checks if playrid in a vehicle
        {
            new
                Float:x,
                Float:y,
                Float:z,
                playerveh = GetPlayerVehicleID(playerid); // gets the id of the player's vehicle and store it into playerveh so we can use it in Get/SetVehiclePos
                GetVehiclePos(playerveh, x, y, z);
                SetVehiclePos(playerveh, x, y, z + 2.0);
        }
    }
    return 1;
}

Edit:



No, the vehicle won't go forward actually it will stop (That's tested).
It's strange, why are you setting vehicle pos? if you want to stop the vehicle you could just stop the engine... SetVehicleParamsForPlayer.

-FalconX