/flip Command for cars.

Started by [KM]Helathien, Jun 09, 2018, 09:50 AM

Previous topic - Next topic

[KM]Helathien

/FLIP COMMAND.

I have not been able to find this command on the forum , so I thought I'd paste it here for help.
Credits: [KM]Helathien.

Code:
Add this in onPlayerCommand( player, cmd, text)

if ( cmd == "flip" )
{
if ( !player.Vehicle ) MessagePlayer( "[#ff1111]Error: [#ffffff]You need to be in a Vehicle to use this command." , player )
else
{
local veh = player.Vehicle;
veh.Rotation = Quaternion( 0.0, 0.0, 0.0, 0.0 );
MessagePlayer( "[#00ff00][INFO] [#ffffff]You have flipped your car." , player )
}
}

Hope it helps :D
Feel free to PM me for any help.
If I am not available on the forum come to VKs Official Server I am usually there.

Sebastian

This is one thing I keep forgeting to implement in my server.
I realize it only when my car rolls down the hill :D

Mohamed Boubekri

Quote from: Sebastian on Jun 09, 2018, 11:26 AMThis is one thing I keep forgeting to implement in my server.
I realize it only when my car rolls down the hill :D
Like me ;D
| What now ? | Not yet ! |
Morrocan:- [ 🇲🇦 ].

rww

With this, only driver can flip the car ;)

PlayerEnteringVehicle <- array(GetMaxPlayers(), 0);

function onPlayerPart(player,reason)
{
if (PlayerEnteringVehicle[player.ID] != 0) PlayerEnteringVehicle[player.ID] = 0;
return 1;
}

function onPlayerEnteringVehicle(player,vehicle,door)
{
PlayerEnteringVehicle[player.ID] = 1;
return 1;
}

function onPlayerEnterVehicle(player,vehicle,seat)
{
PlayerEnteringVehicle[player.ID] = 0;
return 1;
}

function onPlayerExitVehicle(player,vehicle)
{
if (PlayerEnteringVehicle[player.ID] > 0) PlayerEnteringVehicle[player.ID] = 0;
return 1;
}

function onPlayerCommand(player,cmd,text)
{
if (cmd) cmd = cmd.tolower();
local veh = player.Vehicle;

if ( cmd == "flip" )
{
if ( !veh ) MessagePlayer( "[#ff1111]Error: [#ffffff]You need to be in a Vehicle to use this command." , player );
else if ( PlayerEnteringVehicle[player.ID] > 0 || player.State == 4 ) MessagePlayer( "[#ff1111]Error: [#ffffff]You must be a driver." , player );
else
{
veh.EulerAngle = Vector(0.0,0.0,0.0);
MessagePlayer( "[#00ff00][INFO] [#ffffff]You have flipped your car." , player );
}
}
else MessagePlayer( "[#ff1111]Error: [#ffffff]This command doesn't exist." , player );
return 1;
}
Join to Irrelevant Club Discord: https://discord.gg/MsPPZ5uV4X

BeckzyBoi

This is a much better way of doing it. It'll flip only the vehicle x rotation 180 degrees.

function onPlayerCommand(player, command, arguments)
{
    if (cmd == "flip")
    {
            if (player.State != 3) MessagePlayer("Error: You must be the driver of a vehicle.", player)
            else
            {
                local ax = player.Vehicle.EulerAngle.x, ay = player.Vehicle.EulerAngle.y, az = player.Vehicle.EulerAngle.z;
                player.Vehicle.EulerAngle = Vector(ax < 0 ? ax + 3.14159 : ax - 3.14159, ay, az);
                MessagePlayer("ACTION: You have flipped the vehicle.", player);
            }
        }
    }
}

ℛḝξ☂

Quote from: rww on Jun 09, 2018, 02:24 PMWith this, only driver can flip the car ;)

How about :)
if  ( player.VehicleSlot == 0 ) MessagePlayer( "[#ff1111]Error: [#ffffff]You must be a driver." , player );
I may be a slow walker but I am always walking.

ysc3839

@BeckzyBoi #4 If I remembered correctly, you can just use player.Vehicle.EulerAngle.x = ... to change it.

BeckzyBoi

Quote from: ysc3839 on Jul 12, 2018, 08:12 AM@BeckzyBoi #4 If I remembered correctly, you can just use player.Vehicle.EulerAngle.x = ... to change it.

You actually can't. Doing that will reset the y and z angles also. I've got no idea why. The way I posted to do it is the only accurate way.

rww

#8
Quote from: Rest on Jul 12, 2018, 12:51 AM
Quote from: rww on Jun 09, 2018, 02:24 PMWith this, only driver can flip the car ;)

How about :)
if  ( player.VehicleSlot == 0 ) MessagePlayer( "[#ff1111]Error: [#ffffff]You must be a driver." , player );

Layter I check it ;)
Join to Irrelevant Club Discord: https://discord.gg/MsPPZ5uV4X