27.01.2019, 15:07
PHP код:
new sellOwnedHouseID[MAX_PLAYERS]={-1,...};
findOwnedHouse(playerid){
for(new i; i < MAX_HOUSES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0, HouseInfo[i][ExteriorPos][0], HouseInfo[i][ExteriorPos][1], HouseInfo[i][ExteriorPos][2]) &&
HouseInfo[i][server_ID] == PlayerInfo[playerid][HouseID])
return i;
}
return -1;
}
updateHouseInfo(i){
DestroyDynamicPickup(HouseInfo[i][Pickup]);
DestroyDynamic3DTextLabel(HouseInfo[i][Label]);
new s[100];
HouseInfo[i][Pickup] = CreateDynamicPickup(1273, 23, HouseInfo[i][ExteriorPos][0], HouseInfo[i][ExteriorPos][1], HouseInfo[i][ExteriorPos][2], HouseInfo[i][ExteriorWorld]);
format(s, 100, "{70ff83}This house is for sell!\nPrice: %d\nType /buyhouse to buy it\nType /enter to go inside", HouseInfo[i][Price]);
HouseInfo[i][Label] = CreateDynamic3DTextLabel(1 , COLOR_ORANGE, HouseInfo[i][ExteriorPos][0], HouseInfo[i][ExteriorPos][1], HouseInfo[i][ExteriorPos][2],30.0,
INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 7.0);
}
CMD:house(pid,p[]){
new opt1[32],
opt2[32],
s[100],
i;
if(sscanf(params,"s[32]s[32]",opt1,opt2))return SendClientMessage(pid,-1,"/house [selltomarket / selltomarket confirm]");
if(!strcmp(opt1,"selltomarket")){
if(strlen(opt2) && !strcmp(opt2,"confirm")){
if((i=sellOwnedHouseID[pid])==-1)return SendClientMessage(pid,-1,"you haven't seleted any house to sell!");
new houseprice = floatround(HouseInfo[i][Price]*0.5);
updateHouseInfo(i);
HouseInfo[i][ForSell] = 1;
HouseInfo[i][Locked] = 0;
GiveMoney(playerid, houseprice);
sellOwnedHouseID[pid]=-1;
format(s, 100, "You've sold your house for $%d!", houseprice);
SendClientMessage(playerid, COLOR_GREY, str);
}else{
if(sellOwnedHouseID[pid]!=-1)return SendClientMessage(pid,-1,"you are already selling some house type (/house selltomarket confirm)!");
if((i=findOwnedHouse(pid))==-1)return SendClientMessage(pid,-1,"you arent near to any of your houses!");
sellOwnedHouseID[pid]=i;
SendClientMessage(pid,-1,"you are selling your house, type (/house selltomarket confirm)");
}
}
return 1;
}