Help with seatbelt
#1

Hey,

I made a /sb command, but it have to put the player back in his vehicle if he exits the vehicle when he has his seatbelt on.

But it doesn't work..


this part is under:
pawn Code:
if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
pawn Code:
new string2[128];
        if(Player[playerid][Seatbelt] == 1)
        {
            format(string2, sizeof(string2), "~w~You are still ~r~buckled up");
            GameTextForPlayer(playerid, string2, 5000, 3);
            new playercar = GetPlayerVehicleID(playerid);
            new playerseat = GetPlayerVehicleSeat(playerid);
            PutPlayerInVehicle(playerid, playercar, playerseat);
        }
and this part is under:
pawn Code:
if(oldstate == PLAYER_STATE_PASSENGER && newstate == PLAYER_STATE_ONFOOT)
pawn Code:
new string3[128];
        if(Player[playerid][Seatbelt] == 1)
        {
            format(string3, sizeof(string3), "~w~You are still ~r~buckled up");
            GameTextForPlayer(playerid, string3, 5000, 3);
            new playercar1 = GetPlayerVehicleID(playerid);
            new playerseat1 = GetPlayerVehicleSeat(playerid);
            PutPlayerInVehicle(playerid, playercar1, playerseat1);
        }
Reply
#2

Anyone?
Reply
#3

Bumping only allowed after 48 hours.
Reply
#4

Sorry didn't know, but it just suck if you wanna compete your script
Reply
#5

The problem is playercar1 needs to be a global variable and it needs to be set when the player is in the vehicle, currently you're assigning playercar1 to the players current vehicle WHILE not in a vehicle.
Reply
#6

How to make it that, he puts the player back in the last vehicle then?
Reply
#7

is there something like "Getplayerlastvehicleid"
Reply
#8

Quote:
Originally Posted by JhnzRep
View Post
Bumping only allowed after 48 hours.
and No their is no such function,


you have to make it like stated above

pawn Code:
gLastVeh[MAX_PLAYERS];


public OnPlayerEnterVehicle(playerid , vehicleid)
{
gLastVeh[playerid] = vehicleid;

...
Reply
#9

Oke, I made this:

pawn Code:
new GetPlayerLastVehicleID[MAX_PLAYERS];
pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    GetPlayerLastVehicleID[playerid] = vehicleid;
    return 1;
}
But how to do that with the vehicle seat?
Reply
#10

if its for drive then the seat is 0

off to work
Reply
#11

Oke now I did what you told me to,

pawn Code:
new GetPlayerLastVehicleID[MAX_PLAYERS];
new GetPlayerLastSeat[MAX_PLAYERS];
pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    GetPlayerLastVehicleID[playerid] = GetPlayerVehicleID(playerid);
    GetPlayerLastSeat[playerid] = GetPlayerVehicleSeat(playerid);
    return 1;
}
pawn Code:
new string2[128];
        if(Player[playerid][Seatbelt] >= 1)
        {
            new playercar = GetPlayerLastVehicleID[playerid];
            new playerseat = GetPlayerLastSeat[playerid];
            PutPlayerInVehicle(playerid, playercar, playerseat);
            format(string2, sizeof(string2), "~w~You are still ~r~buckled up");
            GameTextForPlayer(playerid, string2, 5000, 3);
        }
pawn Code:
new string3[128];
        if(Player[playerid][Seatbelt] >= 1)
        {
            new playercar1 = GetPlayerLastVehicleID[playerid];
            new playerseat1 = GetPlayerLastSeat[playerid];
            PutPlayerInVehicle(playerid, playercar1, playerseat1);
            format(string3, sizeof(string3), "~w~You are still ~r~buckled up");
            GameTextForPlayer(playerid, string3, 5000, 3);
        }
And still not working...
Reply
#12

Can't you just use it under OnPlayerKeyStateChange?
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys == KEY_SECONDARY_ATTACK)
    {
        if(Player[playerid][Seatbelt] == 1)
        {
            //..........
        }
    }
    return 1;
}
Reply
#13

its under "OnPlayerStateChange"
Reply
#14

anyone?
Reply
#15

Show your /sb command.
Reply
#16

pawn Code:
command(sb, playerid, params[])
{
    new string[128];
    if(IsPlayerInAnyVehicle(playerid))
    if(Player[playerid][Seatbelt] == 0)
    {
        format(string, sizeof(string), "* %s has buckled up his seatbelt.", GetName(playerid));
        NearByMessage(playerid, NICESKY, string);
        Player[playerid][Seatbelt] = 1;
    }
    else
    if(Player[playerid][Seatbelt] == 1)
    {
        format(string, sizeof(string), "* %s has unbuckle his seatbelt.", GetName(playerid));
        NearByMessage(playerid, NICESKY, string);
        Player[playerid][Seatbelt] = 0;
    }
    return 1;
}
Reply
#17

Try this:
pawn Code:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(Player[playerid][Seatbelt] = 1)
    {
        playerseat = GetPlayerVehicleSeat(playerid);
        PutPlayerInVehicle(playerid, playercar, playerseat);
        SendClientMessage(playerid, NICESKY, "Unbuckle first!);
    }
    return 1;
}
Reply
#18

still not..
Reply
#19

Just a suggestion, click here.
It'll do the job?

Jesse
Reply
#20

You have to use OnPlayerExitVehicle, and OnPlayerState, it only gets called when a player is actually out of the car, at which point he has no vehicle ID. That's what I think is causing your code not to work.

Under OnPlayerEnterVehicle, you get the seat id and store it into a global variable. Then on OnPlayerExitVehicle you put them back in the same vehicle with that global var that holds the seat id.

pawn Code:
new
    // at the top of your script
     gSeatID[MAX_PLAYERS]; // a global var for the seat ID

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    // if either they entered as a passenger or driver
    // adjust their seat it
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        gSeatID[playerid] = GetPlayerVehicleSeat(playerid);
    }
    return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(Player[playerid][Seatbelt] = 1)
    {
        // so if the player exits the vehicle
        // and they're still buckled up
        // you put them back in the vehicle
        // in their global seat ID
        PutPlayerInVehicle(playerid, vehicleid, gSeatID[playerid]);
        /*
         *  You would put the code that notifies the player
         *  that they are not unbuckled yet.
         *
         */

        return 1;
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)