Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include < a_samp >
- #include < dini2 >
- #include < YSI\y_hooks >
- #include < YSI\y_commands >
- #define MAX_HOUSES 1000
- forward OnHouseCreate(houseid);
- forward OnHouseDelete(houseid);
- forward OnPlayerEnterHouse(playerid, houseid);
- forward OnPlayerExitHouse(playerid, houseid);
- forward OnPlayerBuyHouse(playerid, houseid);
- forward OnPlayerSellHouse(playerid, houseid);
- enum HOUSE_INFO {
- Float:hX,
- Float:hY,
- Float:hZ,
- Float:hIntX,
- Float:hIntY,
- Float:hIntZ,
- hPrice,
- hEntvw,
- hIntvw,
- hIntid,
- hType,
- hOutintid,
- bool:hLocked,
- Houseid,
- bool:hSold,
- hOwner[ MAX_PLAYER_NAME ],
- Housepickup
- }
- enum PLAYER_INFO {
- hOwnHouse
- }
- enum {
- DIALOG_HOUSE,
- DIALOG_HOUSEINFO
- }
- new HouseInfo[ MAX_HOUSES ][ HOUSE_INFO ], Text3D:HouseLabel[ sizeof(HouseInfo) ], PlayerInfo[ MAX_PLAYERS ][ PLAYER_INFO ];
- hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
- if(newkeys == KEY_SECONDARY_ATTACK) {
- for(new i; i < MAX_HOUSES; i++) {
- if(IsPlayerInRangeOfPoint(playerid, 2.0, HouseInfo[ i ][ hX ], HouseInfo[ i ][ hY ], HouseInfo[ i ][ hZ ])) {
- if(!strcmp(GetName( playerid ), HouseInfo[ i ][ hOwner ], true)) {
- SetPlayerPos(playerid, HouseInfo[ i ][ hIntX ], HouseInfo[ i ][ hIntY ], HouseInfo[ i ][ hIntZ ]);
- SetPlayerVirtualWorld(playerid, HouseInfo[ i ][ hIntvw ]);
- SetPlayerInterior(playerid, HouseInfo[ i ][ hIntid ]);
- CallLocalFunction("OnPlayerEnterHouse", "dd", playerid, i);
- }
- else {
- if(HouseInfo[ i ][ hLocked ]) return SendClientMessage(playerid, -1, "Locked.");
- SetPlayerPos(playerid, HouseInfo[ i ][ hIntX ], HouseInfo[ i ][ hIntY ], HouseInfo[ i ][ hIntZ ]);
- SetPlayerVirtualWorld(playerid, HouseInfo[ i ][ hIntvw ]);
- SetPlayerInterior(playerid, HouseInfo[ i ][ hIntid ]);
- CallLocalFunction("OnPlayerEnterHouse", "dd", playerid, i);
- }
- }
- else if(IsPlayerInRangeOfPoint(playerid, 2.0, HouseInfo[ i ][ hIntX ], HouseInfo[ i ][ hIntY ], HouseInfo[ i ][ hIntZ ])) {
- SetPlayerPos(playerid, HouseInfo[ i ][ hX ], HouseInfo[ i ][ hY ], HouseInfo[ i ][ hZ ]);
- SetPlayerVirtualWorld(playerid, HouseInfo[ i ][ hEntvw ]);
- SetPlayerInterior(playerid, HouseInfo[ i ][ hOutintid ]);
- CallLocalFunction("OnPlayerExitHouse", "dd", playerid, i);
- }
- }
- }
- return 1;
- }
- hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
- switch(dialogid) {
- case DIALOG_HOUSE: {
- if(!response) return 0;
- new i = PlayerInfo[ playerid ][ hOwnHouse ];
- switch(listitem) {
- case 0: {
- new str[ 100 ];
- if(HouseInfo[ i ][ hType ] == 1) { format(str, sizeof(str), "House ID: %d\nPrice: %d$\nSell price: %d$\nType: Small house", i, HouseInfo[ i ][ hPrice ], HouseInfo[ i ][ hPrice ]/2); }
- else if(HouseInfo[ i ][ hType ] == 2) { format(str, sizeof(str), "House ID: %d\nPrice: %d$\nSell price: %d$\nType: Medium house", i, HouseInfo[ i ][ hPrice ], HouseInfo[ i ][ hPrice ]/2); }
- else if(HouseInfo[ i ][ hType ] == 3) { format(str, sizeof(str), "House ID: %d\nPrice: %d$\nSell price: %d$\nType: Big house", i, HouseInfo[ i ][ hPrice ], HouseInfo[ i ][ hPrice ]/2); }
- else if(HouseInfo[ i ][ hType ] == 4) { format(str, sizeof(str), "House ID: %d\nPrice: %d$\nSell price: %d$\nType: Villa", i, HouseInfo[ i ][ hPrice ], HouseInfo[ i ][ hPrice ]/2); }
- ShowPlayerDialog(playerid, DIALOG_HOUSEINFO, DIALOG_STYLE_MSGBOX, "House Info", str, "Exit","");
- }
- case 1: {
- if(HouseInfo[ i ][ hLocked ]) { HouseInfo[ i ][ hLocked ] = false; SendClientMessage(playerid, -1, "Unlocked."); }
- else { HouseInfo[ i ][ hLocked ] = true; SendClientMessage(playerid, -1, "Locked."); }
- }
- case 2: {
- new str[ 100 ], str1[ 24 ];
- GivePlayerMoney(playerid, HouseInfo[ i ][ hPrice ]/2);
- if(HouseInfo[ i ][ hType ] == 1) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Small house\n/buyhouse", i, HouseInfo[ i ][ hPrice ]); }
- else if(HouseInfo[ i ][ hType ] == 2) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Medium house\n/buyhouse", i, HouseInfo[ i ][ hPrice ]); }
- else if(HouseInfo[ i ][ hType ] == 3) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Big house\n/buyhouse", i, HouseInfo[ i ][ hPrice ]); }
- else if(HouseInfo[ i ][ hType ] == 4) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Villa\n/buyhouse", i, HouseInfo[ i ][ hPrice ]); }
- Update3DTextLabelText(HouseLabel[ i ], 0x00FF59AA, str);
- HouseInfo[ i ][ hSold ] = false;
- format(str1, sizeof(str1), "No-one");
- HouseInfo[ i ][ hOwner ] = str1;
- HouseInfo[ i ][ hLocked ] = true;
- CallLocalFunction("OnPlayerSellHouse", "dd", playerid, i);
- }
- }
- }
- }
- return 1;
- }
- stock CreateHouse(houseid, Float:entX, Float:entY, Float:entZ, Float:intX, Float:intY, Float:intZ, entvw, intvw, intid, outintid, price, type) {
- new str[ 100 ];
- if(type == 1) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Small house\n/buyhouse", houseid, price); }
- else if(type == 2) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Medium house\n/buyhouse", houseid, price); }
- else if(type == 3) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Big house\n/buyhouse", houseid, price); }
- else if(type == 4) { format(str, sizeof(str), "House for sale !\nID: %d\nPrice: %d$\nType: Villa\n/buyhouse", houseid, price); }
- HouseLabel[ houseid ] = Create3DTextLabel(str, 0x00FF59AA, entX, entY, entZ, 10.0, entvw, 0);
- HouseInfo[ houseid ][ Housepickup ] = CreatePickup(1273, 1, entX, entY, entZ, entvw);
- HouseInfo[ houseid ][ hX ] = entX;
- HouseInfo[ houseid ][ hY ] = entY;
- HouseInfo[ houseid ][ hZ ] = entZ;
- HouseInfo[ houseid ][ hIntX ] = intX;
- HouseInfo[ houseid ][ hIntY ] = intY;
- HouseInfo[ houseid ][ hIntZ ] = intZ;
- HouseInfo[ houseid ][ hPrice ] = price;
- HouseInfo[ houseid ][ hEntvw ] = entvw;
- HouseInfo[ houseid ][ hIntvw ] = intvw;
- HouseInfo[ houseid ][ hIntid ] = intid;
- HouseInfo[ houseid ][ hOutintid ] = outintid;
- HouseInfo[ houseid ][ Houseid ] = houseid;
- HouseInfo[ houseid ][ hType ] = type;
- HouseInfo[ houseid ][ hLocked ] = true;
- new str1[ 24 ];
- format(str1, sizeof(str1), "No-one");
- HouseInfo[ houseid ][ hOwner ] = str1;
- CallLocalFunction("OnHouseCreate", "d", houseid);
- return 1;
- }
- stock DeleteHouse(houseid) {
- Delete3DTextLabel(HouseLabel[ houseid ]);
- DestroyPickup(HouseInfo[ houseid ][ Housepickup ]);
- HouseInfo[ houseid ][ hX ] = 0;
- HouseInfo[ houseid ][ hY ] = 0;
- HouseInfo[ houseid ][ hZ ] = 0;
- HouseInfo[ houseid ][ hIntX ] = 0;
- HouseInfo[ houseid ][ hIntY ] = 0;
- HouseInfo[ houseid ][ hIntZ ] = 0;
- HouseInfo[ houseid ][ hPrice ] = 0;
- HouseInfo[ houseid ][ hEntvw ] = 0;
- HouseInfo[ houseid ][ hIntvw ] = 0;
- HouseInfo[ houseid ][ hIntid ] = 0;
- HouseInfo[ houseid ][ hOutintid ] = 0;
- HouseInfo[ houseid ][ hType ] = 0;
- CallLocalFunction("OnHouseDelete", "d", houseid);
- return 1;
- }
- stock GetName( playerid ) {
- new pname[ MAX_PLAYER_NAME ];
- GetPlayerName(playerid, pname, sizeof(pname));
- return pname;
- }
- YCMD:buyhouse(playerid, params[], help) {
- #pragma unused help
- #pragma unused params
- for(new i; i < MAX_HOUSES; i++) {
- if(IsPlayerInRangeOfPoint(playerid, 2.0, HouseInfo[ i ][ hX ], HouseInfo[ i ][ hY ], HouseInfo[ i ][ hZ ])) {
- new str[ 115 ], pname[ MAX_PLAYER_NAME ];
- if(HouseInfo[ i ][ hSold ]) return SendClientMessage(playerid, -1, "That house is bought.");
- if(GetPlayerMoney(playerid) < HouseInfo[ i ][ hPrice ]) return SendClientMessage(playerid, -1, "You don't have enought money.");
- HouseInfo[ i ][ hSold ] = true;
- GetPlayerName(playerid, pname, sizeof(pname));
- HouseInfo[ i ][ hOwner ] = pname;
- Update3DTextLabelText(HouseLabel[ i ], 0x00FF59AA, str);
- GivePlayerMoney(playerid, -HouseInfo[ i ][ hPrice ]);
- PlayerInfo[ playerid ][ hOwnHouse ] = i;
- if(HouseInfo[ i ][ hType ] == 1) { format(str, sizeof(str), "Owner: %s\nID: %d\nPrice: %d$\nType: Small house", pname, i, HouseInfo[ i ][ hPrice ]); }
- else if(HouseInfo[ i ][ hType ] == 2) { format(str, sizeof(str), "Owner: %s\nID: %d\nPrice: %d$\nType: Medium house", pname, i, HouseInfo[ i ][ hPrice ]); }
- else if(HouseInfo[ i ][ hType ] == 3) { format(str, sizeof(str), "Owner: %s\nID: %d\nPrice: %d$\nType: Big house", pname, i, HouseInfo[ i ][ hPrice ]); }
- else if(HouseInfo[ i ][ hType ] == 4) { format(str, sizeof(str), "Owner: %s\nID: %d\nPrice: %d$\nType: Villa", pname, i, HouseInfo[ i ][ hPrice ]); }
- Update3DTextLabelText(HouseLabel[ i ], 0x00FF59AA, str);
- CallLocalFunction("OnPlayerBuyHouse", "dd", playerid, i);
- }
- }
- return 1;
- }
- YCMD:house(playerid, params[], help) {
- #pragma unused help
- #pragma unused params
- if(PlayerInfo[ playerid ][ hOwnHouse ] == 0) return SendClientMessage(playerid, -1, "You don't have house.");
- ShowPlayerDialog(playerid, DIALOG_HOUSE, DIALOG_STYLE_LIST, "HOUSE","House Info\nLock house\nSell House","Choose","Quit");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement