[Help] Simple Speed Boost when you press KEY_FIRE
#1

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.
Reply
#2

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

Reply
#3

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.
Reply
#4

What is on line 1391?
Reply
#5

} while(x<200 && y<200 && z<200);
Reply
#6

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

adding spaces will help?

I'll still get the same error.
Reply
#8

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!)
Reply
#9

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
Reply
#10

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

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.
Reply
#12

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

to much boost how to make it smaller
Reply
#14

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.
Reply
#15

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;
}
Reply
#16

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.
Reply
#17

thank you!!
Reply
#18

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)