Advertisement
Seregamil

Dynamic House System

Apr 22nd, 2013
1,843
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 20.35 KB | None | 0 0
  1.  
  2. #include <a_samp>
  3. #include mxINI
  4. #include streamer
  5.  
  6. #define SEREGAMIL -1
  7.  
  8. #define dcmd(%1,%2,%3) if((strcmp((%3)[1],#%1,true,(%2))==0)&&((((%3)[(%2)+1]==0)&&(dcmd_%1(playerid,"")))||(((%3)[(%2)+1]==32)&&(dcmd_%1(playerid,(%3)[(%2)+2]))))) return 1
  9.  
  10. new hinter[16]={1,1,3,2,5,9,10,10,12,6,5,8,1,2,8};
  11.  
  12. new Float:housepos[15][3]=
  13. {
  14.     {244.6262,304.7528,999.1484},
  15.     {2525.8909,-1679.1622,1015.4986},
  16.     {2492.3103,-1696.4454,1014.7650},
  17.     {268.0308,305.3448,999.1484},
  18.     {2233.2769,-1113.8984,1050.8828},
  19.     {2319.0813,-1025.5150,1050.2109},
  20.     {2261.5200,-1136.9385,1050.6328},
  21.     {2261.7595,-1209.9454,1049.0308},
  22.     {2325.7488,-1147.4218,1050.7101},
  23.     {346.3175,306.2907,999.1484},
  24.     {140.2950,1368.9722,1083.8638},
  25.     {2807.3604,-1171.7048,1025.5703},
  26.     {2211.1682,-1075.7603,1050.4844},
  27.     {2237.7590,-1078.3325,1049.0234},
  28.     {2365.1089,-1133.0795,1050.8750}
  29. };
  30.  
  31. #define m_house 500
  32. #define MAX_P_H 1
  33.  
  34. new bool:texts;
  35. new count;
  36.  
  37. enum hs
  38. {
  39.     Float:pos[3],//street
  40.     Float:ent[3],//house
  41.     int,//interior
  42.     own[24],//owner
  43.     clas,//class
  44.     cena,//price
  45.     sell,//sell
  46.     num,
  47.     icon,
  48.     pick,//pickup
  49.     Text3D:htext[256]
  50. };
  51. new hinfo[m_house][hs];
  52. new bool:athouse[MAX_PLAYERS];
  53. new phouse[MAX_PLAYERS];
  54.  
  55. main()
  56. {
  57.     print("\n----------------------------------");
  58.     print(" Blank Gamemode by your name here");
  59.     print("----------------------------------\n");
  60. }
  61.  
  62.  
  63. public OnGameModeInit()
  64. {
  65.     count=0;
  66.     texts = true;//false - off
  67.     loadHouses();
  68.     return 1;
  69. }
  70.  
  71. loadHouses()
  72. {
  73.     for(new x;x!=m_house;x++)
  74.     {
  75.         new str[50];
  76.         format(str,50,"houses/h_%d.ini",x);
  77.         if(fexist(str))
  78.         {
  79.             new file = ini_openFile(str);
  80.             ini_getInteger(file,"num",hinfo[x][num]);
  81.             ini_getString(file,"own",hinfo[x][own],24);
  82.             ini_getFloat(file,"px",hinfo[x][pos][0]);
  83.             ini_getFloat(file,"py",hinfo[x][pos][1]);
  84.             ini_getFloat(file,"pz",hinfo[x][pos][2]);
  85.             ini_getFloat(file,"ex",hinfo[x][ent][0]);
  86.             ini_getFloat(file,"ey",hinfo[x][ent][1]);
  87.             ini_getFloat(file,"ez",hinfo[x][ent][2]);
  88.             ini_getInteger(file,"int",hinfo[x][int]);
  89.             ini_getInteger(file,"class",hinfo[x][clas]);
  90.             ini_getInteger(file,"cena",hinfo[x][cena]);
  91.             ini_getInteger(file,"sell",hinfo[x][sell]);
  92.             count++;
  93.             hinfo[x][pick] = CreatePickup(1273,23,hinfo[x][pos][0],hinfo[x][pos][1],hinfo[x][pos][2]);
  94.             if(texts == true)
  95.             {
  96.                 new hst[256];
  97.                 format(hst,256,"{00ff00}Дом {ffffff}#%d\n{00ff00}Владелец: {ffffff}%s\n{00ff00}Стоймость: {ffffff}%d\n{00ff00}Класс: {ffffff}%s",hinfo[x][num],hinfo[x][own],hinfo[x][cena],hclass(x));
  98.                 hinfo[x][htext] = CreateDynamic3DTextLabel(hst, 0xffffffff, hinfo[x][pos][0],hinfo[x][pos][1],hinfo[x][pos][2], 10.0);
  99.             }
  100.             if(strcmp(hinfo[x][own], "Nobody", true) == 0)
  101.             hinfo[x][icon] = CreateDynamicMapIcon(hinfo[x][pos][0],hinfo[x][pos][1],hinfo[x][pos][2],31,0,-1,-1,-1,500.0);
  102.             else
  103.             hinfo[x][icon] = CreateDynamicMapIcon(hinfo[x][pos][0],hinfo[x][pos][1],hinfo[x][pos][2],32,0,-1,-1,-1,500.0);
  104.             ini_closeFile(file);
  105.             printf("House %d - loaded",x);
  106.         }
  107.     }
  108.     return printf("Houses %d loaded",count);
  109. }
  110.  
  111. public OnPlayerConnect(playerid)
  112. {
  113.     phouse[playerid]=0;
  114.     new name[24];
  115.     GetPlayerName(playerid,name,24);
  116.     for(new x;x!=m_house;x++)
  117.     {
  118.         if(strcmp(hinfo[x][own], "Nobody", true) == 0) continue;
  119.         else if(strcmp(hinfo[x][own], name, true) == 0) phouse[playerid]++;
  120.     }
  121.     SetPVarInt(playerid,"ZHOUSE",0);
  122.     athouse[playerid] = false;
  123.     return 1;
  124. }
  125.  
  126. public OnPlayerDisconnect(playerid, reason)
  127. {
  128.     phouse[playerid]=0;
  129.     SetPVarInt(playerid,"ZHOUSE",0);
  130.     athouse[playerid] = false;
  131.     return 1;
  132. }
  133.  
  134. public OnPlayerSpawn(playerid)
  135. {
  136.     GivePlayerMoney(playerid,999999);
  137.     SetPVarInt(playerid,"ZHOUSE",0);
  138.     SetPlayerPos(playerid,1958.3783,1343.1572,15.3746);
  139.     new name[24];
  140.     GetPlayerName(playerid,name,24);
  141.     for(new x;x!=m_house;x++)
  142.     {
  143.         if(strcmp(hinfo[x][own], "Nobody", true) == 0) continue;
  144.         else if(strcmp(hinfo[x][own], name, true) == 0)
  145.         {
  146.             SetPVarFloat(playerid,"TheHPosx",hinfo[x][pos][0]);
  147.             SetPVarFloat(playerid,"TheHPosy",hinfo[x][pos][1]);
  148.             SetPVarFloat(playerid,"TheHPosz",hinfo[x][pos][2]);
  149.             SetPVarInt(playerid,"TheInt",0);
  150.             SetPlayerPos(playerid,hinfo[x][ent][0],hinfo[x][ent][1],hinfo[x][ent][2]);
  151.             SetPlayerInterior(playerid,hinfo[x][int]);
  152.             SetPlayerVirtualWorld(playerid,playerid+random(150));
  153.             SetPVarInt(playerid,"Selling",hinfo[x][num]);
  154.             athouse[playerid] = true;
  155.             break;
  156.         }
  157.     }
  158.     return 1;
  159. }
  160.  
  161. public OnPlayerDeath(playerid, killerid, reason)
  162. {
  163.     SetPVarInt(playerid,"ZHOUSE",0);
  164.     athouse[playerid] = false;
  165.     return 1;
  166. }
  167.  
  168. public OnPlayerCommandText(playerid, cmdtext[])
  169. {
  170.     dcmd(add,3,cmdtext);
  171.     dcmd(setint,6,cmdtext);
  172.     dcmd(setcena,7,cmdtext);
  173.     dcmd(setclass,8,cmdtext);
  174.     dcmd(asellhouse,10,cmdtext);
  175.     dcmd(sellhouse,9,cmdtext);
  176.     return 0;
  177. }
  178.  
  179. dcmd_sellhouse(playerid,params[])
  180. {
  181.     #pragma unused params
  182.     if(athouse[playerid] == true)
  183.     {
  184.         new hid = GetPVarInt(playerid,"Selling");
  185.         GivePlayerMoney(playerid,hinfo[hid][sell]);
  186.         new str[100];
  187.         format(str,100,"houses/h_%d.ini",hid);
  188.         new file = ini_openFile(str);
  189.         ini_setString(file,"own","Nobody");
  190.         ini_getString(file,"own",hinfo[hid][own],24);
  191.         ini_closeFile(file);
  192.         phouse[playerid]--;
  193.         SetPlayerPos(playerid,GetPVarFloat(playerid,"TheHPosx"),GetPVarFloat(playerid,"TheHPosy"),GetPVarFloat(playerid,"TheHPosz"));
  194.         SetPlayerInterior(playerid,GetPVarInt(playerid,"TheInt"));
  195.         SetPlayerVirtualWorld(playerid,0);
  196.         DestroyDynamicMapIcon(hinfo[hid][icon]);
  197.         hinfo[hid][icon] = CreateDynamicMapIcon(hinfo[hid][pos][0],hinfo[hid][pos][1],hinfo[hid][pos][2],31,0,-1,-1,-1,500.0);
  198.         athouse[playerid] = false;
  199.         SendClientMessage(playerid,-1,"Вы продали дом и получили половину его стоймости");
  200.         if(texts == true)
  201.         {
  202.             new hst[256];
  203.             format(hst,256,"{00ff00}Дом {ffffff}#%d\n{00ff00}Владелец: {ffffff}%s\n{00ff00}Стоймость: {ffffff}%d\n{00ff00}Класс: {ffffff}%s",hinfo[hid][num],hinfo[hid][own],hinfo[hid][cena],hclass(hid));
  204.             UpdateDynamic3DTextLabelText(hinfo[hid][htext],-1,hst);
  205.         }
  206.         return 1;
  207.     }
  208.     return 1;
  209. }
  210.  
  211. dcmd_asellhouse(playerid,params[])
  212. {
  213.     if(!IsPlayerAdmin(playerid)) return 0;
  214.     if(!strlen(params)) return SendClientMessage(playerid,-1,"*/asellhouse [id]");
  215.     new home = strval(params);
  216.     for(new x;x!=m_house;x++)
  217.     {
  218.         if(home == x)
  219.         {
  220.             if(!(strcmp(hinfo[x][own], "Nobody", true) == 0))
  221.             {
  222.                 new str[50];
  223.                 format(str,50,"houses/h_%d.ini",x);
  224.                 if(fexist(str))
  225.                 {
  226.                     new file = ini_openFile(str);
  227.                     new s[24];
  228.                     format(s,24,"Nobody");
  229.                     ini_setString(file,"own",s);
  230.                     ini_closeFile(file);
  231.                     hinfo[x][own] = s;
  232.                     new st[100];
  233.                     format(st,100,"{ffffff}Дом {00ff00}%d {ffffff}успешно продан",home);
  234.                     SendClientMessage(playerid,-1,st);
  235.                     DestroyDynamicMapIcon(hinfo[x][icon]);
  236.                     hinfo[x][icon] = CreateDynamicMapIcon(hinfo[x][pos][0],hinfo[x][pos][1],hinfo[x][pos][2],31,0,-1,-1,-1,500.0);
  237.                     if(texts == true)
  238.                     {
  239.                         new hst[256];
  240.                         format(hst,256,"{00ff00}Дом {ffffff}#%d\n{00ff00}Владелец: {ffffff}%s\n{00ff00}Стоймость: {ffffff}%d\n{00ff00}Класс: {ffffff}%s",hinfo[x][num],hinfo[x][own],hinfo[x][cena],hclass(x));
  241.                         UpdateDynamic3DTextLabelText(hinfo[x][htext],-1,hst);
  242.                     }
  243.                     break;
  244.                 }
  245.             }
  246.             break;
  247.         }
  248.     }
  249.     return 1;
  250. }
  251.  
  252. dcmd_setint(playerid,params[])
  253. {
  254.     if(!IsPlayerAdmin(playerid)) return 0;
  255.     if(!strlen(params[0])) return SendClientMessage(playerid,-1,"*/setint [id] [id int]");
  256.     if(!strlen(params[1])) return SendClientMessage(playerid,-1,"*/setint [id] [id int]");
  257.     for(new x;x!=m_house;x++)
  258.     {
  259.         if(strval(params[0]) == x)
  260.         {
  261.             new str[50];
  262.             format(str,50,"houses/h_%d.ini",x);
  263.             if(fexist(str))
  264.             {
  265.                 new file = ini_openFile(str);
  266.                 ini_setFloat(file,"ex",housepos[strval(params[1])][0]);
  267.                 ini_setFloat(file,"ey",housepos[strval(params[1])][1]);
  268.                 ini_setFloat(file,"ez",housepos[strval(params[1])][2]);
  269.                 ini_setInteger(file,"int",hinter[strval(params[1])]);
  270.                 ini_closeFile(file);
  271.                 hinfo[x][ent][0] = housepos[strval(params[1])][0];
  272.                 hinfo[x][ent][1] = housepos[strval(params[1])][1];
  273.                 hinfo[x][ent][2] = housepos[strval(params[1])][2];
  274.                 hinfo[x][int] = hinter[strval(params[1])];
  275.                 new st[100];
  276.                 format(st,100,"{ffffff}Интерьер дома {00ff00}%d {ffffff}сменен на {00ff00}%d",strval(params[0]),strval(params[1]));
  277.                 SendClientMessage(playerid,-1,st);
  278.                 break;
  279.             }
  280.             else
  281.             break;
  282.         }
  283.     }
  284.     return 1;
  285. }
  286.  
  287. dcmd_setcena(playerid,params[])
  288. {
  289.     if(!IsPlayerAdmin(playerid)) return 0;
  290.     if(!strlen(params[0])) return SendClientMessage(playerid,-1,"*/setcena [id] [value]");
  291.     if(!strlen(params[1])) return SendClientMessage(playerid,-1,"*/setcena [id] [value]");
  292.     for(new x;x!=m_house;x++)
  293.     {
  294.         if(strval(params[0]) == x)
  295.         {
  296.             new str[50];
  297.             format(str,50,"houses/h_%d.ini",x);
  298.             if(fexist(str))
  299.             {
  300.                 new file = ini_openFile(str);
  301.                 ini_setInteger(file,"cena",strval(params[1]));
  302.                 ini_closeFile(file);
  303.                 hinfo[x][cena] = strval(params[1]);
  304.                 new st[100];
  305.                 format(st,100,"{ffffff}Цена дома {00ff00}%d {ffffff}сменена на {00ff00}%d",strval(params[0]),strval(params[1]));
  306.                 SendClientMessage(playerid,-1,st);
  307.                 if(texts == true)
  308.                 {
  309.                     new hst[256];
  310.                     format(hst,256,"{00ff00}Дом {ffffff}#%d\n{00ff00}Владелец: {ffffff}%s\n{00ff00}Стоймость: {ffffff}%d\n{00ff00}Класс: {ffffff}%s",hinfo[x][num],hinfo[x][own],hinfo[x][cena],hclass(x));
  311.                     UpdateDynamic3DTextLabelText(hinfo[x][htext],-1,hst);
  312.                 }
  313.                 break;
  314.             }
  315.             else
  316.             break;
  317.         }
  318.     }
  319.     return 1;
  320. }
  321.  
  322. dcmd_setclass(playerid,params[])
  323. {
  324.     if(!IsPlayerAdmin(playerid)) return 0;
  325.     if(!strlen(params[0])) return SendClientMessage(playerid,-1,"*/setclass [id] [class]");
  326.     if(!strlen(params[1])) return SendClientMessage(playerid,-1,"*/setclass [id] [class]");
  327.     for(new x;x!=m_house;x++)
  328.     {
  329.         if(strval(params[0]) == x)
  330.         {
  331.             new str[50];
  332.             format(str,50,"houses/h_%d.ini",x);
  333.             if(fexist(str))
  334.             {
  335.                 new file = ini_openFile(str);
  336.                 ini_setInteger(file,"class",strval(params[1]));
  337.                 ini_closeFile(file);
  338.                 hinfo[x][clas] = strval(params[1]);
  339.                 new st[100];
  340.                 format(st,100,"{ffffff}Класс дома {00ff00}%d {ffffff}сменен на {00ff00}\"%s\"",strval(params[0]),hclass(x));
  341.                 SendClientMessage(playerid,-1,st);
  342.                 if(texts == true)
  343.                 {
  344.                     new hst[256];
  345.                     format(hst,256,"{00ff00}Дом {ffffff}#%d\n{00ff00}Владелец: {ffffff}%s\n{00ff00}Стоймость: {ffffff}%d\n{00ff00}Класс: {ffffff}%s",hinfo[x][num],hinfo[x][own],hinfo[x][cena],hclass(x));
  346.                     UpdateDynamic3DTextLabelText(hinfo[x][htext],-1,hst);
  347.                 }
  348.                 break;
  349.             }
  350.             else
  351.             break;
  352.         }
  353.     }
  354.     return 1;
  355. }
  356.  
  357. dcmd_add(playerid,params[])
  358. {
  359.     if(!IsPlayerAdmin(playerid)) return 0;
  360.     if(!strlen(params[0])) return SendClientMessage(playerid,-1,"Ну а интерьер за тебя таджики укажут");
  361.     if(!strlen(params[1])) return SendClientMessage(playerid,-1,"Цену за тебя таджики укажут");
  362.     if(count == m_house) return SendClientMessage(playerid,-1,"Лимит домиков на сервере");
  363.     new numb = strval(params[1]);
  364.  
  365.     if(strval(params[0]) < 0 || strval(params[0]) > 16) return SendClientMessage(playerid,-1,"Интерьер от 1 до 15 включительно");
  366.     new Float:ps[3];
  367.     GetPlayerPos(playerid,ps[0],ps[1],ps[2]);
  368.     count++;
  369.     new str[256];
  370.     format(str,256,"houses/h_%d.ini",count);
  371.     new file = ini_createFile(str);
  372.     if(file<0) ini_openFile(str);
  373.     ini_setInteger(file,"num",count);
  374.     ini_setString(file,"own","Nobody");
  375.     ini_setFloat(file,"px",ps[0]);
  376.     ini_setFloat(file,"py",ps[1]);
  377.     ini_setFloat(file,"pz",ps[2]);
  378.     ini_setFloat(file,"ex",housepos[strval(params[0])][0]);
  379.     ini_setFloat(file,"ey",housepos[strval(params[0])][1]);
  380.     ini_setFloat(file,"ez",housepos[strval(params[0])][2]);
  381.     ini_setInteger(file,"int",hinter[strval(params[0])]);
  382.     ini_setInteger(file,"class",1);
  383.     ini_setInteger(file,"cena",numb);
  384.     ini_setInteger(file,"sell",numb/2);
  385.     ini_closeFile(file);
  386.     SetPVarInt(playerid,"ChangeClass",count);
  387.     SetPVarInt(playerid,"ZHOUSE",1);
  388.     ShowPlayerDialog(playerid,6336,DIALOG_STYLE_INPUT,"  ","Введите класс для дома","Ок", "  ");
  389.     return 1;
  390. }
  391.  
  392. loading(x)
  393. {
  394.     new str[50];
  395.     format(str,50,"houses/h_%d.ini",x);
  396.     if(!fexist(str)) return 0;
  397.     new file = ini_openFile(str);
  398.     ini_getInteger(file,"num",hinfo[x][num]);
  399.     ini_getString(file,"own",hinfo[x][own],24);
  400.     ini_getFloat(file,"px",hinfo[x][pos][0]);
  401.     ini_getFloat(file,"py",hinfo[x][pos][1]);
  402.     ini_getFloat(file,"pz",hinfo[x][pos][2]);
  403.     ini_getFloat(file,"ex",hinfo[x][ent][0]);
  404.     ini_getFloat(file,"ey",hinfo[x][ent][1]);
  405.     ini_getFloat(file,"ez",hinfo[x][ent][2]);
  406.     ini_getInteger(file,"int",hinfo[x][int]);
  407.     ini_getInteger(file,"class",hinfo[x][clas]);
  408.     ini_getInteger(file,"cena",hinfo[x][cena]);
  409.     ini_getInteger(file,"sell",hinfo[x][sell]);
  410.     if(texts == true)
  411.     {
  412.         new hst[256];
  413.         format(hst,256,"{00ff00}Дом {ffffff}#%d\n{00ff00}Владелец: {ffffff}%s\n{00ff00}Стоймость: {ffffff}%d\n{00ff00}Класс: {ffffff}%s",hinfo[x][num],hinfo[x][own],hinfo[x][cena],hclass(x));
  414.         hinfo[x][htext] = CreateDynamic3DTextLabel(hst, 0xffffffff, hinfo[x][pos][0],hinfo[x][pos][1],hinfo[x][pos][2], 10.0);
  415.     }
  416.     hinfo[x][pick] = CreatePickup(1273,23,hinfo[x][pos][0],hinfo[x][pos][1],hinfo[x][pos][2]);
  417.     if(strcmp(hinfo[x][own], "Nobody", true) == 0)
  418.     hinfo[x][icon] = CreateDynamicMapIcon(hinfo[x][pos][0],hinfo[x][pos][1],hinfo[x][pos][2],31,0,-1,-1,-1,500.0);
  419.     else
  420.     hinfo[x][icon] = CreateDynamicMapIcon(hinfo[x][pos][0],hinfo[x][pos][1],hinfo[x][pos][2],32,0,-1,-1,-1,500.0);
  421.     ini_closeFile(file);
  422.     printf("House %d - loaded",count);
  423.     return 1;
  424. }
  425.  
  426. public OnPlayerPickUpPickup(playerid, pickupid)
  427. {
  428.     if(GetPVarInt(playerid,"ZHOUSE") == 0)
  429.     {
  430.         new x = IsPlayerNearHouse(playerid);
  431.         if(x!=-1)
  432.         {
  433.             if(pickupid == hinfo[x][pick])
  434.             {
  435.                 new name[24];
  436.                 GetPlayerName(playerid,name,24);
  437.                 if(strcmp(hinfo[x][own], name, true) == 0)
  438.                 {//его дом
  439.                     GameTextForPlayer(playerid,"~n~~n~~n~~n~~n~~n~~n~~n~~n~~w~Press ~y~ALT ~w~to enter",5000,3);
  440.                 }
  441.                 else if(strcmp(hinfo[x][own], "Nobody", true) == 0)
  442.                 {//ничей
  443.                     new str[256];
  444.                     format(str,256,"{ffffff}Номер дома:\t {00ff00}%d\n{ffffff}Цена дома:\t {00ff00}%d\n{ffffff}Класс дома:\t {00ff00}%s",hinfo[x][num],hinfo[x][cena],hclass(x));
  445.                     ShowPlayerDialog(playerid,174,DIALOG_STYLE_MSGBOX,"  ",str,"Купить","Выход");
  446.                 }
  447.                 else
  448.                 {
  449.                     new str[256];
  450.                     format(str,256,"{ffffff}Номер дома:\t {00ff00}%d\n{ffffff}Цена дома:\t {00ff00}%d\n{ffffff}Класс дома:\t {00ff00}%s\n{ffffff}Владелец:\t {00ff00}%s",hinfo[x][num],hinfo[x][cena],hclass(x),hinfo[x][own]);
  451.                     ShowPlayerDialog(playerid,174,DIALOG_STYLE_MSGBOX,"  ",str,"Прочел","");
  452.                 }
  453.             }
  454.         }
  455.     }
  456.     return 1;
  457. }
  458.  
  459. stock hclass(x)
  460. {
  461.     new str[140];
  462.     switch(hinfo[x][clas])
  463.     {
  464.         case 1:format(str,256,"Элитный");
  465.         case 2:format(str,256,"Средний");
  466.         case 3:format(str,256,"Хреновый");
  467.     }
  468.     return str;
  469. }
  470.  
  471. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  472. {
  473.     if(newkeys == KEY_WALK)
  474.     {
  475.         if(athouse[playerid] == true)
  476.         {
  477.             SetPlayerPos(playerid,GetPVarFloat(playerid,"TheHPosx"),GetPVarFloat(playerid,"TheHPosy"),GetPVarFloat(playerid,"TheHPosz"));
  478.             SetPlayerInterior(playerid,GetPVarInt(playerid,"TheInt"));
  479.             SetPlayerVirtualWorld(playerid,0);
  480.             athouse[playerid] = false;
  481.         }
  482.         else
  483.         {
  484.             new x = IsPlayerNearHouse(playerid);
  485.             if(x == -1) return 1;
  486.             new Float:pz[3];
  487.             GetPlayerPos(playerid,pz[0],pz[1],pz[2]);
  488.             SetPVarFloat(playerid,"TheHPosx",pz[0]);
  489.             SetPVarFloat(playerid,"TheHPosy",pz[1]);
  490.             SetPVarFloat(playerid,"TheHPosz",pz[2]);
  491.             SetPVarInt(playerid,"TheInt",GetPlayerInterior(playerid));
  492.             SetPlayerPos(playerid,hinfo[x][ent][0],hinfo[x][ent][1],hinfo[x][ent][2]);
  493.             SetPlayerInterior(playerid,hinfo[x][int]);
  494.             SetPlayerVirtualWorld(playerid,playerid+random(150));
  495.             SetPVarInt(playerid,"Selling",hinfo[x][num]);
  496.             athouse[playerid] = true;
  497.             GameTextForPlayer(playerid,"~n~~n~~n~~n~~n~~n~~n~~n~~n~~w~Press ~y~ALT ~w~to exit",5000,3);
  498.         }
  499.     }
  500.     return 1;
  501. }
  502.  
  503. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  504. {
  505.     if(dialogid == 174)
  506.     {
  507.         if(!response) return 1;
  508.         if(response)
  509.         {//купил
  510.             new hid = IsPlayerNearHouse(playerid);
  511.             if(hid == -1) return SendClientMessage(playerid,-1,"...Встаньте на пикап");
  512.             if(GetPlayerMoney(playerid)<hinfo[hid][cena]) return SendClientMessage(playerid,-1,"...Недостаточно денег для приобретения дома");
  513.             if(phouse[playerid] == MAX_P_H) return SendClientMessage(playerid,-1,"Максимум");
  514.             if(strcmp(hinfo[hid][own], "Nobody", true) == 0)
  515.             {
  516.                 GivePlayerMoney(playerid,-hinfo[hid][cena]);
  517.                 new str[100];
  518.                 new name[24];
  519.                 GetPlayerName(playerid,name,24);
  520.                 format(str,100,"houses/h_%d.ini",hid);
  521.                 new file = ini_openFile(str);
  522.                 ini_setString(file,"own",name);
  523.                 hinfo[hid][own]=name;
  524.                 ini_closeFile(file);
  525.                 SendClientMessage(playerid,-1,"Вы успешно приобрели дом!");
  526.                 phouse[playerid]++;
  527.                 DestroyDynamicMapIcon(hinfo[hid][icon]);
  528.                 hinfo[hid][icon] = CreateDynamicMapIcon(hinfo[hid][pos][0],hinfo[hid][pos][1],hinfo[hid][pos][2],32,0,-1,-1,-1,500.0);
  529.                 if(texts == true)
  530.                 {
  531.                     new hst[256];
  532.                     format(hst,256,"{00ff00}Дом {ffffff}#%d\n{00ff00}Владелец: {ffffff}%s\n{00ff00}Стоймость: {ffffff}%d\n{00ff00}Класс: {ffffff}%s",hinfo[hid][num],hinfo[hid][own],hinfo[hid][cena],hclass(hid));
  533.                     UpdateDynamic3DTextLabelText(hinfo[hid][htext],-1,hst);
  534.                 }
  535.                 return 1;
  536.             }
  537.             else SendClientMessage(playerid,-1,"...Это ваш дом");
  538.             return 1;
  539.         }
  540.     }
  541.     if(dialogid == 6336)
  542.     {
  543.         if(!response) return ShowPlayerDialog(playerid,6336,DIALOG_STYLE_INPUT,"  ","Введите класс для дома","Ок", "  ");
  544.         if(response)
  545.         {
  546.             if(!strlen(inputtext)) ShowPlayerDialog(playerid,6336,DIALOG_STYLE_INPUT,"  ","Введите класс для дома","Ок", "  ");
  547.             if(strval(inputtext) < 1 || strval(inputtext) > 3) return ShowPlayerDialog(playerid,6336,DIALOG_STYLE_INPUT,"  ","Введите класс для дома","Ок", "  ");
  548.             if(GetPVarInt(playerid,"ChangeClass")!=SEREGAMIL)
  549.             {
  550.                 new str[50];
  551.                 format(str,50,"houses/h_%d.ini",GetPVarInt(playerid,"ChangeClass"));
  552.                 if(fexist(str))
  553.                 {
  554.                     new file = ini_openFile(str);
  555.                     ini_setInteger(file,"class",strval(inputtext));
  556.                     ini_closeFile(file);
  557.                     loading(GetPVarInt(playerid,"ChangeClass"));
  558.                     ShowPlayerDialog(playerid,5628,DIALOG_STYLE_MSGBOX,"  ","Дом успешно создан","OK","");
  559.                 }
  560.             }
  561.         }
  562.         SetPVarInt(playerid,"ChangeClass",SEREGAMIL);
  563.         SetPVarInt(playerid,"ZHOUSE",0);
  564.         return true;
  565.     }
  566.     return 1;
  567. }
  568.  
  569. forward IsPlayerNearHouse(playerid);
  570. public IsPlayerNearHouse(playerid)
  571. {
  572.     new Float:Distance;
  573.     for(new x; x!=m_house; x++)
  574.     {
  575.         Distance = GetDistanceToHouse(playerid, x);
  576.         if(Distance < 1.5) return x;
  577.     }
  578.     return -1;
  579. }
  580.  
  581. forward Float:GetDistanceToHouse(playerid, Property);
  582. public Float:GetDistanceToHouse(playerid, Property)
  583. {
  584.     new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
  585.     GetPlayerPos(playerid,x1,y1,z1);
  586.     x2 = hinfo[Property][pos][0];
  587.     y2 = hinfo[Property][pos][1];
  588.     z2 = hinfo[Property][pos][2];
  589.     return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
  590. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement