SA-MP Forums Archive
trying to do IsPlayerOnVehicle - 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)
+--- Thread: trying to do IsPlayerOnVehicle (/showthread.php?tid=676033)



trying to do IsPlayerOnVehicle - ChampDotChamp - 27.05.2020

Does anyone know how i can detect if player is standing on vehicle. Not surfing, only standing


Re: trying to do IsPlayerOnVehicle - xRadical3 - 27.05.2020

Check this thread: https://sampforum.blast.hk/showthread.php?tid=453546
I think this impossible, What do you want to do?


Re: trying to do IsPlayerOnVehicle - ChampDotChamp - 27.05.2020

Quote:
Originally Posted by xRadical3
View Post
Check this thread: https://sampforum.blast.hk/showthread.php?tid=453546
I think this impossible, What do you want to do?
There is a SA:MP bug when you teleport to random location and players that are standing on your vehicle will teleport with you.


Re: trying to do IsPlayerOnVehicle - Runn3R - 27.05.2020

Alternatively, you can use the SAMap plugin to retrieve the Z position (if the player is on the ground) and do it like that?


Re: trying to do IsPlayerOnVehicle - xRadical3 - 27.05.2020

Quote:
Originally Posted by ChampDotChamp
View Post
There is a SA:MP bug when you teleport to random location and players that are standing on your vehicle will teleport with you.
Maybe this method will help, I have no other idea.

1) Check if the player is in the vehicle.
2) If he is in a vehicle, save the model and coordinates then destroy the vehicle.
3) Create the vehicle after the player is teleported.
4) Put the player in the vehicle as driver.
That way, players are standing on vehicle won't teleport with driver.


Re: trying to do IsPlayerOnVehicle - ChampDotChamp - 28.05.2020

Quote:
Originally Posted by Runn3R
View Post
Alternatively, you can use the SAMap plugin to retrieve the Z position (if the player is on the ground) and do it like that?
But that has nothing to do with teleport ?

Quote:
Originally Posted by xRadical3
View Post
Maybe this method will help, I have no other idea.

1) Check if the player is in the vehicle.
2) If he is in a vehicle, save the model and coordinates then destroy the vehicle.
3) Create the vehicle after the player is teleported.
4) Put the player in the vehicle as driver.
That way, players are standing on vehicle won't teleport with driver.
I think this method is not optimized, because it takes a little time to destroy, create and than put players.
Some servers have check like this function IsPlayerOnVehicle(..);


Re: trying to do IsPlayerOnVehicle - GameOvr - 28.05.2020

You have to use MapAndreas include by Ryder to get this in the working state..
pawn Code:
#include <mapandreas>

new jumping[MAX_PLAYERS];

native IsValidVehicle(vehicleid);

#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
       if (PRESSED(KEY_JUMP))
       {
              jumping[playerid] = 1;
              SetTimerEx(JumpTimer, 1500, 0, "i", playerid);
       }
       return 1;
}

forward JumpTimer(playerid);
public JumpTimer(playerid)
{
     jumping[playerid] = 0;
     return 1;
}

stock IsPlayerOnVehicle(playerid) // By GameOvr, just made for you :D
{
       if(IsPlayerInAnyVehicle(playerid)) return 0;
       new Float:x, Float:y, Float:z, Float:px, Float:py, Float:pz, Float:Zval;
       GetPlayerPos(playerid, px, py, pz);
       for(new i = 0; i < MAX_VEHICLES; i++)
       {
              if(IsValidVehicle(i))
              {
                       GetVehiclePos(i, x, y, z);
                       if(IsPlayerInRangeOfPoint(playerid, x, y, z, 2) && !jumping[playerid])
                       {
                                GetPointZPos(px, py, Zval);
                                if(pz > Zval) return 1;
                       }
               }
      }
      return 0;
}
EDIT:I didnt test it or compile, if it's not working tell me


Re: trying to do IsPlayerOnVehicle - ChampDotChamp - 28.05.2020

Quote:
Originally Posted by GameOvr
View Post
You have to use MapAndreas include by Ryder to get this in the working state..
EDIT:I didnt test it or compile, if it's not working tell me
I changed your code because you had some mistakes. But, no help

pawn Code:
stock IsPlayerOnVehicle(playerid) // By GameOvr, just made for you :D
{
    if(IsPlayerInAnyVehicle(playerid)) return INVALID_VEHICLE_ID;

    new Float:x, Float:y, Float:z, Float:px, Float:py, Float:pz, Float:Zval;
    GetPlayerPos(playerid, px, py, pz);

    foreach(new i : Vehicle)
    {
        GetVehiclePos(i, x, y, z);
        if(IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z) && jumping[playerid] == 0)
        {
            MapAndreas_FindZ_For2DCoord(px, py, Zval);
            if(pz > Zval) return i;
        }      
    }

    return INVALID_VEHICLE_ID;
}