Advertisement
Guest User

MySQL Navi - Filterscript

a guest
Nov 27th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.07 KB | None | 0 0
  1. /*
  2.  *  Chill RP - Navi
  3.  *  Copyright (C) 2011  Brian <hagen@hagen.ath.cx>
  4.  *
  5.  *  This program is free software: you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation, either version 3 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19.  
  20. /*
  21.  * ----------------------------------------------------------
  22.  *  You may edit these lines:
  23.  */
  24. #define SQL_HOST "localhost"
  25. #define SQL_DB "database"
  26. #define SQL_USER "username
  27. #define SQL_PASS "passwort"
  28. /*
  29.  * ----------------------------------------------------------
  30.  */
  31.  
  32.  
  33. #pragma tabsize 0
  34. #define FILTERSCRIPT
  35.  
  36. #include <a_samp>
  37. #include <mysql>
  38. #include <zcmd>
  39.  
  40.  
  41. #define NAVI_DIALOG_CATEGORIES 294
  42. #define NAVI_DIALOG_SUBCATEGORIES 295
  43. #define NAVI_DIALOG_PLACES 296
  44.  
  45. new tmp[64];
  46. new QueryString[256];
  47. new Message[128];
  48.  
  49. forward Float:GetPlayerDistanceToPoint(playerid, Float:x1, Float:y1, Float:z1);
  50.  
  51. public OnFilterScriptInit() {
  52.     mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
  53.     return 1;
  54. }
  55.  
  56. public OnFilterScriptExit() {
  57.     mysql_close();
  58.     return 1;
  59. }
  60.  
  61. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  62.     if(dialogid == NAVI_DIALOG_CATEGORIES) {
  63.         if(response) NaviShowPlaces(playerid, inputtext);
  64.         return 1;
  65.     } else if(dialogid == NAVI_DIALOG_SUBCATEGORIES) {
  66.         if(response) {
  67.             NaviShowPlaces(playerid, inputtext);
  68.         } else {
  69.             NaviShowCategories(playerid);
  70.         }
  71.     } else if (dialogid == NAVI_DIALOG_PLACES) {
  72.         if(response) {
  73.             NaviSelectPlace(playerid, inputtext);
  74.         } else {
  75.             if(GetPVarInt(playerid, "navi_lastsubcategory"))
  76.                 NaviShowCategories(playerid, GetPVarInt(playerid, "navi_lastsubcategory"));
  77.             else
  78.                 NaviShowCategories(playerid);
  79.         }
  80.         return 1;
  81.     }
  82.  
  83.     return 0;
  84. }
  85.  
  86. public OnPlayerEnterCheckpoint(playerid) {
  87.     if(GetPVarInt(playerid, "checkpointtype") == 1) {
  88.         SendClientMessage(playerid, 0xD8D8D8FF,"Navi: Ziel erreicht.");
  89.         DisablePlayerCheckpoint(playerid);
  90.         DeletePVar(playerid, "checkpointtype");
  91.         return 1;
  92.     }
  93.  
  94.     return 0;
  95. }
  96.  
  97. CMD:navi(playerid, params[]) {
  98.     if(GetPVarInt(playerid, "navidisabled"))
  99.         return SendClientMessage(playerid, 0xFF3333FF, "Du kannst die Navigation hier nicht benutzen.");
  100.  
  101.     NaviShowCategories(playerid);
  102.     return 1;
  103. }
  104.  
  105. NaviShowCategories(playerid, sub = 0) {
  106.     new categories[512];
  107.  
  108.  
  109.     format(QueryString, sizeof(QueryString), "SELECT `name` FROM `navi_categories` WHERE `navilevel` <= %d AND `sub` = %d ORDER BY `name`", GetPVarInt(playerid, "navilevel"), sub);
  110.     mysql_query(QueryString);
  111.  
  112.     mysql_store_result();
  113.  
  114.     while(mysql_retrieve_row()) {
  115.         mysql_fetch_field_row(tmp, "name");
  116.         strcat(categories, tmp);
  117.         strcat(categories, "\n");
  118.     }
  119.  
  120.  
  121.     if(sub) {
  122.         new subname[128];
  123.  
  124.         format(QueryString, sizeof(QueryString), "SELECT `name` FROM `navi_categories` WHERE `id` = %d", sub);
  125.         mysql_query(QueryString);
  126.         mysql_store_result();
  127.         if(mysql_retrieve_row())
  128.             mysql_fetch_field_row(subname, "name");
  129.         mysql_free_result();
  130.  
  131.         format(Message, sizeof(Message), "Navigation - %s", subname);
  132.         ShowPlayerDialog(playerid, NAVI_DIALOG_SUBCATEGORIES, DIALOG_STYLE_LIST, Message, categories, "Ausw\228;hlen", "Zur\252;ck");
  133.     } else {
  134.         ShowPlayerDialog(playerid, NAVI_DIALOG_CATEGORIES, DIALOG_STYLE_LIST, "Navigation - Kategorien", categories, "Ausw\228;hlen", "Schlie\223;en");
  135.         DeletePVar(playerid, "navi_lastsubcategory");
  136.     }
  137.  
  138.     DeletePVar(playerid, "navi_lastcategory");
  139.  
  140.     mysql_free_result();
  141.  
  142.     return 1;
  143. }
  144.  
  145. NaviShowPlaces(playerid, inputtext[]) {
  146.     new Category[128];
  147.     new CategoryId;
  148.     new commands[2048];
  149.  
  150.     strcat(Category, inputtext);
  151.  
  152.     mysql_real_escape_string(Category, Category);
  153.  
  154.     if(GetPVarInt(playerid, "navi_lastcategory")) {
  155.         CategoryId = GetPVarInt(playerid, "navi_lastcategory");
  156.  
  157.         format(QueryString, sizeof(QueryString), "SELECT `name` FROM `navi_categories` WHERE `id` = '%d'", CategoryId);
  158.         mysql_query(QueryString);
  159.         mysql_store_result();
  160.         if(mysql_retrieve_row())
  161.             mysql_fetch_field_row(Category, "name");
  162.         mysql_free_result();
  163.     } else {
  164.         format(QueryString, sizeof(QueryString), "SELECT `id` FROM `navi_categories` WHERE `name` = '%s'", Category);
  165.         mysql_query(QueryString);
  166.         mysql_store_result();
  167.         CategoryId = mysql_fetch_int();
  168.         mysql_free_result();
  169.     }
  170.  
  171.     SetPVarInt(playerid, "navi_lastcategory", CategoryId);
  172.  
  173.     format(QueryString, sizeof(QueryString), "SELECT NULL FROM `navi_categories` WHERE `sub` = %d", CategoryId);
  174.     mysql_query(QueryString);
  175.     mysql_store_result();
  176.  
  177.     if(mysql_retrieve_row()) {
  178.         SetPVarInt(playerid, "navi_lastsubcategory", CategoryId);
  179.         NaviShowCategories(playerid, CategoryId);
  180.         return 1;
  181.     }
  182.  
  183.     mysql_free_result();
  184.  
  185.     format(QueryString, sizeof(QueryString), "SELECT `name` FROM `navi_places` WHERE `category` = %d ORDER BY `name`", CategoryId);
  186.     mysql_query(QueryString);
  187.     mysql_store_result();
  188.     while(mysql_retrieve_row()) {
  189.         mysql_fetch_field_row(tmp, "name");
  190.         strcat(commands, tmp);
  191.         strcat(commands, "\n");
  192.     }
  193.     mysql_free_result();
  194.  
  195.  
  196.     format(Message, sizeof(Message), "Navigation - %s", Category);
  197.     ShowPlayerDialog(playerid, NAVI_DIALOG_PLACES, DIALOG_STYLE_LIST, Message, commands, "Ausw\228;hlen", "Zur\252;ck");
  198.  
  199.  
  200.     return 1;
  201. }
  202.  
  203. NaviSelectPlace(playerid, inputtext[]) {
  204.     new name[256];
  205.  
  206.     strcat(name, inputtext);
  207.  
  208.     mysql_real_escape_string(name, name);
  209.  
  210.     format(QueryString, sizeof(QueryString), "SELECT * FROM `navi_places` WHERE `name` = '%s' AND `category` = %d", name, GetPVarInt(playerid, "navi_lastcategory"));
  211.     mysql_query(QueryString);
  212.     mysql_store_result();
  213.     if(mysql_retrieve_row()) {
  214.         new pid;
  215.  
  216.         mysql_fetch_field_row(tmp, "id");
  217.         pid = strval(tmp);
  218.  
  219.         if (pid == 36) {
  220.             enum pnsPos_ {
  221.                 Float:pposx,
  222.                 Float:pposy,
  223.                 Float:pposz
  224.             }
  225.             new pnsPos[10][pnsPos_] = {
  226.                 {-1904.7391,273.8949,41.0469},
  227.                 {-2425.5103,1032.3198,50.3906},
  228.                 {488.3104,-1731.2484,11.2403},
  229.                 {1965.2585,2162.0024,10.8203},
  230.                 {719.7296,-466.5216,16.3437},
  231.                 {1025.5741,-1030.9137,32.0172},
  232.                 {1024.7762,-1030.6993,32.0322},
  233.                 {2073.6882,-1831.4650,13.5469},
  234.                 {-99.9173,1105.1434,19.7422},
  235.                 {-1421.3560,2599.7688,55.6875}
  236.             };
  237.             new Float:Min = 100000, Mini;
  238.             for(new i = 0; i < sizeof(pnsPos); i++) {
  239.                 if (GetPlayerDistanceToPoint(playerid, pnsPos[i][pposx], pnsPos[i][pposy], pnsPos[i][pposz]) < Min) {
  240.                     Min = GetPlayerDistanceToPoint(playerid, pnsPos[i][pposx], pnsPos[i][pposy], pnsPos[i][pposz]);
  241.                     Mini = i;
  242.                 }
  243.             }
  244.             SendClientMessage(playerid, 0xD8D8D8FF,"{D8D8D8}Navi: Marker beim der {FFFFFF}n\228;chsten Pay and Spray {D8D8D8}gesetzt");
  245.             SetPlayerCheckpoint(playerid, pnsPos[Mini][pposx], pnsPos[Mini][pposy], pnsPos[Mini][pposz], 4.0);
  246.             SetPVarInt(playerid, "checkpointtype", 1);
  247.         } else {
  248.             new Float:nposx, Float:nposy, Float:nposz;
  249.  
  250.             mysql_fetch_field_row(tmp, "posx");
  251.             nposx = floatstr(tmp);
  252.             mysql_fetch_field_row(tmp, "posy");
  253.             nposy = floatstr(tmp);
  254.             mysql_fetch_field_row(tmp, "posz");
  255.             nposz = floatstr(tmp);
  256.  
  257.             format(Message, sizeof(Message), "{D8D8D8}Navi: Marker bei {FFFFFF}%s {D8D8D8}gesetzt.", name);
  258.             SendClientMessage(playerid, 0xD8D8D8FF, Message);
  259.             SetPlayerCheckpoint(playerid, nposx, nposy, nposz, 4.0);
  260.             SetPVarInt(playerid, "checkpointtype", 1);
  261.         }
  262.     } else {
  263.         SendClientMessage(playerid, 0xFF3333FF, "Ein unerwarteter Fehler ist aufgetreten.");
  264.     }
  265.     mysql_free_result();
  266.  
  267.     return 1;
  268.  
  269. }
  270.  
  271. Float:GetPlayerDistanceToPoint(playerid, Float:x1, Float:y1, Float:z1) {
  272.     new Float:x2,Float:y2,Float:z2;
  273.     GetPlayerPos(playerid,x2,y2,z2);
  274.     return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
  275. }
  276.  
  277.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement