SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   trying to do IsPlayerOnVehicle (https://forum.sa-mp.com/showthread.php?t=676033)

ChampDotChamp 27/05/2020 09:26 PM

trying to do IsPlayerOnVehicle
 
Does anyone know how i can detect if player is standing on vehicle. Not surfing, only standing :p

xRadical3 27/05/2020 10:00 PM

Re: trying to do IsPlayerOnVehicle
 
Check this thread: https://forum.sa-mp.com/showthread.php?t=453546
I think this impossible, What do you want to do?

ChampDotChamp 27/05/2020 10:23 PM

Re: trying to do IsPlayerOnVehicle
 
Quote:

Originally Posted by xRadical3 (Post 4148353)
Check this thread: https://forum.sa-mp.com/showthread.php?t=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.

Runn3R 27/05/2020 10:32 PM

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

xRadical3 27/05/2020 10:55 PM

Re: trying to do IsPlayerOnVehicle
 
Quote:

Originally Posted by ChampDotChamp (Post 4148356)
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.

ChampDotChamp 28/05/2020 08:58 AM

Re: trying to do IsPlayerOnVehicle
 
Quote:

Originally Posted by Runn3R (Post 4148359)
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 (Post 4148363)
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(..);

GameOvr 28/05/2020 10:01 AM

Re: trying to do IsPlayerOnVehicle
 
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

ChampDotChamp 28/05/2020 01:39 PM

Re: trying to do IsPlayerOnVehicle
 
Quote:

Originally Posted by GameOvr (Post 4148411)
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;
}


All times are GMT. The time now is 05:09 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.