Guest User

Whatcha

a guest
Nov 28th, 2010
5,930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 23.86 KB | None | 0 0
  1. /*
  2.     House system by mick88 and Whatcha
  3.     Michael Dabski 2010
  4.     Nickoals Whatcha Core Shaffer 2010
  5.    
  6.     Requirements:
  7.     -Incognito's streamer plugin
  8.     -zcmd command processor (zcmd.inc)
  9.     -sscanf 2.0 plugin
  10.     -MySQL plugin R5 or higher
  11. */
  12.  
  13. #include <a_samp>
  14. #include <streamer>
  15. #include <a_mysql>
  16. #include <sscanf2>
  17. #include <zcmd>
  18.  
  19. //Change this to whatever you like, but keep it as close to actual house number as possible for best efficiency:
  20. #define MAX_HOUSES                      500
  21.  
  22. //Mysql credentials:
  23. #define MYSQL_IP                        "host"
  24. #define MYSQL_USER                      "user"
  25. #define MYSQL_PASSWORD                  "password"
  26. #define MYSQL_DB                        "dbname"
  27. #define MYSQL_TABLE_NAME                "tablename"
  28.  
  29. //Exchanging player data with main script (change this if you use custom money/adminship script):
  30.  
  31. #define IS_ADMIN(%1)                    IsPlayerAdmin(%1)
  32. #define GET_MONEY(%1)                   GetPlayerMoney(%1)
  33. #define ADD_MONEY(%1,%2)                GivePlayerMoney(%1,(%2))
  34.  
  35. /*  Example:
  36.  
  37.     #define IS_ADMIN(%1)                    GetPVarInt(%1, "admin")
  38.     #define GET_MONEY(%1)                   GetPVarInt(%1, "money")
  39.     #define ADD_MONEY(%1,%2)                SetPVarInt(%1, "money", GET_MONEY(%1)+(%2))
  40. */
  41.  
  42. //Script settings:
  43. #define DEFAULT_HOUSE_PRICE             500000
  44. #define DEFAULT_HOUSE_INTERIOR          0
  45. #define HOUSE_SELL_PAYBACK              0.75
  46. #define EXIT_PICKUP_MODEL               1272
  47. #define HOUSE_PICKUP_MODEL              1273
  48.  
  49. #define MAX_INTERIORS                   15 //must equal number of house interiors
  50. #define HOUSE_RANGE                     1.0
  51. #define INVALID_HOUSE_ID                0
  52. #define HOUSE_WORLD_OFFSET              0
  53. #define HOUSE_LABEL_SIZE                64
  54. #define HOUSE_ENTER_LEAVE_KEY           KEY_SECONDARY_ATTACK //key used for entering house and leaving
  55.  
  56. #define HOUSE_LABEL_COLOR               0x008000FF
  57. #define COLOR_RED                       0xAA3333AA
  58. #define COLOR_WHITE                     0xFFFFFFFF
  59. /*
  60.     House system by mick88 and Whatcha
  61.     Michael Dabski 2010
  62.     Nickolas Whatcha Core Shaffer 2010
  63. */
  64. //macros
  65. #define ADMIN                           if (!IS_ADMIN(playerid)) return 0
  66. #define ERROR(%1)                       SendClientMessage(playerid, COLOR_RED, %1)
  67. #define MESSAGE(%1)                     SendClientMessage(playerid, COLOR_WHITE, %1)
  68. #define MSG                             msg, sizeof(msg)
  69. #define QUERY(%1)                       mysql_query(%1, -1, -1, mysql_connection)
  70. #define GET_INT(%1,%2)                  mysql_fetch_field_row(tmp, %2);%1 = strval(tmp)
  71. #define GET_STR(%1,%2)                  mysql_fetch_field_row(%1, %2)
  72. #define GET_FLOAT(%1,%2)                mysql_fetch_field_row(tmp, %2);%1 = floatstr(tmp)
  73. #define NEW_KEY(%1)                     ((newkeys & %1) && !(oldkeys & %1))
  74.  
  75. #define ADD_INTERIOR(%1,%2,%3,%4,%5,%6)                     \
  76.         Interiors[%1][int_x] = %2;                          \
  77.         Interiors[%1][int_y] = %3;                          \
  78.         Interiors[%1][int_z] = %4;                          \
  79.         Interiors[%1][int_r] = %5;                          \
  80.         Interiors[%1][int_interior] = %6;                   \
  81.         Interiors[%1][int_pickup]=CreateDynamicPickup(EXIT_PICKUP_MODEL,23,%2,%3,%4,-1,%6,-1)
  82.        
  83. #define SPAWN_HOUSE(%1)             \
  84.         Houses[%1][house_pickup] = CreateDynamicPickup(HOUSE_PICKUP_MODEL, 23,                  \
  85.                                     Houses[%1][house_x], Houses[%1][house_y],                   \
  86.                                     Houses[%1][house_z], 0, 0, -1);                             \
  87.         Houses[%1][house_label] = CreateDynamic3DTextLabel("", HOUSE_LABEL_COLOR,               \
  88.                                     Houses[%1][house_x], Houses[%1][house_y],                   \
  89.                                     Houses[%1][house_z]+0.75, 20,                               \
  90.                                     INVALID_PLAYER_ID, INVALID_VEHICLE_ID, true, 0, 0, -1);     \
  91.         UpdateHouseLabel(id)
  92.  
  93. #define CREATE_TABLE_QUERY  \
  94.     "CREATE TABLE IF NOT EXISTS `"#MYSQL_TABLE_NAME"`(`id` int(11) NOT NULL,    \
  95.     `x` float NOT NULL,`y` float NOT NULL,`z` float NOT NULL,           \
  96.     `r` float NOT NULL,`interior` smallint(6) NOT NULL,                 \
  97.     `price` int(11) NOT NULL,                                           \
  98.     `Slots` int(11) NOT NULL,                                           \
  99.     `owner` char(25) COLLATE latin1_general_cs NOT NULL,                \
  100.     UNIQUE KEY `id` (`id`))                                             \
  101.     ENGINE=MyISAM DEFAULT CHARSET=latin1                                \
  102.     COLLATE=latin1_general_cs AUTO_INCREMENT=1"
  103. /*
  104.     House system by mick88 and Whatcha
  105.     Michael Dabski 2010
  106.     Nickolas Whatcha Core Shaffer 2010
  107. */
  108. //Public functions - these can be used from outside the script, eg in Gamemode:
  109. forward GetPlayerHouseID(playerid);                 //return ID of the house that player is currently inside
  110. forward IsHouseOwnedByPlayer(playerid, houseid);
  111. forward PutPlayerInHouse(playerid, id);
  112. forward RemovePlayerFromHouse(playerid);
  113. forward GiveHouseToPlayer(playerid, houseid);
  114. forward TakeHouseFromPlayer(houseid);
  115. forward GetPlayerHouseEntrance(playerid);           //Returns ID of the house if player is in house pickup or 0 if not.
  116. forward CreateHouse(Float:x, Float:y, Float:z, Float:r, price, interior, Slots2);
  117. forward GetHousePos(houseid, &Float:x, &Float:y, &Float:z); //Returns XYZ coordinates of house entrance
  118. forward GetHouseFacingAngle(houseid, &Float:angle);
  119. /*
  120.     House system by mick88 and Whatcha
  121.     Michael Dabski 2010
  122.     Nickolas Whatcha Core Shaffer 2010
  123. */
  124. enum HouseData
  125. {
  126.     Float:house_x,
  127.     Float:house_y,
  128.     Float:house_z,
  129.     Float:house_r,
  130.     house_price,
  131.     house_interior,
  132.     house_owner[MAX_PLAYER_NAME],
  133.     house_pickup,
  134.     Text3D:house_label,
  135.     Slots
  136. }
  137. /*
  138.     House system by mick88 and Whatcha
  139.     Michael Dabski 2010
  140.     Nickolas Whatcha Core Shaffer 2010
  141. */
  142. enum PlayerData
  143. {
  144.     last_house_entrance,
  145.     in_house
  146. }
  147. /*
  148.     House system by mick88 and Whatcha
  149.     Michael Dabski 2010
  150.     Nickolas Whatcha Core Shaffer 2010
  151. */
  152. enum InteriorData
  153. {
  154.    int_interior,
  155.     Float:int_x,
  156.     Float:int_y,
  157.     Float:int_z,
  158.     Float:int_r,
  159.     int_pickup
  160. }
  161. /*
  162.     House system by mick88 and Whatcha
  163.     Michael Dabski 2010
  164.     Nickolas Whatcha Core Shaffer 2010
  165. */
  166. new
  167.     mysql_connection,
  168.     Float:Houses[MAX_HOUSES][HouseData],
  169.     Float:Players[MAX_PLAYERS][PlayerData],
  170.     Float:Interiors[MAX_INTERIORS][InteriorData];
  171. /*
  172.     House system by mick88 and Whatcha
  173.     Michael Dabski 2010
  174.     Nickolas Whatcha Core Shaffer 2010
  175. */
  176. //===================================================================
  177. //:::::::::::::::::::::: Callbacks ::::::::::::::::::::::::::::::::::
  178. //===================================================================
  179. /*
  180.     House system by mick88 and Whatcha
  181.     Michael Dabski 2010
  182.     Nickolas Whatcha Core Shaffer 2010
  183. */
  184. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  185. {
  186.     new id;
  187.    if (NEW_KEY(HOUSE_ENTER_LEAVE_KEY))
  188.     {
  189.         if ((id = GetPlayerHouseEntrance(playerid)))
  190.         {
  191.             if (!IsHouseOwnedByPlayer(playerid, id)) return GameTextForPlayer(playerid, "~r~You don't own this house", 3000, 3);
  192.             PutPlayerInHouse(playerid, id);
  193.         }
  194.         else if ((id = Players[playerid][in_house]))
  195.         {
  196.             new i = Houses[id][house_interior];
  197.             if (IsPlayerInRangeOfPoint(playerid, HOUSE_RANGE, Interiors[i][int_x], Interiors[i][int_y], Interiors[i][int_z])) RemovePlayerFromHouse(playerid);
  198.         }
  199.     }
  200.     return 1;
  201. }
  202. /*
  203.     House system by mick88 and Whatcha
  204.     Michael Dabski 2010
  205.     Nickolas Whatcha Core Shaffer 2010
  206. */
  207. public OnFilterScriptInit()
  208. {
  209.    DisableInteriorEnterExits();
  210.     ADD_INTERIOR(0, 2259.8435,  -1136.2699, 1050.6328,  254.2604,   10);
  211.     ADD_INTERIOR(1, 2233.4900,  -1114.4435, 1050.8828,  357.3481,   5);
  212.     ADD_INTERIOR(2, 2196.3943,  -1204.1359, 1049.0234,  78.2122,    6);
  213.     ADD_INTERIOR(3, 2318.1616,  -1026.3762, 1050.2109,  358.3114,   9);
  214.     ADD_INTERIOR(4, 421.8333,   2536.9814,  10,         92.9158,    10);
  215.     ADD_INTERIOR(5, 234.6087,   1187.8195,  1080.2578,  349.4844,   3); //wrong interior ID!!
  216.     ADD_INTERIOR(6, 225.5707,   1240.0643,  1082.1406,  96.2852,    2);
  217.     ADD_INTERIOR(7, 223.2357,   1287.0824,  1082.1406,  359.868,    1);
  218.     ADD_INTERIOR(8, 226.7545,   1114.4180,  1080.9952,  267.4440,   5);
  219.     ADD_INTERIOR(8, 2269.9636,  -1210.3275, 1047.5625,  89.8057,    10);
  220.     ADD_INTERIOR(9, 2496.2087,  -1692.3149, 1014.7422,  181.4683,   3);
  221.     ADD_INTERIOR(10, 1299.1381, -796.1603,  1084.0078,  0,          5);
  222.     ADD_INTERIOR(11, 318.8655,  1115.1758,  1083.8828,  2.0485,     5);
  223.     ADD_INTERIOR(12, 2324.3159, -1148.7551, 1050.7101,  2.1677,     12);
  224.     ADD_INTERIOR(13, 2365.0630, -1135.2068, 1050.8750,  357.6382,   8);
  225.     ADD_INTERIOR(14, 2283.0852, -1139.4916, 1050.8984,  359.7849,   11);
  226.    
  227.     //mysql_debug(1); //uncommend for debugging
  228.    
  229.     mysql_connection = mysql_connect(MYSQL_IP, MYSQL_USER, MYSQL_DB, MYSQL_PASSWORD);
  230.    
  231.     QUERY(CREATE_TABLE_QUERY); //This line creates table in the database. Once ran, can be commented out - required only in the first run
  232.    
  233.     //Loading houses from database
  234.     QUERY("SELECT * FROM `"#MYSQL_TABLE_NAME"` WHERE `id` < "#MAX_HOUSES);
  235.     mysql_store_result(mysql_connection);
  236.     new n;
  237.     while (mysql_retrieve_row())
  238.     {
  239.         new tmp[32];
  240.         new id;
  241.         GET_INT(id, "id");//Loads houseid
  242.         GET_INT(Houses[id][house_price], "price");
  243.         GET_INT(Houses[id][house_interior], "interior");
  244.         GET_INT(Houses[id][Slots], "Slots");
  245.         GET_STR(Houses[id][house_owner], "owner");
  246.        
  247.         new Float:x, Float:y, Float:z, Float:r;
  248.         GET_FLOAT(x, "x");
  249.         GET_FLOAT(y, "y");
  250.         GET_FLOAT(z, "z");
  251.         GET_FLOAT(r, "r");
  252.         Houses[id][house_x] = x;
  253.         Houses[id][house_y] = y;
  254.         Houses[id][house_z] = z;
  255.         Houses[id][house_r] = r;
  256.        
  257.         SPAWN_HOUSE(id);
  258.         n++;
  259.     }
  260.     mysql_free_result(mysql_connection);
  261.     printf("%d houses loaded from %s/%s/%s, username %s", n, MYSQL_IP, MYSQL_DB, MYSQL_TABLE_NAME, MYSQL_USER);
  262.     print("House system loaded");
  263.     return 1;
  264. }
  265. /*
  266.     House system by mick88 and Whatcha
  267.     Michael Dabski 2010
  268.     Nickolas Whatcha Core Shaffer 2010
  269. */
  270. public OnFilterScriptExit()
  271. {
  272.    mysql_close(mysql_connection);
  273.     print("\nHouse system unloaded\n");
  274.     return 1;
  275. }
  276. /*
  277.     House system by mick88 and Whatcha
  278.     Michael Dabski 2010
  279.     Nickolas Whatcha Core Shaffer 2010
  280. */
  281. public OnPlayerPickUpDynamicPickup(playerid, pickupid)
  282. {
  283.     for (new i=1; i < MAX_HOUSES; i++) if (pickupid == Houses[i][house_pickup])
  284.     {
  285.         Players[playerid][last_house_entrance] = i;
  286.         if (IsHouseOwnedByPlayer(playerid, i)) GameTextForPlayer(playerid, "~y~Press ~r~~k~~VEHICLE_ENTER_EXIT~ ~y~to enter your house", 3000, 3);
  287.         break;
  288.     }
  289.     return 1;
  290. }
  291. /*
  292.     House system by mick88 and Whatcha
  293.     Michael Dabski 2010
  294.     Nickolas Whatcha Core Shaffer 2010
  295. */
  296. public OnPlayerConnect(playerid)
  297. {
  298.     Players[playerid][in_house] =               INVALID_HOUSE_ID;
  299.     Players[playerid][last_house_entrance] =    INVALID_HOUSE_ID;
  300.     return 0;
  301. }
  302. /*
  303.     House system by mick88 and Whatcha
  304.     Michael Dabski 2010
  305.     Nickolas Whatcha Core Shaffer 2010
  306. */
  307. public OnPlayerCommandText(playerid, cmdtext[])
  308. {
  309.     return 0;
  310. }
  311. /*
  312.     House system by mick88 and Whatcha
  313.     Michael Dabski 2010
  314.     Nickolas Whatcha Core Shaffer 2010
  315. */
  316. //===================================================================
  317. //:::::::::::::::::::::: Script functions :::::::::::::::::::::::::::
  318. //===================================================================
  319. /*
  320.     House system by mick88 and Whatcha
  321.     Michael Dabski 2010
  322.     Nickolas Whatcha Core Shaffer 2010
  323. */
  324. public GetHousePos(houseid, &Float:x, &Float:y, &Float:z)
  325. {
  326.     if (houseid == INVALID_HOUSE_ID || houseid >= MAX_HOUSES || !Houses[houseid][house_price]) return false;
  327.     x = Houses[houseid][house_x];
  328.     y = Houses[houseid][house_y];
  329.     z = Houses[houseid][house_z];
  330.     return true;
  331. }
  332. /*
  333.     House system by mick88 and Whatcha
  334.     Michael Dabski 2010
  335.     Nickolas Whatcha Core Shaffer 2010
  336. */
  337. public GetHouseFacingAngle(houseid, &Float:angle)
  338. {
  339.     if (houseid == INVALID_HOUSE_ID || houseid >= MAX_HOUSES || !Houses[houseid][house_price]) return false;
  340.     angle = Houses[houseid][house_r];
  341.     return true;
  342. }
  343. /*
  344.     House system by mick88 and Whatcha
  345.     Michael Dabski 2010
  346.     Nickolas Whatcha Core Shaffer 2010
  347. */
  348. stock UpdateHouseLabel(houseid)
  349. {
  350.     if (houseid == INVALID_HOUSE_ID) return false;
  351.     new label[HOUSE_LABEL_SIZE];
  352.     if (isnull(Houses[houseid][house_owner])) format(label, HOUSE_LABEL_SIZE, "For sale\nPrice: %s\nSlots:%i", FormatMoney(Houses[houseid][house_price]), Houses[houseid][Slots]);
  353.     else format(label, HOUSE_LABEL_SIZE, "House owned by:\n%s", Houses[houseid][house_owner]);
  354.     return UpdateDynamic3DTextLabelText(Houses[houseid][house_label], HOUSE_LABEL_COLOR, label);
  355. }
  356. /*
  357.     House system by mick88 and Whatcha
  358.     Michael Dabski 2010
  359.     Nickolas Whatcha Core Shaffer 2010
  360. */
  361. public IsHouseOwnedByPlayer(playerid, houseid)
  362. {
  363.     if (houseid == INVALID_HOUSE_ID) return false;
  364.     return (!isnull(Houses[houseid][house_owner]) && !strcmp(Houses[houseid][house_owner], PlayerName(playerid), false, MAX_PLAYER_NAME));
  365. }
  366. /*
  367.     House system by mick88 and Whatcha
  368.     Michael Dabski 2010
  369.     Nickolas Whatcha Core Shaffer 2010
  370. */
  371. public PutPlayerInHouse(playerid, id)
  372. {
  373.     if (id == INVALID_HOUSE_ID) return 0;
  374.     new interior = Houses[id][house_interior];
  375.     SetPlayerInterior(playerid, Interiors[interior][int_interior]);
  376.     SetPlayerVirtualWorld(playerid, HOUSE_WORLD_OFFSET+id);
  377.     SetPlayerPos(playerid, Interiors[interior][int_x],Interiors[interior][int_y],Interiors[interior][int_z]);
  378.     SetPlayerFacingAngle(playerid, Interiors[interior][int_r]);
  379.     SetCameraBehindPlayer(playerid);
  380.     Players[playerid][in_house] = id;
  381.     Streamer_Update(playerid);
  382.     return 1;
  383. }
  384. /*
  385.     House system by mick88 and Whatcha
  386.     Michael Dabski 2010
  387.     Nickolas Whatcha Core Shaffer 2010
  388. */
  389. public RemovePlayerFromHouse(playerid)
  390. {
  391.     new id = Players[playerid][in_house];
  392.     if (id == INVALID_HOUSE_ID) return 0;
  393.     Streamer_UpdateEx(playerid, Houses[id][house_x], Houses[id][house_y], Houses[id][house_z]);
  394.     SetPlayerInterior(playerid, 0);
  395.     SetPlayerVirtualWorld(playerid, 0);
  396.     SetPlayerPos(playerid, Houses[id][house_x], Houses[id][house_y], Houses[id][house_z]);
  397.     SetPlayerFacingAngle(playerid, Houses[id][house_r]);
  398.     SetCameraBehindPlayer(playerid);
  399.     Players[playerid][in_house] = 0;
  400.     return 1;
  401. }
  402. /*
  403.     House system by mick88 and Whatcha
  404.     Michael Dabski 2010
  405.     Nickolas Whatcha Core Shaffer 2010
  406. */
  407. public GiveHouseToPlayer(playerid, houseid)
  408. {
  409.     if (houseid == INVALID_HOUSE_ID || !isnull(Houses[houseid][house_owner])) return 0;
  410.     GetPlayerName(playerid, Houses[houseid][house_owner], MAX_PLAYER_NAME);
  411.     printf("House %d is given to %s", houseid, Houses[houseid][house_owner]);
  412.     SaveHouse(houseid);
  413.     UpdateHouseLabel(houseid);
  414.     return 1;
  415. }
  416. /*
  417.     House system by mick88 and Whatcha
  418.     Michael Dabski 2010
  419.     Nickolas Whatcha Core Shaffer 2010
  420. */
  421. public TakeHouseFromPlayer(houseid)
  422. {
  423.     if (houseid == INVALID_HOUSE_ID || isnull(Houses[houseid][house_owner])) return 0;
  424.     printf("Evicting %s from house %d", Houses[houseid][house_owner], houseid);
  425.     Houses[houseid][house_owner] = 0;
  426.     SaveHouse(houseid);
  427.     UpdateHouseLabel(houseid);
  428.     return 1;
  429. }
  430. /*
  431.     House system by mick88 and Whatcha
  432.     Michael Dabski 2010
  433.     Nickolas Whatcha Core Shaffer 2010
  434. */
  435. stock GetNewHouseID()
  436. {
  437.     for (new i=1; i < MAX_HOUSES; i++) if (!Houses[i][house_price]) return i;
  438.     return INVALID_HOUSE_ID;
  439. }
  440. /*
  441.     House system by mick88 and Whatcha
  442.     Michael Dabski 2010
  443.     Nickolas Whatcha Core Shaffer 2010
  444. */
  445. stock SaveHouse(houseid)
  446. {
  447.     new q[200];
  448.     format(q, 200, "UPDATE `"#MYSQL_TABLE_NAME"` SET `price`=%d,`owner`='%s',`x`='%f',`y`='%f',`z`='%f',`r`='%f',`interior`=%d,`Slots`=%i WHERE `id`=%d LIMIT 1",
  449.         Houses[houseid][house_price], Houses[houseid][house_owner], Houses[houseid][house_x], Houses[houseid][house_y],
  450.         Houses[houseid][house_z], Houses[houseid][house_r], Houses[houseid][house_interior], Houses[houseid][Slots], houseid);
  451.     QUERY(q);
  452.     return 1;
  453. }
  454. /*
  455.     House system by mick88 and Whatcha
  456.     Michael Dabski 2010
  457.     Nickolas Whatcha Core Shaffer 2010
  458. */
  459. public GetPlayerHouseEntrance(playerid)
  460. {
  461.     new id = Players[playerid][last_house_entrance];
  462.     if (id == INVALID_HOUSE_ID || IsPlayerInRangeOfPoint(playerid, HOUSE_RANGE, Houses[id][house_x], Houses[id][house_y], Houses[id][house_z])) return id;
  463.     return INVALID_HOUSE_ID;
  464. }
  465. /*
  466.     House system by mick88 and Whatcha
  467.     Michael Dabski 2010
  468.     Nickolas Whatcha Core Shaffer 2010
  469. */
  470. public GetPlayerHouseID(playerid)
  471. {
  472.     return Players[playerid][in_house];
  473. }
  474. /*
  475.     House system by mick88 and Whatcha
  476.     Michael Dabski 2010
  477.     Nickolas Whatcha Core Shaffer 2010
  478. */
  479. public CreateHouse(Float:x, Float:y, Float:z, Float:r, price, interior, Slots2)
  480. {
  481.     new id = GetNewHouseID();
  482.     if (id == INVALID_HOUSE_ID || price <= 0 || interior >= MAX_INTERIORS || interior < 0) return INVALID_HOUSE_ID;
  483.     Houses[id][house_x] = x;
  484.     Houses[id][house_y] = y;
  485.     Houses[id][house_z] = z;
  486.     Houses[id][house_r] = r;
  487.     Houses[id][house_price] = price;
  488.     Houses[id][house_interior] = interior;
  489.     Houses[id][house_owner] = 0;
  490.     Houses[id][Slots] = Slots2;
  491.     new q[128];
  492.     format(q, 200, "INSERT INTO `"#MYSQL_TABLE_NAME"` (`id`) VALUES (%d)", id);
  493.     QUERY(q);
  494.     SPAWN_HOUSE(id);
  495.     SaveHouse(id);
  496.     printf("House %d is created. Price %s, interior %d", id, FormatMoney(price), interior);
  497.     return id;
  498. }
  499.  
  500. //===================================================================
  501. //:::::::::::::::::::::: Script commands ::::::::::::::::::::::::::::
  502. //===================================================================
  503. /*
  504.     House system by mick88 and Whatcha
  505.     Michael Dabski 2010
  506.     Nickolas Whatcha Core Shaffer 2010
  507. */
  508. // ======= Player commands ========
  509. CMD:buyhouse(playerid, params[])
  510. {
  511.     new price,
  512.     id = GetPlayerHouseEntrance(playerid);
  513.     if (id == INVALID_HOUSE_ID) return ERROR("You must stand in house entrance!");
  514.     price = Houses[id][house_price];
  515.     if (GET_MONEY(playerid) >= price && GiveHouseToPlayer(playerid, id))
  516.     {
  517.         ADD_MONEY(playerid, -price);
  518.         new msg[128];
  519.         format(MSG, "You bought house for %s", FormatMoney(price));
  520.         MESSAGE(msg);
  521.     }
  522.     else ERROR("You cannot buy this house!");
  523.     return 1;
  524. }
  525. /*
  526.     House system by mick88 and Whatcha
  527.     Michael Dabski 2010
  528.     Nickolas Whatcha Core Shaffer 2010
  529. */
  530. CMD:sellhouse(playerid, params[])
  531. {
  532.    new price,
  533.     id = GetPlayerHouseEntrance(playerid);
  534.     if (!IsHouseOwnedByPlayer(playerid, id)) return ERROR("You must stand in the entrance of your house");
  535.     price = floatround(Houses[id][house_price] * HOUSE_SELL_PAYBACK);
  536.     if (TakeHouseFromPlayer(id))
  537.     {
  538.         ADD_MONEY(playerid, price);
  539.         new msg[128];
  540.         format(MSG, "You sold house for %s", FormatMoney(price));
  541.         MESSAGE(msg);
  542.     }
  543.     else ERROR("You cannot sell this house!");
  544.     return 1;
  545. }
  546. /*
  547.     House system by mick88 and Whatcha
  548.     Michael Dabski 2010
  549.     Nickolas Whatcha Core Shaffer 2010
  550. */
  551. CMD:enter(playerid, params[])
  552. {
  553.     new id = GetPlayerHouseEntrance(playerid);
  554.     if (id == INVALID_HOUSE_ID) return ERROR("You must be in house entrance to use this command");
  555.     if (IsHouseOwnedByPlayer(playerid, id) || IS_ADMIN(playerid)) PutPlayerInHouse(playerid, id);
  556.     else ERROR("You don't own this house");
  557.     return 1;
  558. }
  559. /*
  560.     House system by mick88 and Whatcha
  561.     Michael Dabski 2010
  562.     Nickolas Whatcha Core Shaffer 2010
  563. */
  564. CMD:exit(playerid, params[])
  565. {
  566.     if (!RemovePlayerFromHouse(playerid)) return ERROR("You must be inside house to use this command");
  567.     return 1;
  568. }
  569. /*
  570.     House system by mick88 and Whatcha
  571.     Michael Dabski 2010
  572.     Nickolas Whatcha Core Shaffer 2010
  573. */
  574. CMD:housecmds(playerid, params[])
  575. {
  576.     MESSAGE("House commands: /BuyHouse /SellHouse /enter /exit");
  577.     if (IS_ADMIN(playerid))
  578.     {
  579.         MESSAGE("Admin house commands: /AddHouse /SetPrice /SetInterior /GiveHouse /Evict /TeleHouse");
  580.     }
  581.     return 1;
  582. }
  583. /*
  584.     House system by mick88 and Whatcha
  585.     Michael Dabski 2010
  586.     Nickolas Whatcha Core Shaffer 2010
  587. */
  588. // ======= Admin commands ========
  589. /*
  590.     House system by mick88 and Whatcha
  591.     Michael Dabski 2010
  592.     Nickolas Whatcha Core Shaffer 2010
  593. */
  594. CMD:addhouse(playerid, params[])
  595. {
  596.     ADMIN;
  597.     new Float:x, Float:y, Float:z, Float:r, price, interior, id, msg[128], Slots2;
  598.     GetPlayerPos(playerid, x, y, z);
  599.     GetPlayerFacingAngle(playerid, r);
  600.     if (sscanf(params, "iI("#DEFAULT_HOUSE_INTERIOR")i", price, interior, Slots2)) return ERROR("Usage: /AddHouse [price] (interior="#DEFAULT_HOUSE_INTERIOR") [Slots]");
  601.     if (price <= 0) return ERROR("Price given is not correct!");
  602.     if ((id = CreateHouse(x, y, z, r, price, interior, Slots2)) == INVALID_HOUSE_ID) ERROR("House could not be created! House limit "#MAX_HOUSES" may have been reached");
  603.     format(MSG, "House %d has been created with price %s and interior %d", id, FormatMoney(Houses[id][house_price]), Houses[id][house_interior]);
  604.     //  Houses[id][Slots] = Slots2;
  605.     MESSAGE(msg);
  606.     Streamer_Update(playerid);
  607.     return 1;
  608. }
  609. /*
  610.     House system by mick88 and Whatcha
  611.     Michael Dabski 2010
  612.     Nickolas Whatcha Core Shaffer 2010
  613. */
  614. CMD:telehouse(playerid, params[])
  615. {
  616.     ADMIN;
  617.     new Float:x, Float:y, Float:z, id;
  618.     if (sscanf(params, "i", id)) return ERROR("Usage: /TeleHouse [houseid]");
  619.     if (!GetHousePos(id, x, y, z)) return ERROR("Invalid house id!");
  620.     Streamer_UpdateEx(playerid, x, y ,z);
  621.     SetPlayerVirtualWorld(playerid, 0);
  622.     SetPlayerInterior(playerid, 0);
  623.     SetPlayerPos(playerid, x, y, z);
  624.     return 1;
  625. }
  626. /*
  627.     House system by mick88 and Whatcha
  628.     Michael Dabski 2010
  629.     Nickolas Whatcha Core Shaffer 2010
  630. */
  631. CMD:setprice(playerid, params[])
  632. {
  633.     ADMIN;
  634.     new price;
  635.     if (sscanf(params,  "i", price)) return ERROR("Usage: /SetPrice [price]");
  636.     if (price <= 0) return ERROR("Price is too low!");
  637.     new id = GetPlayerHouseEntrance(playerid);
  638.     if (id == INVALID_HOUSE_ID) return ERROR("You must stand in house entrance!");
  639.     Houses[id][house_price] = price;
  640.     SaveHouse(id);
  641.     UpdateHouseLabel(id);
  642.     new msg[128];
  643.     format(MSG, "House %d price set to %s", id, FormatMoney(price));
  644.     MESSAGE(msg);
  645.     return 1;
  646. }
  647. /*
  648.     House system by mick88 and Whatcha
  649.     Michael Dabski 2010
  650.     Nickolas Whatcha Core Shaffer 2010
  651. */
  652. CMD:setinterior(playerid, params[])
  653. {
  654.     ADMIN;
  655.     new interior;
  656.     if (sscanf(params,  "i", interior)) return ERROR("Usage: /SetInterior [interior]");
  657.     if (interior < 0 || interior >= MAX_INTERIORS) return ERROR("Wrong interior id! Interior must be lower than "#MAX_INTERIORS);
  658.     new id = GetPlayerHouseEntrance(playerid);
  659.     if (id == INVALID_HOUSE_ID) return ERROR("You must stand in house entrance!");
  660.     Houses[id][house_interior] = interior;
  661.     SaveHouse(id);
  662.     new msg[128];
  663.     format(MSG, "House %d interior set to %d", id, interior);
  664.     MESSAGE(msg);
  665.     return 1;
  666. }
  667.  
  668. /*
  669.     House system by mick88 and Whatcha
  670.     Michael Dabski 2010
  671.     Nickolas Whatcha Core Shaffer 2010
  672. */
  673. CMD:evict(playerid, params[])
  674. {
  675.     ADMIN;
  676.     if (!TakeHouseFromPlayer(GetPlayerHouseEntrance(playerid))) return ERROR("Error: make sure you are standing in the entrance of owned house!");
  677.     else MESSAGE("Player is evicted from house");
  678.     Streamer_Update(playerid);
  679.     return 1;
  680. }
  681. /*
  682.     House system by mick88 and Whatcha
  683.     Michael Dabski 2010
  684.     Nickolas Whatcha Core Shaffer 2010
  685. */
  686. CMD:givehouse(playerid, params[])
  687. {
  688.     ADMIN;
  689.     new pid;
  690.     if (sscanf(params, "u", pid)) return ERROR("Usage: /GiveHouse [player]");
  691.     if (pid == INVALID_PLAYER_ID) return ERROR("Invalid Player ID");
  692.     if (!GiveHouseToPlayer(pid, GetPlayerHouseEntrance(playerid))) return ERROR("Error: make sure you are standing in the entrance of unowned house!");
  693.     else
  694.     {
  695.         new msg[128];
  696.         format(MSG, "House given to %s", PlayerName(pid));
  697.         MESSAGE(msg);
  698.     }
  699.     Streamer_Update(playerid);
  700.     return 1;
  701. }
  702. //===================================================================
  703. //:::::::::::::::::::::: Stock functions ::::::::::::::::::::::::::::
  704. //===================================================================
  705. /*
  706.     House system by mick88 and Whatcha
  707.     Michael Dabski 2010
  708.     Nickolas Whatcha Core Shaffer 2010
  709. */
  710. stock PlayerName(playerid)
  711. {
  712.     new name[MAX_PLAYER_NAME];
  713.     GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  714.     return name;
  715. }
  716.  
  717. stock FormatMoney(Float:amount, delimiter[2]=",")
  718. {
  719.     #define MAX_MONEY_STRING 16
  720.     new txt[MAX_MONEY_STRING];
  721.     format(txt, MAX_MONEY_STRING, "$%d", floatround(amount));
  722.     new l = strlen(txt);
  723.     if (amount < 0) // -
  724.     {
  725.         if (l > 5) strins(txt, delimiter, l-3);
  726.         if (l > 8) strins(txt, delimiter, l-6);
  727.         if (l > 11) strins(txt, delimiter, l-9);
  728.     }
  729.     else
  730.     {
  731.         if (l > 4) strins(txt, delimiter, l-3);
  732.         if (l > 7) strins(txt, delimiter, l-6);
  733.         if (l > 10) strins(txt, delimiter, l-9);
  734.     }
  735.     return txt;
  736. }
  737.  
  738. /*
  739.     House system by mick88 and Whatcha
  740.     Michael Dabski 2010
  741.     Nickolas Whatcha Core Shaffer 2010
  742. */
Advertisement
Add Comment
Please, Sign In to add comment