derpierre65

[FILTERSCRIPT] HouseSystem

Feb 1st, 2012
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.67 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dini>
  3. #include <bfx_imStream>
  4. #include <sscanf>
  5. #define FILTERSCRIPT
  6.  
  7. #define MAX_HOUSE 500
  8.  
  9. #define green 0x00AF00FF
  10. #define blue  0xBC1100FF
  11. #define error 0xC30000FF
  12. #define info  0x00C000FF
  13.  
  14. #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
  15.  
  16. new file[255];
  17. new hausInfos[MAX_PLAYERS] = 0;
  18. new lastVirtualWorld = 0;
  19.  
  20. forward loadHouse(id);
  21. forward saveHouse(id);
  22. forward unloadHouse(id);
  23. forward reloadHouse(id);
  24. forward resetInfos(playerid);
  25.  
  26. enum houseIdConf {
  27.     hInterior, Float:x,Float:y,Float:z
  28. }
  29. new hEnter[][houseIdConf] = {
  30. {3, 235.2818,1187.2037,1080.2578},
  31. {2, 225.756989, 1240.000000, 1082.149902},
  32. {1, 223.1909 ,1287.2478, 1082.1406},
  33. {7, 225.630997, 1022.479980, 1084.069946},
  34. {15, 294.6726,1473.5618,1080.2578},
  35. {15, 328.0414,1478.0096,1084.4375},
  36. {15, 385.803986, 1471.769897, 1080.209961},
  37. {1,2233.8032, 1712.2303, 1011.7632}
  38. };
  39. enum House {
  40.     hPickupid,
  41.     Text3D:hText,
  42.     hMapID,
  43.     hOwner[255],
  44.     hPreis[255],
  45.     Float:hX,
  46.     Float:hY,
  47.     Float:hZ,
  48.     hLocked,
  49.     hPickupExit,
  50.     hEnterID,
  51.     hVirtualWorld
  52. }
  53.  
  54. new hInfo[MAX_HOUSE][House];
  55.  
  56. public OnFilterScriptInit() {
  57.     for (new i=1;i<=MAX_HOUSE;i++) {
  58.         format(file,sizeof file, "House/House%d.cfg", i);
  59.         if ( dini_Exists(file) ) { loadHouse(i); }
  60.     }
  61.     return 1;
  62. }
  63.  
  64. public OnFilterScriptExit()
  65. {
  66.     for (new i=1;i<=MAX_HOUSE;i++) {
  67.         format(file,sizeof file, "House/House%d.cfg", i);
  68.         if ( dini_Exists(file) ) { saveHouse(i); unloadHouse(i); }
  69.     }
  70.     return 1;
  71. }
  72.  
  73. public resetInfos(playerid) {
  74.     hausInfos[playerid] = 0;
  75.     return 1;
  76. }
  77.  
  78. public saveHouse(id) {
  79.     format(file,sizeof file, "House/House%d.cfg", id);
  80.     if ( dini_Exists(file) ) {
  81.         dini_Set(file, "Owner", hInfo[id][hOwner]);
  82.     }
  83.     return 1;
  84. }
  85.  
  86. public reloadHouse(id) {
  87.     unloadHouse(id);
  88.     loadHouse(id);
  89.     return 1;
  90. }
  91.  
  92. public unloadHouse(id) {
  93.     if ( dini_Exists("House/") ) {
  94.         format(file,sizeof file, "House/House%d.cfg", id);
  95.         if ( dini_Exists(file) ) {
  96.             bRemoveMapIcon(hInfo[id][hMapID]);
  97.             DestroyPickup(hInfo[id][hPickupid]);
  98.             DestroyPickup(hInfo[id][hPickupExit]);
  99.             Delete3DTextLabel(hInfo[id][hText]);
  100.         }
  101.     }
  102.     return 1;
  103. }
  104.  
  105. public loadHouse(id) {
  106.     new pID, mID, color;
  107.     if ( dini_Exists("House/") ) {
  108.         format(file,sizeof file, "House/House%d.cfg", id);
  109.         if ( dini_Exists(file) ) {
  110.             hInfo[id][hOwner] = dini_Get(file, "Owner");
  111.             hInfo[id][hPreis] = dini_Int(file, "Preis");
  112.             hInfo[id][hEnterID] = dini_Int(file, "Int");
  113.             hInfo[id][hLocked] = dini_Int(file, "Locked");
  114.             hInfo[id][hX] = dini_Float(file, "hX");
  115.             hInfo[id][hY] = dini_Float(file, "hY");
  116.             hInfo[id][hZ] = dini_Float(file, "hZ");
  117.             if(!strcmp(hInfo[id][hOwner], "Staat", false)) {
  118.                 pID = 1273;
  119.                 mID = 31;
  120.                 color = green;
  121.             }
  122.             else { pID = 1272; mID = 32; color = blue; }
  123.             lastVirtualWorld = dini_Int(file, "VW");
  124.             hInfo[id][hVirtualWorld] = lastVirtualWorld;
  125.             hInfo[id][hMapID] = bCreateMapIcon(hInfo[id][hX],hInfo[id][hY],hInfo[id][hZ], mID, 0);
  126.             hInfo[id][hPickupid] = CreatePickup(pID, 1, hInfo[id][hX],hInfo[id][hY],hInfo[id][hZ], 0);
  127.             hInfo[id][hPickupExit] = CreatePickup(1318, 1, hEnter[hInfo[id][hEnterID]][x],hEnter[hInfo[id][hEnterID]][y],hEnter[hInfo[id][hEnterID]][z], hInfo[id][hVirtualWorld]);
  128.             new string[255];
  129.             if ( mID == 31 ) { format(string,sizeof string, "Besitzer: %s\nPreis: %d$", hInfo[id][hOwner], hInfo[id][hPreis]); }
  130.             else { format(string,sizeof string, "Besitzer: %s\nPreis: Nicht zum Verkauf", hInfo[id][hOwner]); }
  131.             hInfo[id][hText] = Create3DTextLabel(string, color, hInfo[id][hX],hInfo[id][hY],hInfo[id][hZ] + 0.5,10.0,0);
  132.         }
  133.     }
  134.     return 1;
  135. }
  136.  
  137. public OnPlayerCommandText(playerid, cmdtext[])
  138. {
  139.     dcmd(lock,4,cmdtext);
  140.     dcmd(createhouse, 11, cmdtext);
  141.     return 0;
  142. }
  143.  
  144. public OnPlayerDeath(playerid, killerid, reason) {
  145.     SetPlayerVirtualWorld(playerid, 0);
  146.     return 1;
  147. }
  148.  
  149. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  150.     new houseID = hausInfos[playerid], string[255], name[255];
  151.     switch(dialogid) {
  152.         case 1800: {
  153.             if ( response == 1 ) {
  154.                 if(!strcmp(hInfo[houseID][hOwner], "Staat", false)) {
  155.                     if ( GetPlayerMoney(playerid) >=hInfo[houseID][hPreis] ) {
  156.                         GetPlayerName(playerid, name, 255);
  157.                         hInfo[houseID][hOwner] = name;
  158.                         GivePlayerMoney(playerid, -hInfo[houseID][hPreis]);
  159.                         saveHouse(houseID);
  160.                         reloadHouse(houseID);
  161.                         GameTextForPlayer(playerid, "Immobilien gekauft", 2000, 1);
  162.                     }
  163.                     else { SendClientMessage(playerid, error, "Du hast nicht genug Geld."); }
  164.                 }
  165.                 else { SendClientMessage(playerid, error, "Das Haus steht nicht zum Verkauf."); }
  166.             }
  167.             SetTimerEx("resetInfos", 2000, 0, "i", playerid);
  168.         }
  169.         case 1801: {
  170.             if ( response == 1 ) {
  171.                 GetPlayerName(playerid, name, 255);
  172.                 if(!strcmp(hInfo[houseID][hOwner], name, false)) {
  173.                     SendClientMessage(playerid, info, "Du bist jetzt in deinem Haus.");
  174.                     SetPlayerInterior(playerid, hEnter[hInfo[houseID][hEnterID]][hInterior]);
  175.                     SetPlayerPos(playerid, hEnter[hInfo[houseID][hEnterID]][x],hEnter[hInfo[houseID][hEnterID]][y],hEnter[hInfo[houseID][hEnterID]][z]);
  176.                     SetPlayerVirtualWorld(playerid, hInfo[houseID][hVirtualWorld]);
  177.                 }
  178.                 else {
  179.                     if ( hInfo[houseID][hLocked] == 1 ) { SendClientMessage(playerid, error, "Das Haus ist abgeschlossen."); }
  180.                     else {
  181.                         SendClientMessage(playerid, info, "Du hast das Haus betreten.");
  182.                         SetPlayerInterior(playerid, hEnter[hInfo[houseID][hEnterID]][hInterior]);
  183.                         SetPlayerPos(playerid, hEnter[hInfo[houseID][hEnterID]][x],hEnter[hInfo[houseID][hEnterID]][y],hEnter[hInfo[houseID][hEnterID]][z]);
  184.                         SetPlayerVirtualWorld(playerid, hInfo[houseID][hVirtualWorld]);
  185.                     }
  186.                 }
  187.             }
  188.             SetTimerEx("resetInfos", 2000, 0, "i", playerid);
  189.         }
  190.         case 1802: {
  191.             if ( response == 1 ) {
  192.                 SetPlayerVirtualWorld(playerid, 0);
  193.                 SetPlayerInterior(playerid, 0);
  194.                 SetPlayerPos(playerid, hInfo[houseID][hX],hInfo[houseID][hY],hInfo[houseID][hZ]);
  195.                 format(string,sizeof string, "Du hast das Haus von %s verlassen", hInfo[houseID][hOwner]);
  196.                 SendClientMessage(playerid, info, string);
  197.                
  198.                 SetTimerEx("resetInfos", 3500, 0, "i", playerid);
  199.             }
  200.             else { SetTimerEx("resetInfos", 2000, 0, "i", playerid); }
  201.         }
  202.         case 1803: {
  203.             if ( response == 1 ) {
  204.                 new house = strval(inputtext);
  205.                 GetPlayerName(playerid, name, 255);
  206.                 format(string,sizeof string, "House/House%d.cfg", house);
  207.                 if ( dini_Exists(string) ) {
  208.                     new owner[255];
  209.                     owner = dini_Get(string, "Owner");
  210.                     if( !strcmp(owner, name, false)) {
  211.                         if ( hInfo[house][hLocked] == 1 ) { hInfo[house][hLocked] = 0; SendClientMessage(playerid, info, "Dein Haus wurde aufgeschlossen."); }
  212.                         else { hInfo[house][hLocked] = 1; SendClientMessage(playerid, info, "Dein Haus wurde abgeschlossen."); }
  213.                     }
  214.                     else { SendClientMessage(playerid, error, "Das Haus gehört nicht dir."); }
  215.                 }
  216.                 else { SendClientMessage(playerid, error, "Es existiert kein Haus mit dieser Hausnummer."); }
  217.             }
  218.         }
  219.     }
  220.     return 1;
  221. }
  222.  
  223. public OnPlayerPickUpPickup(playerid, pickupid) {
  224.     new string[255], houseEnter = -1, houseExit = -1, button[255], verkaufstatus[255];
  225.     for (new i=1;i<MAX_HOUSE;i++) {
  226.         format(file,sizeof file, "House/House%d.cfg", i);
  227.         if ( dini_Exists(file) ) {
  228.             if ( hInfo[i][hPickupid] == pickupid ) { houseEnter = i; format(string,sizeof string, "%d - %d",hInfo[i][hPickupid], pickupid); }
  229.             if ( hInfo[i][hPickupExit] == pickupid ) { houseExit = i; format(string,sizeof string, "%d - %d",hInfo[i][hPickupExit], pickupid); }
  230.         }
  231.     }
  232.     if ( houseEnter != -1 && hausInfos[playerid] <= 0 ) {
  233.         new houseNR = houseEnter;
  234.         hausInfos[playerid] = houseNR;
  235.         format(button, 255, ""); format(verkaufstatus,255, "Nicht zum Verkauf");
  236.         if(!strcmp(hInfo[houseNR][hOwner], "Staat", false)) {
  237.             format(verkaufstatus,255, "%d$", hInfo[houseNR][hPreis]);
  238.             format(string,sizeof string, "Hausnummer:\t\t %d\nBesitzer:\t\t %s\nPreis:\t\t\t %s", houseNR, hInfo[houseNR][hOwner], verkaufstatus);
  239.             ShowPlayerDialog(playerid, 1800, DIALOG_STYLE_MSGBOX, "Haus Informationen", string, "Kaufen", "Schließen");
  240.         }
  241.         else {
  242.             format(button, 255, ""); format(verkaufstatus,255, "Nicht zum Verkauf");
  243.             format(string,sizeof string, "Hausnummer:\t\t %d\nBesitzer:\t\t %s\nPreis:\t\t\t %s", houseNR, hInfo[houseNR][hOwner], verkaufstatus);
  244.             ShowPlayerDialog(playerid, 1801, DIALOG_STYLE_MSGBOX, "Haus Informationen", string, "Betreten", "Schließen");
  245.         }
  246.     }
  247.     else if ( houseExit != -1 && hausInfos[playerid] <= 0 ) {
  248.         new houseNR = houseExit;
  249.         hausInfos[playerid] = houseNR;
  250.         format(string,sizeof string, "Willst du das Haus von %s verlassen?", hInfo[houseNR][hOwner]);
  251.         ShowPlayerDialog(playerid, 1802, DIALOG_STYLE_MSGBOX, "Haus Informationen", string, "Ja", "Nein");
  252.     }
  253.     return 1;
  254. }
  255.  
  256. dcmd_lock(playerid, params[]) {
  257.     #pragma unused params
  258.     PlayerWillLockHouse(playerid);
  259.     return 1;
  260. }
  261.  
  262. dcmd_createhouse(playerid, params[]) {
  263.     new preis, string[255], interior;
  264.     if ( IsPlayerAdmin(playerid) ) {
  265.         format(string, sizeof(string), "Bitte benutze /Createhouse [Geld] [HausID].");
  266.         if ( sscanf(params, "ii", preis, interior) ) { SendClientMessage(playerid, error, string); }
  267.         else {
  268.             if ( interior <= sizeof hEnter - 1 ) {
  269.                 new Float:pX, Float:pY, Float:pZ;
  270.                 GetPlayerPos(playerid, pX, pY, pZ);
  271.                 new first = -1;
  272.                 for (new i=1;i<=MAX_HOUSE;i++) {
  273.                     format(file,sizeof file, "House/House%d.cfg", i);
  274.                     if ( !dini_Exists(file) && first == -1 ) { first = i; }
  275.                 }
  276.                 format(file,sizeof file, "House/House%d.cfg", first);
  277.                 format(string,255,"Staat");
  278.                 dini_Create(file);
  279.                 dini_Set(file, "Owner", string);
  280.                 dini_IntSet(file, "Preis", preis);
  281.                 dini_IntSet(file, "Int", interior);
  282.                 dini_IntSet(file, "Locked", 1);
  283.                 dini_IntSet(file, "VW", lastVirtualWorld + 1);
  284.                 dini_FloatSet(file, "hX", pX);
  285.                 dini_FloatSet(file, "hY", pY);
  286.                 dini_FloatSet(file, "hZ", pZ);
  287.  
  288.                 hInfo[first][hOwner] = string;
  289.                 hInfo[first][hPreis] = preis;
  290.                 hInfo[first][hEnterID] = interior;
  291.                 hInfo[first][hVirtualWorld] = lastVirtualWorld + 1;
  292.                 hInfo[first][hX] = pX,hInfo[first][hY] = pY,hInfo[first][hZ] = pZ;
  293.                 loadHouse(first);
  294.                 lastVirtualWorld ++;
  295.             }
  296.             else { SendClientMessage(playerid, error, "Falsche Interior Zahl."); }
  297.         }
  298.     } else { SendClientMessage(playerid, error, "Du bist kein Admin."); }
  299.     return 1;
  300. }
  301.  
  302. forward PlayerWillLockHouse(playerid);
  303. public PlayerWillLockHouse(playerid) {
  304.     new Float:pX, Float:pY, Float:pZ, name[255], hasHouse;
  305.     GetPlayerPos(playerid, pX, pY, pZ);
  306.     GetPlayerName(playerid, name, 255);
  307.     for (new i=1;i<MAX_HOUSE;i++) {
  308.         format(file,sizeof file, "House/House%d.cfg", i);
  309.         if ( dini_Exists(file) ) {
  310.             if( !strcmp(hInfo[i][hOwner], name, false)) { hasHouse ++; }
  311.         }
  312.     }
  313.     if ( hasHouse >= 1 ) { ShowPlayerDialog(playerid, 1803, DIALOG_STYLE_INPUT, "Haus", "Bitte gib eine Haus Nummer ein.", "Bestätigen", "Abbrechen"); }
  314.     else { SendClientMessage(playerid, error, "Du hast kein Haus"); }
  315.     return 1;
  316. }
Advertisement
Add Comment
Please, Sign In to add comment