DAMN IT DOESN'T WORK PROPERLY!
#1

Hey,

I have this code right down bellow:

OnPlayerKeyStageChange
Код:
 if(((newkeys & KEY_FIRE) == (KEY_FIRE)) && (GetPlayerState(playerid) == 2))
	{
  if(IsPlayerInAnyVehicle(playerid))
  SetVehicleVelocity(GetPlayerVehicleID(playerid), 0.0, 1.0, 0.0);
	}
This means when I press the FIRE button while driving a vehicle, my vehicle gets a speed boost. BUT when I press FIRE my vehicle doesn't go forward, but blasts itself to the north. So my question = How to make this work that when I press FIRE it gives a boost to the angle where the vehicle is driving and not always the north.

sorry for my extremely bad english I am still a student LOL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Reply
#2

Код:
if(newkeys== KEY_FIRE && GetPlayerState(playerid) == 2))
	{
  if(IsPlayerInAnyVehicle(playerid))
  SetVehicleVelocity(GetPlayerVehicleID(playerid), 0.0, 1.0, 0.0);
	}
Reply
#3

Add this somewhere in your script...

pawn Код:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    GetPlayerFacingAngle(playerid, a);
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}
...and then...

pawn Код:
if((newkeys & KEY_FIRE) && (GetPlayerState(playerid) == 2))
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    GetXYInFrontOfPlayer(playerid, x, y, 1.0);
    SetVehicleVelocity(GetPlayerVehicleID(playerid), x, y, 0.0);
}
You don't need to check IsPlayerInAnyVehicle because GetPlayerState already does that.
Reply
#4

use GetVehicleVelocity, and then do something similar to this

pawn Код:
SetVelocityForward(playerid, Float:multi)
{
if (IsPlayerInAnyVehicle(playerid))
{
new Float:angle, Float:velox, Float:veloy;
GetPlayerFacingAngle(playerid, angle);
velox = multi * floatsin(angle, degrees);
veloy = multi * floatcos(angle, degrees);
SetVehicleVelocity(GetPlayerVehicleID(playerid), velox, veloy, 0.01);
}
return 1;
}
@MadeMan, you are confusing velocities with coords.
Reply
#5

Yes, my mistake.
Reply
#6

Ok, guys thanks, but what is the code I have to fill in and where?
Reply
#7

No one?
Reply
#8

pawn Код:
if((newkeys & KEY_FIRE) && (GetPlayerState(playerid) == 2))
{
    SetVelocityForward(playerid, 1.0);
}
You must also add the SetVelocityForward function to your script

pawn Код:
SetVelocityForward(playerid, Float:multi)
{
    if (IsPlayerInAnyVehicle(playerid))
    {
        new Float:angle, Float:velox, Float:veloy;
        GetVehicleZAngle(GetPlayerVehicleID(playerid), angle);
        velox = multi * floatsin(-angle, degrees);
        veloy = multi * floatcos(-angle, degrees);
        SetVehicleVelocity(GetPlayerVehicleID(playerid), velox, veloy, 0.01);
    }
    return 1;
}
Reply
#9

Great I get no errors. Now I am going to test it
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)