Advertisement
Guest User

Untitled

a guest
Jul 31st, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.24 KB | None | 0 0
  1. /*
  2.                         Dynamic Entrance System
  3. */
  4.  
  5. #define FILTERSCRIPT
  6.  
  7. #include <a_samp>
  8. #include "../include/a_mysql.inc"
  9. #include "../include/sscanf2.inc"
  10. #include "../include/zcmd.inc"
  11.  
  12. #define MySQL_HOST "localhost"
  13. #define MySQL_USER "root"
  14. #define MySQL_DB   "rpg"
  15. #define MySQL_PASS ""
  16.  
  17. #define MAX_ENTRANCES (100)
  18. #define MAX_ENTRANCE_NAME (25)
  19.  
  20. #define void%0(%1)\
  21.             forward%0(%1); public%0(%1)
  22. #define function%0(%1)\
  23.                 stock%0(%1)
  24. #define forEx(%0,%1)\
  25.             for(new %0; %0 != %1; %0++)
  26. #define PRESSED(%0)\
  27.             (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  28.  
  29. enum items
  30. {
  31.     ID,
  32.     Name[MAX_ENTRANCE_NAME],
  33.     Float:Enter[3],
  34.     Float:Exit[3],
  35.     Interior,
  36.     VirtualW
  37. }
  38. new eSystem[MAX_ENTRANCES][items];
  39.  
  40. new Text3D:EnterLabel[MAX_ENTRANCES];
  41.  
  42. public OnFilterScriptInit()
  43. {
  44.     CreateMySQLConnection(MySQL_HOST, MySQL_USER, MySQL_DB, MySQL_PASS);
  45.  
  46.     mysql_query("SELECT * FROM `entrances`");
  47.     mysql_store_result();
  48.  
  49.     new query[200], string[66], Count = 1;
  50.  
  51.     while(mysql_fetch_row(query))
  52.     {
  53.         sscanf(query,"e<p<|>is[25]ffffffii>",eSystem[Count]);
  54.  
  55.         format(string,sizeof(string),"Entrance: %s\nPress [ENTER] to enter!", eSystem[Count][Name]);
  56.         EnterLabel[Count] = Create3DTextLabel(string, -1, eSystem[Count][Enter][0], eSystem[Count][Enter][1], eSystem[Count][Enter][2], 100.0, 0, 0);
  57.         Count++;
  58.     }
  59.     mysql_free_result();
  60.     return 1;
  61. }
  62.  
  63. public OnFilterScriptExit()
  64. {
  65.     print("INFO: DES System UnLoaded!");
  66.     mysql_close();
  67.     print("INFO: MySQL Connection closed!");
  68.     return 1;
  69. }
  70.  
  71. command(create, playerid, params[])
  72. {
  73.     if (!IsPlayerAdmin(playerid)) return 0;
  74.  
  75.     new pName[MAX_ENTRANCE_NAME], pInterior, query[200];
  76.  
  77.     if (sscanf(params,"s[25]i", pName, pInterior))
  78.     {
  79.         return SendClientMessage(playerid, -1, "* USAGE: /create [Entrance Name] [Interior ID]");
  80.     }
  81.     if (strlen(pName) > MAX_ENTRANCE_NAME)
  82.     {
  83.         return SendClientMessage(playerid, -1, "* Entrance Name Cannot By Longer Than 25 Simbols!");
  84.     }
  85.     new Float:Player[3];
  86.     GetPlayerPos(playerid, Player[0], Player[1], Player[2]);
  87.  
  88.     mysql_query("SELECT MAX(ID) FROM `entrances`");
  89.     mysql_store_result();
  90.  
  91.     new sqlid[10];
  92.     mysql_fetch_row_format(sqlid,"|");
  93.     printf("INFO: Last ID: %s", sqlid);
  94.  
  95.     new SQLID = strval(sqlid);
  96.     SQLID++;
  97.     eSystem[SQLID][ID] = SQLID;
  98.     eSystem[SQLID][Name] = pName;
  99.     eSystem[SQLID][Enter][0] = Player[0];
  100.     eSystem[SQLID][Enter][1] = Player[1];
  101.     eSystem[SQLID][Enter][2] = Player[2];
  102.     eSystem[SQLID][VirtualW] = SQLID;
  103.  
  104.     format(query,sizeof(query),"INSERT INTO `entrances` (`ID`,`Name`,`X`,`Y`,`Z`,`VirtualW`) VALUES ('%i','%s','%f','%f','%f','%i')",
  105.     eSystem[SQLID][ID], eSystem[SQLID][Name], eSystem[SQLID][Enter][0], eSystem[SQLID][Enter][1], eSystem[SQLID][Enter][2], eSystem[SQLID][VirtualW]);
  106.     mysql_query(query);
  107.  
  108.     new string[66];
  109.     format(string,sizeof(string),"Entrance: %s!\nPress [ENTER] to enter!", eSystem[SQLID][Name]);
  110.     EnterLabel[SQLID] = Create3DTextLabel(string, -1, eSystem[SQLID][Enter][0], eSystem[SQLID][Enter][1], eSystem[SQLID][Enter][2], 50.0, 0, 1);
  111.  
  112.     UpdateExitCordinates(SQLID,pInterior);
  113.     mysql_free_result();
  114.     return 1;
  115. }
  116.  
  117.  
  118.  
  119. function UpdateExitCordinates(eID, eInterior)
  120. {
  121.     switch(eInterior)
  122.     {
  123.         case 1: // LV Gym
  124.         {
  125.             eSystem[eID][Interior] = 7;
  126.             eSystem[eID][Exit][0] = 773.579956;
  127.             eSystem[eID][Exit][1] = -77.096694;
  128.             eSystem[eID][Exit][2] = 1000.655029;
  129.         }
  130.         case 2: // Car school
  131.         {
  132.             eSystem[eID][Interior] = 3;
  133.             eSystem[eID][Exit][0] = -2029.798339;
  134.             eSystem[eID][Exit][1] = -106.675910;
  135.             eSystem[eID][Exit][2] = 1035.171875;
  136.         }
  137.         case 3: // Bike school
  138.         {
  139.             eSystem[eID][Interior] = 3;
  140.             eSystem[eID][Exit][0] = 1494.325195;
  141.             eSystem[eID][Exit][1] = 1304.942871;
  142.             eSystem[eID][Exit][2] = 1093.289062;
  143.         }
  144.         case 4: // LS Police HQ
  145.         {
  146.             eSystem[eID][Interior] = 6;
  147.             eSystem[eID][Exit][0] = 246.783996;
  148.             eSystem[eID][Exit][1] = 63.900199;
  149.             eSystem[eID][Exit][2] = 1003.640625;
  150.         }
  151.         case 5: // Zero's RC Shop
  152.         {
  153.             eSystem[eID][Interior] = 6;
  154.             eSystem[eID][Exit][0] = -2240.468505;
  155.             eSystem[eID][Exit][1] = 137.060440;
  156.             eSystem[eID][Exit][2] = 1035.414062;
  157.         }
  158.         case 6: // Ammunation 1
  159.         {
  160.             eSystem[eID][Interior] = 1;
  161.             eSystem[eID][Exit][0] = 286.148986;
  162.             eSystem[eID][Exit][1] = -40.644397;
  163.             eSystem[eID][Exit][2] = 1001.515625;
  164.         }
  165.         case 7: // 24/7 1
  166.         {
  167.             eSystem[eID][Interior] = 17;
  168.             eSystem[eID][Exit][0] = -25.884498;
  169.             eSystem[eID][Exit][1] = -185.868988;
  170.             eSystem[eID][Exit][2] = 1003.546875;
  171.         }
  172.         case 8: //  Jefferson motel
  173.         {
  174.             eSystem[eID][Interior] = 15;
  175.             eSystem[eID][Exit][0] = 2215.454833;
  176.             eSystem[eID][Exit][1] = -1147.475585;
  177.             eSystem[eID][Exit][2] = 1025.796875;
  178.         }
  179.         case 9: // Binco
  180.         {
  181.             eSystem[eID][Interior] = 15;
  182.             eSystem[eID][Exit][0] = 207.737991;
  183.             eSystem[eID][Exit][1] = -109.019996;
  184.             eSystem[eID][Exit][2] = 1005.132812;
  185.         }
  186.         case 10: // Club
  187.         {
  188.             eSystem[eID][Interior] = 17;
  189.             eSystem[eID][Exit][0] = 493.390991;
  190.             eSystem[eID][Exit][1] = -22.722799;
  191.             eSystem[eID][Exit][2] = 1000.679687;
  192.         }
  193.         default: // Bar
  194.         {
  195.             eSystem[eID][Interior] = 11;
  196.             eSystem[eID][Exit][0] = 501.980987;
  197.             eSystem[eID][Exit][1] = -69.150199;
  198.             eSystem[eID][Exit][2] = 998.757812;
  199.         }
  200.     }
  201.     new query[200];
  202.     format(query,sizeof(query),"UPDATE `entrances` SET `exitX` = '%f', `exitY` = '%f', `exitZ` = '%f', `Interior` = '%i' WHERE `ID` = '%i'",
  203.     eSystem[eID][Exit][0], eSystem[eID][Exit][1], eSystem[eID][Exit][2], eSystem[eID][Interior], eID);
  204.     mysql_query(query);
  205. }
  206.  
  207.  
  208. function CreateMySQLConnection(host[], user[], db[], pass[])
  209. {
  210.     mysql_connect(host, user, db, pass);
  211.  
  212.     if (mysql_ping() >= 1)
  213.     {
  214.         print("INFO: Connected To MySQL!");
  215.     }
  216.     else
  217.     {
  218.         print("INFO: Can't Connect To MySQL!");
  219.     }
  220.    
  221.     mysql_query("CREATE TABLE IF NOT EXISTS `entrances` ( \
  222.       `ID` int(3) NOT NULL, \
  223.       `Name` varchar(25) NOT NULL, \
  224.       `X` float NOT NULL, \
  225.       `Y` float NOT NULL, \
  226.       `Z` float NOT NULL, \
  227.       `exitX` float NOT NULL, \
  228.       `exitY` float NOT NULL, \
  229.       `exitZ` float NOT NULL, \
  230.       `Interior` int(5) NOT NULL, \
  231.       `VirtualW` int(3) NOT NULL \
  232.     ) ENGINE=InnoDB DEFAULT CHARSET=latin1;");
  233. }
  234.  
  235.  
  236. void OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  237. {
  238.     if (PRESSED(KEY_SECONDARY_ATTACK))
  239.     {
  240.         forEx(i, MAX_ENTRANCES)
  241.         {
  242.             if (IsPlayerInRangeOfPoint(playerid, 2, eSystem[i][Enter][0], eSystem[i][Enter][1], eSystem[i][Enter][2]))
  243.             {
  244.                 SetPlayerVirtualWorld(playerid, eSystem[i][VirtualW]);
  245.                 SetPlayerInterior(playerid, eSystem[i][Interior]);
  246.                 SetPlayerPos(playerid, eSystem[i][Exit][0], eSystem[i][Exit][1], eSystem[i][Exit][2]);
  247.                 SetPVarInt(playerid, "entranceID", i); // Need for exit
  248.                 break; // Stoping loop
  249.             }
  250.         }
  251.         if (IsPlayerInRangeOfPoint(playerid, 2, eSystem[GetPVarInt(playerid,"entranceID")][Exit][0], eSystem[GetPVarInt(playerid,"entranceID")][Exit][1], eSystem[GetPVarInt(playerid,"entranceID")][Exit][2]))
  252.         {
  253.             SetPlayerVirtualWorld(playerid, 0);
  254.             SetPlayerInterior(playerid, 0);
  255.             SetPlayerPos(playerid, eSystem[GetPVarInt(playerid,"entranceID")][Enter][0], eSystem[GetPVarInt(playerid,"entranceID")][Enter][1], eSystem[GetPVarInt(playerid,"entranceID")][Enter][2]);
  256.         }
  257.     }
  258.     return 1;
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement