Check playername
#1

Hello need help , i want to do like if player gets into train as passenger pay 10euro to driver so , i need to get driver name or id somehow and then give him those money that i take from passenger , need some exmaples how to do this
Reply
#2

You have to check if the player entered in the train and if the train has a driver.

Here's an example:

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    switch(newstate)
    {
        case PLAYER_STATE_PASSENGER:
        {// Check if player has entered as passenger
            if(GetPlayerVehicleID(playerid) == TRAIN_ID)
            {// Check if the vehicle is the train, CHANGE TO TRAIN VEHICLE ID
                new driverid = GetVehicleDriverID(GetPlayerVehicleID(playerid));
                // Get the driverid
                if(driverid != INVALID_PLAYER_ID)
                {// Check if the train has a driver
                    // Do stuff
                }
            }
        }
    }
    return 1;
}

stock GetVehicleDriverID(vehicleid)
{
    for(new i; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInVehicle(i, vehicleid))
        {
            if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
            {
                return i;
            }
        }
    }
    return INVALID_PLAYER_ID;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)