Advertisement
Guest User

Dynamic Entrance System

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