Interesting possible bug with GetPlayerPos and GetVehiclePos
#1

I'm trying to develop a bunnyhop button for motorbikes, and my code looks like this:
pawn Код:
if((newkeys & 2048) && !(oldkeys & 2048)) //thats the special/turret up button, for motorbike bunnyhop
      {
        new vehicleid = GetPlayerVehicleID(playerid);
            new modelid = GetVehicleModel(vehicleid);
            if((modelid == 521) || (modelid == 522) || (modelid == 448) || (modelid == 523) || (modelid == 586) || (modelid == 581) || (modelid == 468) || (modelid == 463) || (modelid == 432) || (modelid == 431) || (modelid == 462))
            {
                new Float:posx, Float:posy, Float:posz;
                GetPlayerPos(playerid,posx,posy,posz);
                new Float:debugZ = MapAndreas_FindZ_For2DCoord(posx,posy,posz);//debug
                printf("Current Pos: %f X, %f Y, %f Z",posx,posy,posz);//debug
                printf("Map andreas co ord: %f Z",debugZ);//debug
              if(MapAndreas_FindZ_For2DCoord(posx,posy,posz) == posz)
              {
              new Float:x, Float:y, Float:z;
                  GetVehicleVelocity(vehicleid,x,y,z);
                  SetVehicleVelocity(vehicleid,x,y,z+0.2);
                  return 1;
                }
                return 1;
            }
        }
I noticed that the code never worked until I took out the MapAndreas_FindZ_For2DCoord line. At first I thought it was because the coord given by it wasn't EXACTLY the same as my ACTUAL position.

I also noticed that the messages I got in the console always gave me the same Z co-ord, regardless of how high i was above the ground. I set my height to 30000 over the abandoned airfield and got a Z co-ord of 27. This made Map Andreas ALWAYS return 1 as the z co-ord. I also tried to go above water, but that sent a console message telling me my Z co-ord was 0. It was trying to tell me that being 30000 units above the water had a Z co-ord of 0. :O

So I'm thinking that GetPlayerPos and GetVehiclePos BOTH get the height of the ground below you, NOT your ACTUAL height. Could I ask for someone to test my theory please?
Reply
#2

I see that you've fixed this but if it does happen again try:

Код:
public OnPlayerSpawn(playerid)
{
  SetPlayerColor(playerid, 0xC9C9C9);
  return 1;
}
Even though it is when the player spawns, will it make much difference?
Reply
#3

This is not how you use MapAndreas_FindZ_For2DCoord:
pawn Код:
new Float:debugZ = MapAndreas_FindZ_For2DCoord(posx,posy,posz);
This is the correct way:
pawn Код:
new Float:debugZ;
MapAndreas_FindZ_For2DCoord(posx, posy, debugZ);
Your whole code fixed & should be working:
pawn Код:
if((newkeys & 2048) && !(oldkeys & 2048)) //thats the special/turret up button, for motorbike bunnyhop
{
  new vehicleid = GetPlayerVehicleID(playerid),
    modelid = GetVehicleModel(vehicleid);

  if((modelid == 521) || (modelid == 522) || (modelid == 448) || (modelid == 523) || (modelid == 586) || (modelid == 581) || (modelid == 468) || (modelid == 463) || (modelid == 432) || (modelid == 431) || (modelid == 462))
  {
    new Float:posx, Float:posy, Float:posz, Float:debugZ;

    GetPlayerPos(playerid, posx, posy, posz);
    MapAndreas_FindZ_For2DCoord(posx, posy, debugZ);//debug

    printf("posx = %f posy = %f, posz = %f, debugZ = %f", posx, posy, posz, debugZ);//debug

    if(floatround(debugZ) == floatround(posz))
    {
      GetVehicleVelocity(vehicleid, posx, posy, posz);
      SetVehicleVelocity(vehicleid, posx, posy, (posz + 0.2));
    }

    return 1;
  }
}
Reply
#4

Quote:
Originally Posted by Rattertouille
I see that you've fixed this but if it does happen again try:

Код:
public OnPlayerSpawn(playerid)
{
  SetPlayerColor(playerid, 0xC9C9C9);
  return 1;
}
Even though it is when the player spawns, will it make much difference?
Wrong post?

Thanks Finn. That works fine untill I go onto a ramp or something, but that doesn't belong in this post. No longer a bug , mods please close.
Reply
#5

Woops, sorry was ment to post that here: http://forum.sa-mp.com/index.php?topic=156692.0
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)