05.08.2014, 04:39
Okay I would like to find out the owner of a vehicle from just the ID...How would it be possible? What function would I use? Thanks for the help!
/// an example
new mowner[MAX_VEHICLES][MAX_PLAYER_NAME]; // on top of your gm
////////////////
// onplayerstatechange
// if new state == driver
new mid = GetPlayerIdFromName(mowner[vehicleid]);
if(mid == playerid)
{
SendClientMessage(playerid,-1,"Welcome to your vehicle");
return 1;
}
new msgas[126];
format(msgas,sizeof(msgas),"Vehicle owned by %s",mowner[vehicleid]);
SendClientMessage(playerid,-1,msgas);
return 1;
}
GetPlayerName(playerid,mowner[vehicleid],24); /// to make player own a vehicle
stock GetPlayerIdFromName(playername[])
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new playername2[MAX_PLAYER_NAME];
GetPlayerName(i, playername2, sizeof(playername2));
if(strcmp(playername2, playername, true, strlen(playername)) == 0)
{
return i;
}
}
}
return INVALID_PLAYER_ID;
}
////////////// owner of vehicle id from id
new mid = GetPlayerIdFromName(mowner[yourid]);
// 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;
}