Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: [KM]Helathien on Jun 09, 2018, 09:50 AM

Title: /flip Command for cars.
Post by: [KM]Helathien on Jun 09, 2018, 09:50 AM
/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
Title: Re: /flip Command for cars.
Post by: Sebastian on Jun 09, 2018, 11:26 AM
This is one thing I keep forgeting to implement in my server.
I realize it only when my car rolls down the hill :D
Title: Re: /flip Command for cars.
Post by: Mohamed Boubekri on Jun 09, 2018, 12:49 PM
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
Title: Re: /flip Command for cars.
Post by: rww on Jun 09, 2018, 02:24 PM
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;
}
Title: Re: /flip Command for cars.
Post by: BeckzyBoi on Jul 12, 2018, 12:46 AM
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);
            }
        }
    }
}
Title: Re: /flip Command for cars.
Post by: ℛḝξ☂ 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 );
Title: Re: /flip Command for cars.
Post by: 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.
Title: Re: /flip Command for cars.
Post by: BeckzyBoi on Jul 12, 2018, 07:42 PM
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.
Title: Re: /flip Command for cars.
Post by: rww on Jul 16, 2018, 09:11 PM
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 ;)