Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <streamer>
- #include <SII>
- #include <zcmd>
- #include <sscanf2>
- #define LABELTEXT1 "{00FF00}House Name: {0099FF}%s\n{00FF00}House Owner: {FFFFFF}No Owner\n{00FF00}House Value: {FFFFFF}$%d\n{00FF00}For Sale: {FFFFFF}Yes\n{00FF00}House ID: {FFFFFF}%d"
- #define LABELTEXT2 "House Name: {FFFFFF}%s\n{FF0000}House Owner: {FFFFFF}%s\n{FF0000}House Value: {FFFFFF}$%d\n{FF0000}For Sale: {FFFFFF}No\n{00BC00}{FF0000}House ID: {FFFFFF}%d"
- #define DEFAULT_HOUSE_NAME "House For Sale!"
- #define MAX_HOUSES 10000
- #define DIALOG_BHOUSE 5000
- #define DIALOG_MHOUSE 5001
- #define DIALOG_MHOUSE2 5002
- #define DIALOG_C-ENTER 5003
- enum HouseInfo
- {
- HouseName[54],
- Owner[24],
- Owned,
- Price,
- Float:XPos,
- Float:YPos,
- Float:ZPos,
- VirtualWorld,
- Text3D:HouseLabel
- }
- new HInfo[MAX_HOUSES][HouseInfo];
- new HouseCount;
- new HouseEnter[MAX_HOUSES];
- new PlayerInHouseID[MAX_PLAYERS];
- new IsInterior[MAX_PLAYERS];
- public OnGameModeInit()
- {
- print("\n|=====================================================================|");
- print("|---------------------------------------------------------------------|");
- print("|*~*~*~*~*~*~*~*~*Windrush House System 100% ready!!~*~*~*~*~*~*~*~*~*|");
- print("|---------------------------------------------------------------------|");
- print("|=====================================================================|\n");
- LoadHouses();
- return 1;
- }
- public OnPlayerDisconnect(playerid)
- {
- IsInterior[playerid] = 0;
- return 1;
- }
- CMD:chouse(playerid,params[])
- {
- new HousePrice,id = HouseCount;
- new Float:x,Float:y,Float:z;
- new file[40],labelstring[300];
- if(sscanf(params,"i",HousePrice)) return SendClientMessage(playerid,-1,"USAGE: /createhouse <price>");
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,-1,"You aren't an admin!");
- GetPlayerPos(playerid,x,y,z);
- HInfo[id][Price] = HousePrice;
- HInfo[id][Owned] = 0;
- HInfo[id][XPos] = x;
- HInfo[id][YPos] = y;
- HInfo[id][ZPos] = z;
- HInfo[id][VirtualWorld] = GetPlayerVirtualWorld(playerid);
- format(HInfo[id][Owner],24,"Nonusablenameforthishouse");
- SendClientMessage(playerid,-1,"House created");
- HouseEnter[id] = CreateDynamicCP(x,y,z,1.5,GetPlayerVirtualWorld(playerid));
- format(file,sizeof(file),"FHouse/Houses/%i.ini",id);
- INI_Open(file);
- INI_WriteString("HouseName",DEFAULT_HOUSE_NAME);
- INI_WriteInt("Price",HousePrice);
- INI_WriteInt("Owned",0);
- INI_WriteInt("VirtualWorld",GetPlayerVirtualWorld( playerid));
- INI_WriteFloat("XPos",x);
- INI_WriteFloat("YPos",y);
- INI_WriteFloat("ZPos",z);
- INI_WriteString("Owner","Nonusablenameforthishouse ");
- INI_Save();
- INI_Close();
- format(labelstring,sizeof(labelstring),LABELTEXT1,DEFAULT_HOUSE_NAME,HousePrice,id);
- HInfo[id][HouseLabel] = Create3DTextLabel(labelstring,0xFF0000FF,x,y,z,25.0,GetPlayerVirtualWorld(playerid));
- HouseCount++;
- return 1;
- }
- CMD:sellh(playerid,params[])
- {
- for(new i = 0; i < MAX_HOUSES;i++)
- {
- if(!IsPlayerInRangeOfPoint(playerid,8.0,HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos])) continue;
- if(HInfo[i][Owned] == 0) return SendClientMessage(playerid,-1,"This house isn't owned");
- new pName[24], id = HouseCount;
- GetPlayerName(playerid,pName,sizeof(pName));
- if(HInfo[i][Owned] == 1 && strcmp(pName,HInfo[i][Owner]) != 0) return SendClientMessage(playerid,-1,"You aren't the owner of this house!");
- HInfo[i][Owned] = 0;
- new file[60],string[300];
- format(HInfo[i][Owner],24,"Nonusablenameforthishouse");
- format(file,sizeof(file),"FHouse/Houses/%i.ini",id);
- INI_Open(file);
- INI_WriteString("HouseName",DEFAULT_HOUSE_NAME);
- INI_WriteInt("Owned",0);
- INI_WriteString("Owner","Nonusablenameforthishouse ");
- INI_Save();
- INI_Close();
- format(string,sizeof(string),LABELTEXT1,DEFAULT_HOUSE_NAME,HInfo[id][Price],id);//Formating the string, so we can update the label of the house
- Update3DTextLabelText(HInfo[i][HouseLabel],0xFF0000FF,string);//Updating the label with a red color
- return 1;
- }
- return 1;
- }
- CMD:hmenu(playerid,params[])
- {
- if(IsInterior[playerid] == 1)
- {
- new string[128];
- strcat(string,"{00FF00}Change House Name\n",sizeof(string));
- strcat(string,"{FF0000}Exit House\n",sizeof(string));
- ShowPlayerDialog(playerid,DIALOG_MHOUSE,DIALOG_STYLE_LIST,"{00FF00}House System",string,"Ok","Cancel");
- }
- else return SendClientMessage(playerid,0xFF0000FF,"You Must In The Inside of The House");
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- //==============================================================================
- //--Buy-A-House-----------------------------------------------------------------
- //==============================================================================
- if(dialogid == DIALOG_BHOUSE)
- {
- if(response)
- {
- BuyHouse(playerid);
- }
- }
- //==============================================================================
- // House Menu------------------------------------------------------------------
- //==============================================================================
- if(dialogid == DIALOG_MHOUSE)
- {
- switch(listitem)
- {
- case 0:
- {
- if(IsPlayerOwnedHouse(playerid))
- {
- ShowPlayerDialog(playerid,DIALOG_MHOUSE2,DIALOG_STYLE_INPUT,"{00FF00}House System","Type Your New Name Of Your House","Finish","Close");
- }
- }
- case 1:
- {
- SetPlayerPos(playerid,HInfo[playerid][XPos],HInfo[playerid][YPos],HInfo[playerid][ZPos]);
- SetPlayerInterior(playerid,GetPVarInt(playerid,"PlayersInteriorHouse"));
- SetPlayerVirtualWorld(playerid,GetPVarInt(playerid ,"PlayerVirtualWorldHouse"));
- IsInterior[playerid] = 0;
- }
- }
- }
- //==============================================================================
- if(dialogid == DIALOG_MHOUSE2)
- {
- if(response)
- {
- for(new i = 0; i < MAX_HOUSES;i++)
- {
- new string[300],file[60],pName[24],id = HouseCount;
- GetPlayerName(playerid,pName,sizeof(pName));
- format(file,sizeof(file),"FHouse/Houses/%i.ini",id);
- INI_Open(file);
- INI_WriteString("HouseName",inputtext);
- INI_Save();
- INI_Close();
- format(string,sizeof(string),LABELTEXT2,inputtext,pName,HInfo[i][Price],id);
- Update3DTextLabelText(HInfo[i][HouseLabel],0xFF0000FF,string);
- }
- }
- }
- //==============================================================================
- // When player Enter CP--------------------------------------------------------
- //==============================================================================
- if(dialogid == DIALOG_C-ENTER)
- {
- if(response)
- {
- for(new i = 0; i < MAX_HOUSES;i++)
- {
- SetPVarInt(playerid,"PlayersInteriorHouse",GetPlayerInterior(playerid));//Storing, so later we can reset it back
- SetPVarInt(playerid,"PlayerVirtualWorldHouse",GetPlayerVirtualWorld(playerid));//Storing, so later we can reset it back
- SetPlayerInterior(playerid,12);//Setting the players interior.
- SetPlayerPos(playerid,2496.049804,-1695.238159,1014.742187) ;//Setting the players position.
- SetPlayerVirtualWorld(playerid,HInfo[playerid][VirtualWorld]);//Preventing players from different houses, finding each other.
- PlayerInHouseID[playerid] = i;
- IsInterior[playerid] = 1;
- }
- }
- }
- //==============================================================================
- return 1;
- }
- public OnPlayerEnterDynamicCP(playerid,checkpointid)
- {
- for(new i = 0; i < MAX_HOUSES;i++)//Looping threw all houses.
- {
- if(checkpointid == HouseEnter[i])//Checking if the checkpoint id corresponds to one of the house interiors
- {
- new pName[24];//Creating the new var for the players name
- GetPlayerName(playerid,pName,24);//Storing the players name
- if(HInfo[i][Owned] == 1 && strcmp(HInfo[i][Owner],pName) == 0)//String comparing between the players name and the house owners name, to check if they match.
- {
- ShowPlayerDialog(playerid,DIALOG_C-ENTER,DIALOG_STYLE_MSGBOX,"{00FF00}House System","{FF0000}Are You Sure To Enter To Your House?","Yes","No");
- }
- if(HInfo[i][Owned] == 1 && strcmp(HInfo[i][Owner],pName) != 0)//Checking if the house is owned but the house owner and the players name don't match.
- {
- SendClientMessage(playerid,-1,"You don't own this house");
- }
- if(HInfo[i][Owned] == 0)//Simply checking if the house isn't owned.
- {
- ShowPlayerDialog(playerid, DIALOG_BHOUSE,DIALOG_STYLE_MSGBOX,"{00FF00}House System","{FFFFFF}Are You Sure To Buy This House?","Yes","No");
- }
- }
- }
- return 1;
- }
- stock LoadHouses()
- {
- new file[60],houseowner[24];
- for(new i = 0; i < MAX_HOUSES;i++)
- {
- format(file,sizeof(file),"FAdmin/Houses/%i.ini",i);
- if(!INI_Exist(file)) continue;
- INI_Open(file);
- HInfo[i][HouseName] = INI_ReadString("HouseName",DEFAULT_HOUSE_NAME);
- HInfo[i][Price] = INI_ReadInt("Price");
- HInfo[i][Owned] = INI_ReadInt("Owned");
- HInfo[i][XPos] = INI_ReadInt("XPos");
- HInfo[i][YPos] = INI_ReadInt("YPos");
- HInfo[i][ZPos] = INI_ReadInt("ZPos");
- HInfo[i][VirtualWorld] = INI_ReadInt("VirtualWorld");
- INI_ReadString(houseowner,"Owner");
- format(HInfo[i][Owner],24,"%s",houseowner);
- HouseEnter[i] = CreateDynamicCP(HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos],1.5,HInfo[i][VirtualWorld]);
- new labelstring[300];
- switch(HInfo[i][Owned])
- {
- case 0:{format(labelstring,sizeof(labelstring),"Owned: No \nPrice: %i",HInfo[i][Price]);}//If it isnt...
- case 1:{format(labelstring,sizeof(labelstring),"Owned: Yes \nPrice: %i \nOwner: %s",HInfo[i][Price],HInfo[i][Owner]);}//If it is...
- }
- HInfo[i][HouseLabel] = Create3DTextLabel(labelstring,0xFF0000FF,HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos],25.0,HInfo[i][VirtualWorld]);//Creating the label with the formatted string.
- HouseCount++;
- INI_Close();
- }
- return 1;
- }
- stock BuyHouse(playerid)
- {
- for(new i = 0; i < MAX_HOUSES;i++)
- {
- new file[60],string[300],pName[24], id = HouseCount;
- new hname[MAX_PLAYER_NAME+9];
- GetPlayerName(playerid,pName,sizeof(pName));
- format(hname,sizeof(hname),"%s's House",pName);
- if(!IsPlayerInRangeOfPoint(playerid,8.0,HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos])) continue;//Check if the player is near a house checkpoint
- if(GetPlayerMoney(playerid) < HInfo[i][Price]) return SendClientMessage(playerid,-1,"You don't have enough money");//Checking the players money, to see if he has enough to buy the house.
- if(HInfo[i][Owned] == 1) return SendClientMessage(playerid,-1,"This house is already owned");//Checking if the house is already owned.
- HInfo[i][Owned] = 1;
- format(HInfo[i][Owner],24,"%s",pName);
- format(file,sizeof(file),"FHouse/Houses/%i.ini",id);
- INI_Open(file);
- INI_WriteString("HouseName",hname);
- INI_WriteInt("Owned",1);
- INI_WriteString("Owner",pName);
- INI_Save();
- INI_Close();
- format(string,sizeof(string),LABELTEXT2,hname,pName,HInfo[playerid][Price],id);
- Update3DTextLabelText(HInfo[i][HouseLabel],0xFF0000FF,string);
- GivePlayerMoney(playerid,-HInfo[i][Price]);
- return 1;
- }
- return 1;
- }
- stock IsPlayerOwnedHouse(playerid)
- {
- new pName[24];
- GetPlayerName(playerid,pName,sizeof(pName));
- if(HInfo[playerid][Owned] == 1 && strcmp(HInfo[playerid][Owner],pName) == 0)
- {
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment