SA-MP Forums Archive
[Help] Simple Speed Boost when you press KEY_FIRE - 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: [Help] Simple Speed Boost when you press KEY_FIRE (/showthread.php?tid=154175)



[Help] Simple Speed Boost when you press KEY_FIRE - Toni - 12.06.2010

Hello, I was just wondering..how do you create a speed boost on key_fire?

I've tried it with SetPlayerVelocity -- GetPlayerVelocity but I can't figure it out. Please help heh.


Re: [Help] Simple Speed Boost when you press KEY_FIRE - DJDhan - 12.06.2010

At the top somewhere:

Code:
#define HOLDING(%0) \
	((newkeys & (%0)) == (%0))
Code:
OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
{
  if(IsPlayerInAnyVehicle(playerid))
  {
      
    if (HOLDING( KEY_FIRE ))
    {
       do
        {
        new Float:x,Float:y,Float:z,vehid; vehid=GetPlayerVehicleID(playerid);
        GetVehicleVelocity(vehid,x,y,z); 
        SetVehicleVelocity(vehid,x+30,y+30,z+30);
        } while(x<200 && y<200 && z<200);
    }
  }
  return 1;
}




Re: [Help] Simple Speed Boost when you press KEY_FIRE - Toni - 12.06.2010

pawn Code:
C:\xxx\xxx\xxx\Party For Life!\gamemodes\party.pwn(1391) : error 017: undefined symbol "x"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Error.



Re: [Help] Simple Speed Boost when you press KEY_FIRE - TheInnocentOne - 12.06.2010

What is on line 1391?


Re: [Help] Simple Speed Boost when you press KEY_FIRE - Toni - 12.06.2010

} while(x<200 && y<200 && z<200);


Re: [Help] Simple Speed Boost when you press KEY_FIRE - TheInnocentOne - 12.06.2010

pawn Code:
} while(x < 200 && y < 200 && z < 200);



Re: [Help] Simple Speed Boost when you press KEY_FIRE - Toni - 12.06.2010

adding spaces will help?

I'll still get the same error.


Re: [Help] Simple Speed Boost when you press KEY_FIRE - Simon - 12.06.2010

Quote:
Originally Posted by DJDhan
At the top somewhere:
Code:
// snip
Code:
// snip
[*] Velocities need to keep their sign for direction. If you add onto a velocity you're going to slow the vehicle down if the velocity was for example -30.0 (-30 + 30 = 0, stopped completely!)[*] You have an infinite loop. There is absolutely no assignment in your code, if the velocities were all < 200 to start with then the code would never stop executing.[*] You're getting the above error because you defined your check variables inside the loop. The loop check is not in the same scope as the variable creation.

pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
  if(IsPlayerInAnyVehicle(playerid))
  {
     
    if (newkeys & KEY_FIRE)
    {
        new
          Float:x, Float:y, Float:z, vehid;

        vehid = GetPlayerVehicleID(playerid);


        GetVehicleVelocity(vehid,x, y, z);

        if (x >= 0.0) x += 30.0;
        else x -= 30.0;


        if (y >= 0.0) y += 30.0;
        else y -= 30.0;


        if (z >= 0.0) z += 30.0;
        else z -= 30.0;

        SetVehicleVelocity(vehid, x, y, z);
    }
  }

  return 1;
}
You may want to remove the addition/subtraction of z. If you don't remove it you will get a falling boost/rise also (allowing people to defy gravity!)


Re: [Help] Simple Speed Boost when you press KEY_FIRE - Toni - 12.06.2010

nothing wrong now Simon! Thakns


But now I tested it. My results (in coords)

Start Pos. -> X = 0 | Y = 0 | Z = 1.2

After 3 secs of clicking LMB. -> X = 1327.89 | Y = 1321.83 | Z = 1161.80


Heh. Over power much? lol


Re: [Help] Simple Speed Boost when you press KEY_FIRE - Simon - 13.06.2010

Hah, I kinda suspected that. You'll probably want to change the 30.0 to something like 1.0-5.0 then


Re: [Help] Simple Speed Boost when you press KEY_FIRE - nemesis- - 13.06.2010

Quote:
Originally Posted by Simon
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
  if(IsPlayerInAnyVehicle(playerid))
  {
That will allow you to speedboost even if you are a passenger in a vehicle. Swap IsPlayerInAnyVehicle with if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER). That will ensure only the vehicle's driver can speedboost.


Re: [Help] Simple Speed Boost when you press KEY_FIRE - Bcklup - 13.06.2010

I have a simple sys like this in my GM but its a little different, I use GetXYForwardVelocity(i edited GetXYInFrontOfPlayer)


Re: [Help] Simple Speed Boost when you press KEY_FIRE - Kar - 13.06.2010

to much boost how to make it smaller


Re: [Help] Simple Speed Boost when you press KEY_FIRE - DJDhan - 13.06.2010

I added the do-while loop so that the velocity remain below 200 and you don't reach the speed of light when you use the boost.


Re: [Help] Simple Speed Boost when you press KEY_FIRE - MadeMan - 13.06.2010

Quote:
Originally Posted by DJDhan
I added the do-while loop so that the velocity remain below 200 and you don't reach the speed of light when you use the boost.
Velocity of 200 is already very close to speed of light

You can also try this:

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        if(newkeys & KEY_FIRE)
        {
            new vehicleid = GetPlayerVehicleID(playerid);
            new Float:angle;
            GetVehicleZAngle(vehicleid, angle);

            new Float:velox, Float:veloy, Float:veloz;
            GetVehicleVelocity(vehicleid, velox, veloy, veloz);

            velox += floatsin(-angle, degrees);
            veloy += floatcos(-angle, degrees);
            SetVehicleVelocity(vehicleid, velox, veloy, veloz);
        }
    }
    return 1;
}



Re: [Help] Simple Speed Boost when you press KEY_FIRE - Toni - 13.06.2010

Quote:
Originally Posted by MadeMan
Quote:
Originally Posted by DJDhan
I added the do-while loop so that the velocity remain below 200 and you don't reach the speed of light when you use the boost.
Velocity of 200 is already very close to speed of light

You can also try this:

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        if(newkeys & KEY_FIRE)
        {
            new vehicleid = GetPlayerVehicleID(playerid);
            new Float:angle;
            GetVehicleZAngle(vehicleid, angle);

            new Float:velox, Float:veloy, Float:veloz;
            GetVehicleVelocity(vehicleid, velox, veloy, veloz);

            velox += floatsin(-angle, degrees);
            veloy += floatcos(-angle, degrees);
            SetVehicleVelocity(vehicleid, velox, veloy, veloz);
        }
    }
    return 1;
}
Thanks I'll try that.


Re: [Help] Simple Speed Boost when you press KEY_FIRE - samp03c - 26.12.2010

thank you!!


Re: [Help] Simple Speed Boost when you press KEY_FIRE - Gotti_ - 10.03.2011

can anyone make this speed boost can activate and deactivate on command pls


Re: [Help] Simple Speed Boost when you press KEY_FIRE - HyperZ - 10.03.2011

Quote:
Originally Posted by Gotti_
Посмотреть сообщение
can anyone make this speed boost can activate and deactivate on command pls
Check this: https://sampforum.blast.hk/showthread.php?tid=95064