[help] Vehicle check script doesn't work
#1

I used OnPlayerStateChange, it works.
But there's still a problem.

This code:
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(GetVehicleModel(vehicleid)==596) //PD Car
{
SendClientMessage(playerid, COLOR_BLUE, "You entered 'LSPD' Car from 'Los Santos Police Department'");
}
else
{
SendClientMessage(playerid, COLOR_RED, "Only cops on duty can drive this vehicle!");
RemovePlayerFromVehicle(playerid);
//return 0;
         }
    }
}
Works on all vehicles, I mean, it checks every vehicle I have on the server. It should only check car ID 596. How do I resolve this?
Reply
#2

Hmm try to add some think like new pdcar; then creat the vehicle witht his variable pdcar = creatvehicleblabla also you are not using the playerid''
pawn Код:
IsPlayerInVehicle(playerid,(pdcar));
            {
                    //put code here..
            }
                else
                {
                     SendClientMessage(playerid, COLOR_LIGHTBLUE, "You cant drive this vehicle!");
                }
Reply
#3

I used OnPlayerStateChange, it works.
But there's still a problem.

This code:
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(GetVehicleModel(vehicleid)==596) //PD Car
{
SendClientMessage(playerid, COLOR_BLUE, "You entered 'LSPD' Car from 'Los Santos Police Department'");
}
else
{
SendClientMessage(playerid, COLOR_RED, "Only cops on duty can drive this vehicle!");
RemovePlayerFromVehicle(playerid);
//return 0;
         }
    }
}
Works on all vehicles, I mean, it checks every vehicle I have on the server. It should only check car ID 596. How do I resolve this?
Reply
#4

This might work
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(newstate == PLAYER_STATE_DRIVER && GetVehicleModel(vehicleid)==596)//check if its cop car here too
    {
        if(GetVehicleModel(vehicleid)==596) //PD Car
        {
            SendClientMessage(playerid, COLOR_BLUE, "You entered 'LSPD' Car from 'Los Santos Police Department'");
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "Only cops on duty can drive this vehicle!");
            RemovePlayerFromVehicle(playerid);
        }
    }
    return 1;//i think state change is supposed to return 1 to work properly too (Not Positive).
}
EDIT: Heres a better version that actually checks if a player is a cop

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(newstate == PLAYER_STATE_DRIVER && GetVehicleModel(vehicleid)==596)//check if its cop car hee too
    {
        if(pTeam[playerid] == TEAM_COPS) //or use GetPlayerTeam if you have used teams
        {                               //or even GetPlayerSkin depending on your system.
            SendClientMessage(playerid, COLOR_BLUE, "You entered 'LSPD' Car from 'Los Santos Police Department'");
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "Only cops on duty can drive this vehicle!");
            RemovePlayerFromVehicle(playerid);
        }
    }
    return 1;
}
Reply
#5

Probably, I think I messed it up again with my jobs.

Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(newstate == PLAYER_STATE_DRIVER && GetVehicleModel(vehicleid)==596)//check if its cop car here too
{
if(GetVehicleModel(vehicleid)==596) //PD Car
{
 if(job[playerid] == 1 && job[playerid] == 2 || job[playerid] == 3 && job[playerid] == 4 || job[playerid] == 5 && job[playerid] == 6 || job[playerid] == 7 && job[playerid] == 8)
SendClientMessage(playerid, COLOR_BLUE, "You entered 'LSPD' Car from 'Los Santos Police Department'");
}
else
{
SendClientMessage(playerid, COLOR_RED, "Only cops on duty can drive this vehicle!");
RemovePlayerFromVehicle(playerid);
}
}
return 0;
}
Reply
#6

pawn Код:
if(job[playerid] == 1 && job[playerid] == 2 || job[playerid] == 3 && job[playerid] == 4 || job[playerid] == 5 && job[playerid] == 6 || job[playerid] == 7 && job[playerid] == 8)
Won't work job[playerid] cant be 2 values at the same time.
For instance
pawn Код:
if(job[playerid] == 1 && job[playerid] == 2
What your asking there is if 'job[playerid]' holds 1 and 2 at the same time. Which is impossible.

Change to
pawn Код:
if(job[playerid] == 1 || job[playerid] == 2 || job[playerid] == 3 || job[playerid] == 4 || job[playerid] == 5 || job[playerid] == 6 || job[playerid] == 7 || job[playerid] == 8)
Reply
#7

Well, I'm not really familair with pteam and gteam, so I think I'll try to find an other way or learn that quickly
I know how to add the pTeam, but I have no idea how to add all these jobs in that team.
I have 8 Job IDs (1- for police, I have no idea how to enter that in a PTeam
Thank you.
Reply
#8

Try this
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(newstate == PLAYER_STATE_DRIVER && GetVehicleModel(vehicleid)==596)//check if its cop car hee too
    {
        if(job[playerid] == 1 || job[playerid] == 2 || job[playerid] == 3 || job[playerid] == 4 || job[playerid] == 5 || job[playerid] == 6 || job[playerid] == 7 || job[playerid] == 8)
        {
            SendClientMessage(playerid, COLOR_BLUE, "You entered 'LSPD' Car from 'Los Santos Police Department'");
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "Only cops on duty can drive this vehicle!");
            RemovePlayerFromVehicle(playerid);
        }
    }
    return 1;
}
It would help if you told me which job is actually the cops.
Reply
#9

You're great!
Thanks.
Reply
#10

Your welcome glad to help
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)