26.04.2017, 12:25
how to make vehicle boost system same as gamerX?
#include <a_samp>
#define VEL_AM 1.8 //Set this to what you want, have a play with it to set the speeds.
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_FIRE){ //Check to see if the player has clicked the shooting button (Left mouse / Left CTRL as default)
switch(GetPlayerState(playerid)) //Get the state of the player and check below.
{
case PLAYER_STATE_DRIVER: //Check to see if the player is the driver.
{
new Float:vPos[3];
GetVehicleVelocity(GetPlayerVehicleID(playerid), vPos[0], vPos[1], vPos[2]); //Get the current velocity (speed / direction / height etc...)
SetVehicleVelocity(GetPlayerVehicleID(playerid), vx * VEL_AM, vy * VEL_AM, vz); //Set the vehicles velocity (EG: Add the boost!)
}
}
}
return 1;
}
#define VELOCITY_BOOST 1.6 new Float:vx, Float:vy, Float:vz, Float:a, Float:vl; GetVehicleVelocity(GetPlayerVehicleID(playerid), vx, vy, vz); // Get current Velocity vl = floatsqroot(vx*vx + vy*vy); // Calculate X/Y Vector length to be able to calculate a Vector which is definitely higher than this GetVehicleZAngle(GetPlayerVehicleID(playerid), a); // Get Angle vx = vl * VELOCITY_BOOST * floatsin(-a, degrees); // This calculates a new Vector, pointing in the direction of a and multiplied by VELOCITY_BOOST vy = vl * VELOCITY_BOOST * floatcos(-a, degrees); SetVehicleVelocity(GetPlayerVehicleID(playerid), vx, vy, vz);
You'll have to tetrieve the Angle of the Vehicle and based on that, a Vector pointing to the same direction.
To make the boost effective at all times you also have to calculate the current total velocity (X/Y) and make the new vector length longer than the current (else you will not speed up). Код:
#define VELOCITY_BOOST 1.6 new Float:vx, Float:vy, Float:vz, Float:a, Float:vl; GetVehicleVelocity(GetPlayerVehicleID(playerid), vx, vy, vz); // Get current Velocity vl = floatsqroot(vx*vx + vy*vy); // Calculate X/Y Vector length to be able to calculate a Vector which is definitely higher than this GetVehicleZAngle(GetPlayerVehicleID(playerid), a); // Get Angle vx = vl * VELOCITY_BOOST * floatsin(-a, degrees); // This calculates a new Vector, pointing in the direction of a and multiplied by VELOCITY_BOOST vy = vl * VELOCITY_BOOST * floatcos(-a, degrees); SetVehicleVelocity(GetPlayerVehicleID(playerid), vx, vy, vz); vz remains untouched but you can also multiply it by VELOCITY_BOOST if you want to. You can also leave away the vl calculation but that will make the speed boost always have the same strength. I personally prefer stronger boosts at higher speeds. |