Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Chill RP - Navi
- * Copyright (C) 2011 Brian <hagen@hagen.ath.cx>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /*
- * ----------------------------------------------------------
- * You may edit these lines:
- */
- #define SQL_HOST "localhost"
- #define SQL_DB "database"
- #define SQL_USER "username
- #define SQL_PASS "passwort"
- /*
- * ----------------------------------------------------------
- */
- #pragma tabsize 0
- #define FILTERSCRIPT
- #include <a_samp>
- #include <mysql>
- #include <zcmd>
- #define NAVI_DIALOG_CATEGORIES 294
- #define NAVI_DIALOG_SUBCATEGORIES 295
- #define NAVI_DIALOG_PLACES 296
- new tmp[64];
- new QueryString[256];
- new Message[128];
- forward Float:GetPlayerDistanceToPoint(playerid, Float:x1, Float:y1, Float:z1);
- public OnFilterScriptInit() {
- mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
- return 1;
- }
- public OnFilterScriptExit() {
- mysql_close();
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
- if(dialogid == NAVI_DIALOG_CATEGORIES) {
- if(response) NaviShowPlaces(playerid, inputtext);
- return 1;
- } else if(dialogid == NAVI_DIALOG_SUBCATEGORIES) {
- if(response) {
- NaviShowPlaces(playerid, inputtext);
- } else {
- NaviShowCategories(playerid);
- }
- } else if (dialogid == NAVI_DIALOG_PLACES) {
- if(response) {
- NaviSelectPlace(playerid, inputtext);
- } else {
- if(GetPVarInt(playerid, "navi_lastsubcategory"))
- NaviShowCategories(playerid, GetPVarInt(playerid, "navi_lastsubcategory"));
- else
- NaviShowCategories(playerid);
- }
- return 1;
- }
- return 0;
- }
- public OnPlayerEnterCheckpoint(playerid) {
- if(GetPVarInt(playerid, "checkpointtype") == 1) {
- SendClientMessage(playerid, 0xD8D8D8FF,"Navi: Ziel erreicht.");
- DisablePlayerCheckpoint(playerid);
- DeletePVar(playerid, "checkpointtype");
- return 1;
- }
- return 0;
- }
- CMD:navi(playerid, params[]) {
- if(GetPVarInt(playerid, "navidisabled"))
- return SendClientMessage(playerid, 0xFF3333FF, "Du kannst die Navigation hier nicht benutzen.");
- NaviShowCategories(playerid);
- return 1;
- }
- NaviShowCategories(playerid, sub = 0) {
- new categories[512];
- format(QueryString, sizeof(QueryString), "SELECT `name` FROM `navi_categories` WHERE `navilevel` <= %d AND `sub` = %d ORDER BY `name`", GetPVarInt(playerid, "navilevel"), sub);
- mysql_query(QueryString);
- mysql_store_result();
- while(mysql_retrieve_row()) {
- mysql_fetch_field_row(tmp, "name");
- strcat(categories, tmp);
- strcat(categories, "\n");
- }
- if(sub) {
- new subname[128];
- format(QueryString, sizeof(QueryString), "SELECT `name` FROM `navi_categories` WHERE `id` = %d", sub);
- mysql_query(QueryString);
- mysql_store_result();
- if(mysql_retrieve_row())
- mysql_fetch_field_row(subname, "name");
- mysql_free_result();
- format(Message, sizeof(Message), "Navigation - %s", subname);
- ShowPlayerDialog(playerid, NAVI_DIALOG_SUBCATEGORIES, DIALOG_STYLE_LIST, Message, categories, "Ausw\228;hlen", "Zur\252;ck");
- } else {
- ShowPlayerDialog(playerid, NAVI_DIALOG_CATEGORIES, DIALOG_STYLE_LIST, "Navigation - Kategorien", categories, "Ausw\228;hlen", "Schlie\223;en");
- DeletePVar(playerid, "navi_lastsubcategory");
- }
- DeletePVar(playerid, "navi_lastcategory");
- mysql_free_result();
- return 1;
- }
- NaviShowPlaces(playerid, inputtext[]) {
- new Category[128];
- new CategoryId;
- new commands[2048];
- strcat(Category, inputtext);
- mysql_real_escape_string(Category, Category);
- if(GetPVarInt(playerid, "navi_lastcategory")) {
- CategoryId = GetPVarInt(playerid, "navi_lastcategory");
- format(QueryString, sizeof(QueryString), "SELECT `name` FROM `navi_categories` WHERE `id` = '%d'", CategoryId);
- mysql_query(QueryString);
- mysql_store_result();
- if(mysql_retrieve_row())
- mysql_fetch_field_row(Category, "name");
- mysql_free_result();
- } else {
- format(QueryString, sizeof(QueryString), "SELECT `id` FROM `navi_categories` WHERE `name` = '%s'", Category);
- mysql_query(QueryString);
- mysql_store_result();
- CategoryId = mysql_fetch_int();
- mysql_free_result();
- }
- SetPVarInt(playerid, "navi_lastcategory", CategoryId);
- format(QueryString, sizeof(QueryString), "SELECT NULL FROM `navi_categories` WHERE `sub` = %d", CategoryId);
- mysql_query(QueryString);
- mysql_store_result();
- if(mysql_retrieve_row()) {
- SetPVarInt(playerid, "navi_lastsubcategory", CategoryId);
- NaviShowCategories(playerid, CategoryId);
- return 1;
- }
- mysql_free_result();
- format(QueryString, sizeof(QueryString), "SELECT `name` FROM `navi_places` WHERE `category` = %d ORDER BY `name`", CategoryId);
- mysql_query(QueryString);
- mysql_store_result();
- while(mysql_retrieve_row()) {
- mysql_fetch_field_row(tmp, "name");
- strcat(commands, tmp);
- strcat(commands, "\n");
- }
- mysql_free_result();
- format(Message, sizeof(Message), "Navigation - %s", Category);
- ShowPlayerDialog(playerid, NAVI_DIALOG_PLACES, DIALOG_STYLE_LIST, Message, commands, "Ausw\228;hlen", "Zur\252;ck");
- return 1;
- }
- NaviSelectPlace(playerid, inputtext[]) {
- new name[256];
- strcat(name, inputtext);
- mysql_real_escape_string(name, name);
- format(QueryString, sizeof(QueryString), "SELECT * FROM `navi_places` WHERE `name` = '%s' AND `category` = %d", name, GetPVarInt(playerid, "navi_lastcategory"));
- mysql_query(QueryString);
- mysql_store_result();
- if(mysql_retrieve_row()) {
- new pid;
- mysql_fetch_field_row(tmp, "id");
- pid = strval(tmp);
- if (pid == 36) {
- enum pnsPos_ {
- Float:pposx,
- Float:pposy,
- Float:pposz
- }
- new pnsPos[10][pnsPos_] = {
- {-1904.7391,273.8949,41.0469},
- {-2425.5103,1032.3198,50.3906},
- {488.3104,-1731.2484,11.2403},
- {1965.2585,2162.0024,10.8203},
- {719.7296,-466.5216,16.3437},
- {1025.5741,-1030.9137,32.0172},
- {1024.7762,-1030.6993,32.0322},
- {2073.6882,-1831.4650,13.5469},
- {-99.9173,1105.1434,19.7422},
- {-1421.3560,2599.7688,55.6875}
- };
- new Float:Min = 100000, Mini;
- for(new i = 0; i < sizeof(pnsPos); i++) {
- if (GetPlayerDistanceToPoint(playerid, pnsPos[i][pposx], pnsPos[i][pposy], pnsPos[i][pposz]) < Min) {
- Min = GetPlayerDistanceToPoint(playerid, pnsPos[i][pposx], pnsPos[i][pposy], pnsPos[i][pposz]);
- Mini = i;
- }
- }
- SendClientMessage(playerid, 0xD8D8D8FF,"{D8D8D8}Navi: Marker beim der {FFFFFF}n\228;chsten Pay and Spray {D8D8D8}gesetzt");
- SetPlayerCheckpoint(playerid, pnsPos[Mini][pposx], pnsPos[Mini][pposy], pnsPos[Mini][pposz], 4.0);
- SetPVarInt(playerid, "checkpointtype", 1);
- } else {
- new Float:nposx, Float:nposy, Float:nposz;
- mysql_fetch_field_row(tmp, "posx");
- nposx = floatstr(tmp);
- mysql_fetch_field_row(tmp, "posy");
- nposy = floatstr(tmp);
- mysql_fetch_field_row(tmp, "posz");
- nposz = floatstr(tmp);
- format(Message, sizeof(Message), "{D8D8D8}Navi: Marker bei {FFFFFF}%s {D8D8D8}gesetzt.", name);
- SendClientMessage(playerid, 0xD8D8D8FF, Message);
- SetPlayerCheckpoint(playerid, nposx, nposy, nposz, 4.0);
- SetPVarInt(playerid, "checkpointtype", 1);
- }
- } else {
- SendClientMessage(playerid, 0xFF3333FF, "Ein unerwarteter Fehler ist aufgetreten.");
- }
- mysql_free_result();
- return 1;
- }
- Float:GetPlayerDistanceToPoint(playerid, Float:x1, Float:y1, Float:z1) {
- new Float:x2,Float:y2,Float:z2;
- GetPlayerPos(playerid,x2,y2,z2);
- return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement