SA-MP Forums Archive
Question - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Question (/showthread.php?tid=529645)



Question - Lajko1 - 03.08.2014

I have one problem with OnPlayerStateChange.. I made seatbelt/helmet system but the problem is when player fall from bike it says "you have unbuckled your seatbelt" it should say "you removed safety helmet"... - this was when code was OnPlayerExitVehicle

Now I moved code OnPlayerStateChange and it won't even say that I removed my helmet when I go off the bike..
All I want to do is when player fall off the bike it should say that player removed safety helmet.

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{

    new string[256];
    new sendername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    new vehicleid = GetPlayerVehicleID(playerid);

    if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_EXIT_VEHICLE)
    {
        if(SeatBelt[playerid] == 1)
        {
            if(IsModelABike(vehicleid)) // Bike - helmet
            {
                SeatBelt[playerid] = 0;
                if(IsPlayerAttachedObjectSlotUsed(playerid, 1)) RemovePlayerAttachedObject(playerid, helmet[0]); // Removing his helmet
                if (Masked[playerid] == 1) format(string, sizeof(string), "*Stranger_%d removes the safety helmet.", maskid[playerid]);
                else format(string, sizeof(string), "*%s removes the safety helmet.", sendername);
                ProxDetector(8.0, playerid, string,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA);
                return 1;
            }
            else // SEATBELT
            {
                SeatBelt[playerid] = 0;
                if (Masked[playerid] == 1) format(string, sizeof(string), "*Stranger_%d unbuckles his seatbelt.", maskid[playerid]);
                else format(string, sizeof(string), "*%s unbuckles his seatbelt.", sendername);
                ProxDetector(8.0, playerid, string,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA);
            }
        }
    }



Re: Question - KayJ - 03.08.2014

I suggest put onfall bike code(helmet) in : OnPlayerExitVehicle


Re: Question - McBan - 03.08.2014

Код:
if(IsModelABike(vehicleid)) // Bike - helmet
            {
                SeatBelt[playerid] = 0;
                if(IsPlayerAttachedObjectSlotUsed(playerid, 1)) RemovePlayerAttachedObject(playerid, helmet[0]); // Removing his helmet
                if (Masked[playerid] == 1) format(string, sizeof(string), "*Stranger_%d removes the safety helmet.", maskid[playerid]);
                else format(string, sizeof(string), "*%s removes the safety helmet.", sendername);
                ProxDetector(8.0, playerid, string,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA);
                return 1;
            }
            else // SEATBELT
            {
                SeatBelt[playerid] = 0;
                if (Masked[playerid] == 1) format(string, sizeof(string), "*Stranger_%d unbuckles his seatbelt.", maskid[playerid]);
                else format(string, sizeof(string), "*%s unbuckles his seatbelt.", sendername);
                ProxDetector(8.0, playerid, string,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA);
            }
In

Код:
OnPlayerExitVehicle



Re: Question - Lajko1 - 03.08.2014

I've put that OnPlayerExitVehicle.. but when player fall from the bike it's still same.. it doesn't remove his helmet..


Re: Question - McBan - 03.08.2014

Are you certain you are removing the helmet from the actual object slot? Maybe the helmet is in another slot?


Re: Question - Threshold - 03.08.2014

OnPlayerExitVehicle is not called when a player falls off a bike...
It even tells you that on the wiki... https://sampwiki.blast.hk/wiki/OnPlayerExitVehicle

And use PLAYER_STATE_ONFOOT, because the same applies to PLAYER_STATE_EXIT_VEHICLE with falling off bikes..


Re: Question - Lajko1 - 03.08.2014

Okay if I'm using onplayerstate change it's working bit better but why it sends message "unbuckles his seatbelt" instead of "removes safety helmet" ??

pawn Код:
new string[256];
    new sendername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    new vehicleid = GetPlayerVehicleID(playerid);

    if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
    {
        if(SeatBelt[playerid] == 1)
        {
            if(IsModelABike(vehicleid)) // Bike - helmet
            {
                SeatBelt[playerid] = 0;
                if(IsPlayerAttachedObjectSlotUsed(playerid, 1)) RemovePlayerAttachedObject(playerid, helmet[0]); // Removing his helmet
                if (Masked[playerid] == 1) format(string, sizeof(string), "*Stranger_%d removes the safety helmet.", maskid[playerid]);
                else format(string, sizeof(string), "*%s removes the safety helmet.", sendername);
                ProxDetector(8.0, playerid, string,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA);
                return 1;
            }
            else // SEATBELT
            {
                SeatBelt[playerid] = 0;
                if (Masked[playerid] == 1) format(string, sizeof(string), "*Stranger_%d unbuckles his seatbelt.", maskid[playerid]);
                else format(string, sizeof(string), "*%s unbuckles his seatbelt.", sendername);
                ProxDetector(8.0, playerid, string,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA);
            }
        }
    }



Re: Question - Threshold - 03.08.2014

If the player is not in a vehicle, what do you think 'GetPlayerVehicleID(playerid)' returns? It returns '0'.
Then you do 'if(IsModelABike(0))', which is not going to go well... so it heads for the 'else' instead.

So you should rather do:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate & (PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER)) //Player entered the vehicle
    {
        SeatBelt[playerid] = (IsModelABike(GetPlayerVehicleID(playerid))) ? (2) : (1);
        //SeatBelt[playerid] = ...        Bike (2), Other Vehicle (1). So if 'SeatBelt[playerid] == 2', it means they're wearing a helmet.
    }
    if((newstate & PLAYER_STATE_ONFOOT) && (oldstate & (PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER)))
    {
        if(SeatBelt[playerid] == 2) //Bike - helmet
        {
            SeatBelt[playerid] = 0;
            if(IsPlayerAttachedObjectSlotUsed(playerid, 1)) RemovePlayerAttachedObject(playerid, helmet[0]); // Removing his helmet
            if(Masked[playerid] == 1) format(string, sizeof(string), "*Stranger_%d removes the safety helmet.", maskid[playerid]);
            else format(string, sizeof(string), "*%s removes the safety helmet.", sendername);
            ProxDetector(8.0, playerid, string,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA);
        }
        else if(SeatBelt[playerid] == 1) //Seatbelt
        {
            SeatBelt[playerid] = 0;
            if(Masked[playerid] == 1) format(string, sizeof(string), "*Stranger_%d unbuckles his seatbelt.", maskid[playerid]);
            else format(string, sizeof(string), "*%s unbuckles his seatbelt.", sendername);
            ProxDetector(8.0, playerid, string,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA,0x33CCFFAA);
        }
    }
    return 1;
}



Re: Question - Lajko1 - 03.08.2014

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{

    new string[256];
    new sendername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    new vehicleid = GetPlayerVehicleID(playerid);

    if(newstate & (PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER)) //tag mismatch
    {
        SeatBelt[playerid] = (IsModelABike(GetPlayerVehicleID(playerid))) ? (2) : (1);
        //SeatBelt[playerid] = ...        Bike (2), Other Vehicle (1). So if 'SeatBelt[playerid] == 2', it means they're wearing a helmet.
    }
    if((newstate & PLAYER_STATE_ONFOOT) && (oldstate & (PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER))) //tag mismatch
2x tagmismatch I commented lines


Re: Question - ViniBorn - 03.08.2014

pawn Код:
if(newstate & PLAYER_STATE_DRIVER || newstate & PLAYER_STATE_PASSENGER)

if(newstate & PLAYER_STATE_ONFOOT && (oldstate & PLAYER_STATE_DRIVER || oldstate & PLAYER_STATE_PASSENGER))