27.12.2014, 06:30
pawn Код:
COMMAND:buyhouse(playerid, params[])
{
// Setup local variables
new Msg[128];
if (GetPlayerScore(playerid) < 200) return SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You need at least 200 scores to buy a house.");
// If a player hasn't logged in properly, he cannot use this command
if (INT_IsPlayerLoggedIn(playerid) == 0) return 0;
// Check if the player isn't inside a vehicle (the player must be on foot to use this command)
if (GetPlayerVehicleSeat(playerid) == -1)
{
// Check if the player is near a house-pickup
for (new HouseID = 1; HouseID < MAX_HOUSES; HouseID++)
{
// Check if the house exists
if (IsValidDynamicPickup(AHouseData[HouseID][PickupID]))
{
// Check if the player is in range of the house-pickup
if (IsPlayerInRangeOfPoint(playerid, 2.5, AHouseData[HouseID][HouseX], AHouseData[HouseID][HouseY], AHouseData[HouseID][HouseZ]))
{
// Check if the house isn't owned yet
if (AHouseData[HouseID][Owned] == false)
{
// Check if the player can afford this house
if (INT_GetPlayerMoney(playerid) >= AHouseData[HouseID][HousePrice])
House_SetOwner(playerid, HouseID); // Give ownership of the house to the player (if he has a spare houseslot)
else
SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot afford this house"); // The player cannot afford this house
}
else
{
// Let the player know that this house is already owned by a player
format(Msg, 128, "{FF0000}This house is already owned by {FFFF00}%s", AHouseData[HouseID][Owner]);
SendClientMessage(playerid, 0xFFFFFFFF, Msg);
}
// The player was in range of a house-pickup, so stop searching for the other house pickups
return 1;
}
}
}
// All houses have been processed, but the player wasn't in range of any house-pickup, let him know about it
SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}To buy a house, you have to be near a house-pickup");
}
else
SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You can't buy a house when you're inside a vehicle");
// Let the server know that this was a valid command
return 1;
}