SA-MP Forums Archive
OnPlayerEnterVehicle - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: OnPlayerEnterVehicle (/showthread.php?tid=266692)



OnPlayerEnterVehicle - cruising - 05.07.2011

Hello!

i cant get this to work. either you got the message and still can fly, or you not get the message and still can fly, you never gets ejected from the hunter :S

pawn Код:
public OnPlayerEnterVehicle(playerid,vehicleid,ispassenger)
{
    if(GetVehicleModel(vehicleid) == 553)
    {
        SendClientMessage(playerid, 0x33CCFFAA, "This is a NUCLEAR BOMB plane!!");
        SetVehicleHealth(vehicleid, 2000.0);
    }
    if(GetVehicleModel(vehicleid) == 476)
    {
        SendClientMessage(playerid, 0x33CCFFAA, "This is a fighter and a bomb plane!");
    }
    if(GetVehicleModel(vehicleid) == 432)
    {
        SendClientMessage(playerid, 0x33CCFFAA, "This is a heavy reinforced tank!");
        SetVehicleHealth(vehicleid, 3000.0);
    }
    if(GetVehicleModel(vehicleid) == 425) //hunter
    {
        if(GetPlayerScore(playerid) > 0 && GetPlayerScore(playerid) < 200)
        SendClientMessage(playerid, 0x33CCFFAA, "You need 200 kills to have permission to fly a Hunter!");
        RemovePlayerFromVehicle(playerid);
    }
    return 1;
}



AW: OnPlayerEnterVehicle - Nero_3D - 05.07.2011

OnPlayerEnterVehicle and RemovePlayerFromVehicle

You will notice that you cant remove someone from something that he isnt in

Use OnPlayerKeyStateChange


Re: OnPlayerEnterVehicle - [NoV]LaZ - 05.07.2011

OnPlayerEnterVehicle gets called when a player is close to a vehicle and presses enter, it will never get called when a player is in a vehicle.
In your case, you'd need OnPlayerStateChange.

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if (newstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if (GetVehicleModel(GetPlayerVehicleID(playerid) == vehicle model)
        {
             // do something
        }
        // ...
    }
    return 1;
}



Re: OnPlayerEnterVehicle - Wesley221 - 05.07.2011

Edit, late


Re: OnPlayerEnterVehicle - cruising - 05.07.2011

Quote:
Originally Posted by [NoV]LaZ
Посмотреть сообщение
OnPlayerEnterVehicle gets called when a player is close to a vehicle and presses enter, it will never get called when a player is in a vehicle.
In your case, you'd need OnPlayerStateChange.

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if (newstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if (GetVehicleModel(GetPlayerVehicleID(playerid) == VEHICLE ID)
        {
             // do something
        }
        // ...
    }
    return 1;
}
I dont know what im doing wrong here, but i get some errors about define VEHICLE and ID
and if i define ill get plenty of errors

Code:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if (newstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if (GetVehicleModel(GetPlayerVehicleID(playerid) == VEHICLE ID)
        {
            if(GetVehicleModel(vehicleid) == 425) //hunter
            }
                if(GetPlayerScore(playerid) > 0 && GetPlayerScore(playerid) < 200)
                }
                    SendClientMessage(playerid, 0x33CCFFAA, "You need 200 kills to have permission to fly a Hunter!");
                    RemovePlayerFromVehicle(playerid);
                }
    return 1;
}

Errors: Line 651 if (GetVehicleModel(GetPlayerVehicleID(playerid) == VEHICLE ID)
pawn Код:
error 017: undefined symbol "VEHICLE"
error 017: undefined symbol "ID"
error 029: invalid expression, assumed zero
fatal error 107: too many error messages on one line



Re: OnPlayerEnterVehicle - [NoV]LaZ - 05.07.2011

I gave you a raw example.

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if (newstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if (GetVehicleModel(GetPlayerVehicleID(playerid) == 425) // Hunter
        {
            if (GetPlayerScore(playerid) < 200)
            {
                SendClientMessage(playerid, -1, "You need 200 kills to take this, bla bla");
                RemovePlayerFromVehicle(playerid);
            }
        }
    }
    return 1;
}
Notice I've used GetPlayerVehicleID instead of vehicleid. That's because that callback we're using doesn't have a vehicleid parameter. If you're working in a callback that doesn't have a vehicleid parameter, and the player is using a vehicle, just use GetPlayerVehicleID. It returns the vehicle's id the player is in.


Re: OnPlayerEnterVehicle - cruising - 05.07.2011

Ah ok!

but i get a error on this to, sorry for my noobish.
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if (newstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if (GetVehicleModel(GetPlayerVehicleID(playerid) == 425) // Hunter
        { // error line
            if (GetPlayerScore(playerid) < 200)
            {
                SendClientMessage(playerid, -1, "You need 200 kills to take this, bla bla");
                RemovePlayerFromVehicle(playerid);
            }
        }
    }
    return 1;
}



Re: OnPlayerEnterVehicle - [NoV]LaZ - 05.07.2011

pawn Код:
if (GetVehicleModel(GetPlayerVehicleID(playerid) == 425))
My bad. That should work.


Re: OnPlayerEnterVehicle - [MG]Dimi - 05.07.2011

In my opinion you can also use
PHP код:
public OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    new 
vehid GetPlayerVehicleID(playerid);
    if(
vehid == 425)
    {
        new 
score GetPlayerScore(playerid);
        if(
score 200)
        {
            
SetVehicleParamsForPlayer(playerid,vehicleid,1);
            
SendClientMessage(playerid0x33CCFFAA"You need 200 kills to have permission to fly a Hunter!");
            return 
1;
        }
        return 
1;
    }
    return 
1;




Re: OnPlayerEnterVehicle - cruising - 05.07.2011

Quote:
Originally Posted by [NoV]LaZ
Посмотреть сообщение
pawn Код:
if (GetVehicleModel(GetPlayerVehicleID(playerid) == 425))
My bad. That should work.
Now the errors is gone, but it make the last line in GM warning about something other in the game :S

EDIT: i dont get any message and do not get ejected.