Vehicle Owner from Vehicle ID
#3

Here's another method, which is (imo) more efficient than the above one. I came up with this a minute ago so it's not 100% as this will only return a name if the owner is connected. If not, it'll return a negative value to kill the command.

It's obviously not plug and play but should give you an idea of how to proceed. This method requires you to store the vehicle ID in to a player variable (and save/load it ofcourse) and then check if the value of that variable is the same as the vehicle ID you're accessing.

pawn Код:
// In your PlayerInfo enum
enum pInfo
{
    CarOwner,
};
new PlayerInfo[MAX_PLAYERS][pInfo];

// Using an example command: /carowner
CMD:carowner(playerid, params[])
{
    // Create two variables for the name and string
    new name[MAX_PLAYER_NAME], string[50];
    // String size 50 because the "Vehicle is owned by" is 20 characters long, and "name" is 24.   

    // Make the command only usable when playerid is in a vehicle
    if(!IsPlayerInAnyVehicle(playerid))
        return SendClientMessage(playerid, -1, "You need to be in a vehicle in order to do this command!");
       
    // Loop through all connected players
    foreach(new i: Player)
    {
        // If a player's "CarOwner" variable is the vehicleid
        if(PlayerInfo[i][CarOwner] == GetPlayerVehicleID(playerid))
        {
            // Store their name in the "name" variable
            GetPlayerName(i, name, sizeof(name));
        }
       
        else return false;
    }

    // Now format them with a message and send it to playerid
    format(string, sizeof(string), "Vehicle is owned by %s", name);
    SendClientMessage(playerid, -1, string);
   
    // Return a value
    return 1;
}
Reply


Messages In This Thread
Vehicle Owner from Vehicle ID - by Alex_T - 05.08.2014, 04:39
Re: Vehicle Owner from Vehicle ID - by Gintaras123 - 05.08.2014, 15:51
Re: Vehicle Owner from Vehicle ID - by Dignity - 05.08.2014, 16:03

Forum Jump:


Users browsing this thread: 1 Guest(s)