Advertisement
Shiny_

Untitled

Sep 17th, 2013
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.93 KB | None | 0 0
  1. // Includes:
  2.     #include <iostream>
  3.     #include <string>
  4.  
  5.     /* SA-MP GDK: */
  6.     #include <sampgdk/a_objects.hpp>
  7.     #include <sampgdk/a_players.hpp>
  8.     #include <sampgdk/a_samp.hpp>
  9.     #include <sampgdk/a_vehicles.hpp>
  10.     #include <sampgdk/core.hpp>
  11.     #include <sampgdk/plugin.h>
  12.  
  13.     /* SQLite: */
  14.     // #include "sqlite3.h"
  15.  
  16.     /* Namespace: */
  17.     using namespace std;
  18.     /* Pragmas: */
  19.     // #pragma comment(lib, "sqlite3.lib")
  20.     #pragma comment(lib, "sampgdk3.lib")
  21.  
  22. // Macros:
  23.     #define PUBLIC PLUGIN_EXPORT bool PLUGIN_CALL
  24.     #define BindKey(key)                                                                                            \
  25.             if(newkeys & BindKey_(key))
  26.     #define EXPORTING(Plugin_Name)                                                                                  \
  27.             PLUGIN_EXPORT bool PLUGIN_CALL Load(void ** ppData) {return Plugin_Name.Load(ppData) >= NULL;}          \
  28.             PLUGIN_EXPORT void PLUGIN_CALL Unload() {Plugin_Name.Unload();}                                         \
  29.             PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {return SUPPORTS_VERSION | SUPPORTS_PROCESS_TICK;}    \
  30.             PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {Plugin_Name.ProcessTimers();}
  31.     /*#define DB_NAME                                                                                                   \
  32.             "scriptfiles/PSD.db"
  33.     #define TABLE_NAME                                                                                              \
  34.             "PSD"*/
  35.  
  36. // Variables:
  37.     static ThisPlugin PSD;
  38.     char Speed3DText[MAX_PLAYERS];
  39.     char CarFireObject[MAX_PLAYERS];
  40.     float xyz[3][MAX_PLAYERS];
  41.  
  42. // Functions:
  43.     inline static int SetTimer(TimerCallback callback, int interval, bool repeat, void * param = 0) {
  44.         return SetTimer(interval, repeat, callback, param);
  45.     }
  46.  
  47.     int BindKey_(char * key) {
  48.         if(!strcmp("action", key)) return KEY_ACTION;
  49.         else if(!strcmp("crouch", key)) return KEY_CROUCH;
  50.         else if(!strcmp("fire", key)) return KEY_FIRE;
  51.         else if(!strcmp("sprint", key)) return KEY_SPRINT;
  52.         else if(!strcmp("attack", key)) return KEY_SECONDARY_ATTACK;
  53.         else if(!strcmp("jump", key)) return KEY_JUMP;
  54.         else if(!strcmp("lookr", key)) return KEY_LOOK_RIGHT;
  55.         else if(!strcmp("lookl", key)) return KEY_LOOK_LEFT;
  56.         else if(!strcmp("lookb", key)) return KEY_LOOK_BEHIND;
  57.         else if(!strcmp("handbrake", key)) return KEY_HANDBRAKE;
  58.         else if(!strcmp("submission", key)) return KEY_SUBMISSION;
  59.         else if(!strcmp("walk", key)) return KEY_WALK;
  60.         else if(!strcmp("aup", key)) return KEY_ANALOG_UP;
  61.         else if(!strcmp("adown", key)) return KEY_ANALOG_DOWN;
  62.         else if(!strcmp("aleft", key)) return KEY_ANALOG_LEFT;
  63.         else if(!strcmp("aright", key)) return KEY_ANALOG_RIGHT;
  64.         else if(!strcmp("yes", key)) return KEY_YES;
  65.         else if(!strcmp("no", key)) return KEY_NO;
  66.         else if(!strcmp("ctrlback", key)) return KEY_NO;
  67.         else if(!strcmp("up", key)) return KEY_UP;
  68.         else if(!strcmp("down", key)) return KEY_DOWN;
  69.         else if(!strcmp("left", key)) return KEY_LEFT;
  70.         else if(!strcmp("right", key)) return KEY_RIGHT;
  71.         else return false;
  72.     }
  73.  
  74.     float GetSpeed(int playerid) {
  75.         IsPlayerInAnyVehicle(playerid)? GetVehicleVelocity(GetPlayerVehicleID(playerid), &xyz[0][playerid], &xyz[1][playerid], &xyz[2][playerid]):
  76.             GetPlayerVelocity(playerid, &xyz[0][playerid], &xyz[1][playerid], &xyz[2][playerid]);
  77.         return 235 * sqrtf(powf(xyz[2][playerid], 2) + powf(xyz[1][playerid], 2) + powf(xyz[0][playerid], 2));
  78.     }
  79.  
  80.     /*void asm_eq(int dword_name, int value) {
  81.         __asm {mov dword ptr dword_name, value};
  82.     }*/
  83.  
  84. // Public functions:
  85.     PUBLIC OnGameModeInit() {
  86.         int j;
  87.         __asm mov dword ptr j, 7; // j = 7
  88.         sampgdk_logprintf("j = %d", j);
  89.  
  90.         /*int rc;
  91.         char * error;
  92.         sampgdk_logprintf("Otwieranie bazy "DB_NAME"...");
  93.         sqlite3 * db;
  94.         rc = sqlite3_open(DB_NAME, &db);
  95.         if(rc) {
  96.             sampgdk_logprintf("Błąd podczas otwierania bazy danych: %s", sqlite3_errmsg(db));
  97.             sqlite3_close(db);
  98.             return true;
  99.         } else sampgdk_logprintf("Otwarto bazę "DB_NAME".");
  100.        
  101.         sampgdk_logprintf("Tworzenie tabeli "TABLE_NAME"...");
  102.        
  103.         const char * sqlCreateTable = "CREATE TABLE "TABLE_NAME"(id INTEGER PRIMARY KEY, value STRING);";
  104.         rc = sqlite3_exec(db, sqlCreateTable, NULL, NULL, &error);
  105.         if(rc) {
  106.             sampgdk_logprintf("Wystąpił błąd podczas tworzenia bazy danych: %s", sqlite3_errmsg(db));
  107.             sqlite3_free(error);
  108.         } else sampgdk_logprintf("Stworzono tabelę "TABLE_NAME".");
  109.        
  110.         sampgdk_logprintf("Wstawianie wartości do tabeli "TABLE_NAME"...");
  111.  
  112.         const char * sqlInsert = "INSERT INTO "TABLE_NAME" VALUES(NULL, 'COCIETOINTERESI');";
  113.         rc = sqlite3_exec(db, sqlInsert, NULL, NULL, &error);
  114.         if(rc) {
  115.             sampgdk_logprintf("Wystąpił błąd podczas tworzenia bazy danych: %s", sqlite3_errmsg(db));
  116.             sqlite3_free(error);
  117.         } else sampgdk_logprintf("Wstawiono wartości do tabeli "TABLE_NAME".");
  118.        
  119.         sampgdk_logprintf("Odczytywanie wartości z tabeli "TABLE_NAME"...");
  120.  
  121.         const char * sqlSelect = "SELECT * FROM "TABLE_NAME";";
  122.         char ** results = NULL;
  123.         int rows, columns;
  124.         sqlite3_get_table(db, sqlSelect, &results, &rows, &columns, &error);
  125.         if(rc) {
  126.             sampgdk_logprintf("Wystąpił błąd podczas tworzenia bazy danych: %s", sqlite3_errmsg(db));
  127.             sqlite3_free(error);
  128.         } else {
  129.             for(int rowCtr = 0; rowCtr <= rows; ++rowCtr) {
  130.                 for(int colCtr = 0; colCtr < columns; ++colCtr) {
  131.                     int cellPosition = (rowCtr * columns) + colCtr;
  132.                     cout.width(12);
  133.                     cout.setf(ios::left);
  134.                     cout << results[cellPosition] << " ";
  135.                 }
  136.                 cout << endl;
  137.                 if (0 == rowCtr) {
  138.                     for(int colCtr = 0; colCtr < columns; ++colCtr) {
  139.                         cout.width(12);
  140.                         cout.setf(ios::left);
  141.                         cout << "~~~~~~~~~~~~ ";
  142.                     }
  143.                     cout << endl;
  144.                 }
  145.             }
  146.         }
  147.         sqlite3_free_table(results);
  148.         sampgdk_logprintf("Zamykanie "DB_NAME"...");
  149.         sqlite3_close(db);*/
  150.         return true;
  151.     }
  152.  
  153.     PUBLIC OnPlayerUpdate(int playerid) {
  154.         char str[128];
  155.         IsPlayerInAnyVehicle(playerid)? sprintf(str, "%0.2f km/h", GetSpeed(playerid)), UpdatePlayer3DTextLabelText(playerid, Speed3DText[playerid], -1, str): false;
  156.         return true;
  157.         return true;
  158.     }
  159.    
  160.     PUBLIC OnPlayerStateChange(int playerid, int newstate, int oldstate) {
  161.         newstate == PLAYER_STATE_DRIVER? Speed3DText[playerid] = CreatePlayer3DTextLabel(playerid, "Infernus\n666 KM/H", -1, 0, 0, 0, 15.0, INVALID_PLAYER_ID, GetPlayerVehicleID(playerid), 1): false;
  162.         oldstate == PLAYER_STATE_DRIVER? DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]): false;
  163.         return true;
  164.     }
  165.    
  166.     PUBLIC OnPlayerKeyStateChange(int playerid, int newkeys, int oldkeys) {
  167.         if(IsValidObject(CarFireObject[playerid]) == 0) {
  168.             CarFireObject[playerid] = CreateObject(18694, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 500.0f);
  169.             AttachObjectToVehicle(CarFireObject[playerid], GetPlayerVehicleID(playerid), 0.0f, -2.3f, 1.2f, 180.0f, 0.0f, 0.0f);
  170.             AddVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  171.         }
  172.        
  173.         BindKey("submission") {
  174.             RepairVehicle(GetPlayerVehicleID(playerid));
  175.             GameTextForPlayer(playerid,"~y~Pojazd naprawiony!", 2000, 5);
  176.             PlayerPlaySound(playerid, 1133, 0.0f, 0.0f, 0.0f);
  177.         }
  178.         return true;
  179.     }
  180.     PUBLIC OnPlayerDisconnect(int playerid, int reason) {
  181.         !IsPlayerConnected(playerid)? DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]): false;
  182.         return true;
  183.     }
  184.  
  185. // Exports:
  186.     EXPORTING(PSD);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement