OnPlayerEnterVehicle
#1

Hi, I don't know what's problem but it seems that normal players can drive and get in some faction-restricted vehicles.
So , I put all these codes here. Please check them out and if you can , reply. thanks.
OnPlayerEnterVehicle Code :
PHP Code:
public OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    new 
Float:xFloat:yFloat:z;
    if(
GetPlayerSurfingVehicleID(playerid) == vehicleid)
    {
        new 
Float:hp;
        
GetPlayerHealth(playerid,hp);
           
GetPlayerPos(playeridxyz);
        if(!
PlayerInfo[playerid][pMask]) format(stringsizeof(string), "* %s slipped off the top of the vehicle and fell."PlayerRPName(playerid));
        else 
format(stringsizeof(string), "* Gharibe slipped off the top of the vehicle and fell.");
        
ProxDetector(30.0playeridstringCOLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
        
SetPlayerPos(playeridx+3y+3z+1);
        
SetPlayerHealth(playerid,hp-3);
        
PlayerPlaySound(playerid11300.00.00.0);
        
LoopingAnim(playerid,"PED","BIKE_fallR",4.0,0,1,1,1,0);
    }
    if(!
ispassenger)
    {
        else if(
IsACopCar(vehicleid))
        {
            if(!
IsACop(playerid))
            {
                
displayCenterHUDInfo(playerid,  "You are not a member of the~n~~b~LSPD/FBI/SAST~w~."8);
                
PlayerPlaySound(playerid10580.00.00.0);
                
ClearAnimations(playerid);
            }
        }
    else if(
PlayerTied[playerid] != 0) { ClearAnimations(playerid); }
    else if(
PlayerCuffed[playerid] != 0) { ClearAnimations(playerid); }
    else if(
PlayerFrozen[playerid] != 0) { ClearAnimations(playerid); }
    else if(
RapidResKitActive[playerid] != 0) { ClearAnimations(playerid); }
    else if(
PlayerJustDied[playerid] != 0) { ClearAnimations(playerid); }
    return 
1;

* I've deleted some codes (Other Factions Codes)
IsACop Code :
PHP Code:
stock IsACop(playerid)
{
    if(
IsPlayerConnected(playerid))
    {
        new 
leader PlayerInfo[playerid][pLeader];
        new 
member PlayerInfo[playerid][pMember];
        if(
member==|| member==|| member==3)
        {
            return 
1;
        }
        else if(
leader==|| leader==|| leader==3)
        {
            return 
1;
        }
        else if(
IsAnAgent(playerid))
        {
            return 
1;
        }
    }
    return 
0;

IsACopCar Code :
PHP Code:
stock IsACopCar(vehicleid)
{
    for(new 
ii<50i++)
    {
        if(
vehicleid == FacInfo[1][fCars][i])return 1;
    }
    return 
0;

* There's too many cars that defined like this : (FacInfo[1] ; 1 Is LSPD)
FacInfo[1][fCars][1] = CreateVehicle ...


I'll +Rep for the best answer.

And also it's about 2 month that I'm dealing with this problem.
Reply
#2

Use OnPlayerStateChange, instead, with your codes

pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
    {
    }
}
Reply
#3

Hey

Change this
Code:
else if(IsACopCar(vehicleid))
{
            if(IsACop(playerid))
            {
            //other codes
             }
}
To

Code:
else if(!IsACopCar(vehicleid))
{
           if(IsACop(playerid))
           {
             //other codes
            }
}
Because when you use
! It is true
If you don't use it is false , so if he is not a cop then

Code:
if(IsACop(playerid))
And if he is a cop

Code:
if(!IsACop(playerid))
If you understand what I say.. good day
Reply
#4

You mean like this?
PHP Code:
else if(!IsACopCar(vehicleid))
        {
            if(!
IsACop(playerid))
            {
                
displayCenterHUDInfo(playerid,  "You are not a member of the~n~~b~LSPD/FBI/SAST~w~."8); //display for 8 seconds
                
PlayerPlaySound(playerid10580.00.00.0);
                
ClearAnimations(playerid);
            }
        } 
Reply
#5

Code:
else if(!IsACopCar(vehicleid))
{
         if(IsACop(playerid)
        {
         //if he he not a cop your codes
         }
}
If he is a cop then if(!IsACop(playerid)
Use this ! When he is something , and don't use it when he is not
Reply
#6

It didn't work.
Reply
#7

Pm me your whole code I will make and send you tomorrow
Reply
#8

What are you talking about Cruse? The exclamation mark represents a false or negative value.

if(!variable)
Means 'variable' is either 0 or less, or is false.

if(variable)
Means 'variable' is greater than 0, or true.

You have everything in reverse...
Reply
#9

Quote:
Originally Posted by Threshold
View Post
What are you talking about Cruse? The exclamation mark represents a false or negative value.

if(!variable)
Means 'variable' is either 0 or less, or is false.

if(variable)
Means 'variable' is greater than 0, or true.

You have everything in reverse...
I don't know Threshold but can you check IsACop? Returns won't change !'s?
Reply
#10

Your code seems correct. Do you get the "you are not a member of..." message?

If you do, then OnPlayerEnterVehicle and ClearAnimations is not a good combination for players with reasonable lag. I'd try alternative methods such as OnPlayerStateChange and SetVehicleParams to lock vehicle doors.

EDIT: oh and change 'else if(IsCopCar' to just 'if(IsCopCar'
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)