SA-MP Forums Archive
DAMN IT DOESN'T WORK PROPERLY! - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: DAMN IT DOESN'T WORK PROPERLY! (/showthread.php?tid=122208)



DAMN IT DOESN'T WORK PROPERLY! - stieben - 20.01.2010

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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Re: DAMN IT DOESN'T WORK PROPERLY! - timmehhh - 20.01.2010

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



Re: DAMN IT DOESN'T WORK PROPERLY! - MadeMan - 20.01.2010

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.


Re: DAMN IT DOESN'T WORK PROPERLY! - Daren_Jacobson - 20.01.2010

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.


Re: DAMN IT DOESN'T WORK PROPERLY! - MadeMan - 20.01.2010

Yes, my mistake.


Re: DAMN IT DOESN'T WORK PROPERLY! - stieben - 21.01.2010

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


Re: DAMN IT DOESN'T WORK PROPERLY! - stieben - 21.01.2010

No one?


Re: DAMN IT DOESN'T WORK PROPERLY! - MadeMan - 21.01.2010

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;
}



Re: DAMN IT DOESN'T WORK PROPERLY! - stieben - 22.01.2010

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