SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 27/05/2020, 09:26 PM   #1
ChampDotChamp
Little Clucker
 
Join Date: Apr 2020
Posts: 4
Reputation: 0
Default trying to do IsPlayerOnVehicle

Does anyone know how i can detect if player is standing on vehicle. Not surfing, only standing
ChampDotChamp is offline   Reply With Quote
Old 27/05/2020, 10:00 PM   #2
xRadical3
Gangsta
 
xRadical3's Avatar
 
Join Date: May 2017
Location: Iran
Posts: 558
Reputation: 20
Default 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?
xRadical3 is offline   Reply With Quote
Old 27/05/2020, 10:23 PM   #3
ChampDotChamp
Little Clucker
 
Join Date: Apr 2020
Posts: 4
Reputation: 0
Default Re: trying to do IsPlayerOnVehicle

Quote:
Originally Posted by xRadical3 View Post
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.
ChampDotChamp is offline   Reply With Quote
Old 27/05/2020, 10:32 PM   #4
Runn3R
Huge Clucker
 
Runn3R's Avatar
 
Join Date: Dec 2013
Location: Croatia, Split
Posts: 420
Reputation: 36
Default 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?
Runn3R is offline   Reply With Quote
Old 27/05/2020, 10:55 PM   #5
xRadical3
Gangsta
 
xRadical3's Avatar
 
Join Date: May 2017
Location: Iran
Posts: 558
Reputation: 20
Lightbulb Re: trying to do IsPlayerOnVehicle

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.
xRadical3 is offline   Reply With Quote
Old 28/05/2020, 08:58 AM   #6
ChampDotChamp
Little Clucker
 
Join Date: Apr 2020
Posts: 4
Reputation: 0
Default Re: trying to do IsPlayerOnVehicle

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(..);
ChampDotChamp is offline   Reply With Quote
Old 28/05/2020, 10:01 AM   #7
GameOvr
Huge Clucker
 
GameOvr's Avatar
 
Join Date: Jun 2018
Posts: 292
Reputation: 9
Default 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
__________________
GameOvr is offline   Reply With Quote
Old 28/05/2020, 01:39 PM   #8
ChampDotChamp
Little Clucker
 
Join Date: Apr 2020
Posts: 4
Reputation: 0
Default Re: trying to do IsPlayerOnVehicle

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;
}
ChampDotChamp is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 07:15 AM.


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