Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Includes:
- #include <iostream>
- #include <string>
- /* SA-MP GDK: */
- #include <sampgdk/a_objects.hpp>
- #include <sampgdk/a_players.hpp>
- #include <sampgdk/a_samp.hpp>
- #include <sampgdk/a_vehicles.hpp>
- #include <sampgdk/core.hpp>
- #include <sampgdk/plugin.h>
- /* SQLite: */
- // #include "sqlite3.h"
- /* Namespace: */
- using namespace std;
- /* Pragmas: */
- // #pragma comment(lib, "sqlite3.lib")
- #pragma comment(lib, "sampgdk3.lib")
- // Macros:
- #define PUBLIC PLUGIN_EXPORT bool PLUGIN_CALL
- #define BindKey(key) \
- if(newkeys & BindKey_(key))
- #define EXPORTING(Plugin_Name) \
- PLUGIN_EXPORT bool PLUGIN_CALL Load(void ** ppData) {return Plugin_Name.Load(ppData) >= NULL;} \
- PLUGIN_EXPORT void PLUGIN_CALL Unload() {Plugin_Name.Unload();} \
- PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {return SUPPORTS_VERSION | SUPPORTS_PROCESS_TICK;} \
- PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {Plugin_Name.ProcessTimers();}
- /*#define DB_NAME \
- "scriptfiles/PSD.db"
- #define TABLE_NAME \
- "PSD"*/
- // Variables:
- static ThisPlugin PSD;
- char Speed3DText[MAX_PLAYERS];
- char CarFireObject[MAX_PLAYERS];
- float xyz[3][MAX_PLAYERS];
- // Functions:
- inline static int SetTimer(TimerCallback callback, int interval, bool repeat, void * param = 0) {
- return SetTimer(interval, repeat, callback, param);
- }
- int BindKey_(char * key) {
- if(!strcmp("action", key)) return KEY_ACTION;
- else if(!strcmp("crouch", key)) return KEY_CROUCH;
- else if(!strcmp("fire", key)) return KEY_FIRE;
- else if(!strcmp("sprint", key)) return KEY_SPRINT;
- else if(!strcmp("attack", key)) return KEY_SECONDARY_ATTACK;
- else if(!strcmp("jump", key)) return KEY_JUMP;
- else if(!strcmp("lookr", key)) return KEY_LOOK_RIGHT;
- else if(!strcmp("lookl", key)) return KEY_LOOK_LEFT;
- else if(!strcmp("lookb", key)) return KEY_LOOK_BEHIND;
- else if(!strcmp("handbrake", key)) return KEY_HANDBRAKE;
- else if(!strcmp("submission", key)) return KEY_SUBMISSION;
- else if(!strcmp("walk", key)) return KEY_WALK;
- else if(!strcmp("aup", key)) return KEY_ANALOG_UP;
- else if(!strcmp("adown", key)) return KEY_ANALOG_DOWN;
- else if(!strcmp("aleft", key)) return KEY_ANALOG_LEFT;
- else if(!strcmp("aright", key)) return KEY_ANALOG_RIGHT;
- else if(!strcmp("yes", key)) return KEY_YES;
- else if(!strcmp("no", key)) return KEY_NO;
- else if(!strcmp("ctrlback", key)) return KEY_NO;
- else if(!strcmp("up", key)) return KEY_UP;
- else if(!strcmp("down", key)) return KEY_DOWN;
- else if(!strcmp("left", key)) return KEY_LEFT;
- else if(!strcmp("right", key)) return KEY_RIGHT;
- else return false;
- }
- float GetSpeed(int playerid) {
- IsPlayerInAnyVehicle(playerid)? GetVehicleVelocity(GetPlayerVehicleID(playerid), &xyz[0][playerid], &xyz[1][playerid], &xyz[2][playerid]):
- GetPlayerVelocity(playerid, &xyz[0][playerid], &xyz[1][playerid], &xyz[2][playerid]);
- return 235 * sqrtf(powf(xyz[2][playerid], 2) + powf(xyz[1][playerid], 2) + powf(xyz[0][playerid], 2));
- }
- /*void asm_eq(int dword_name, int value) {
- __asm {mov dword ptr dword_name, value};
- }*/
- // Public functions:
- PUBLIC OnGameModeInit() {
- int j;
- __asm mov dword ptr j, 7; // j = 7
- sampgdk_logprintf("j = %d", j);
- /*int rc;
- char * error;
- sampgdk_logprintf("Otwieranie bazy "DB_NAME"...");
- sqlite3 * db;
- rc = sqlite3_open(DB_NAME, &db);
- if(rc) {
- sampgdk_logprintf("Błąd podczas otwierania bazy danych: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- return true;
- } else sampgdk_logprintf("Otwarto bazę "DB_NAME".");
- sampgdk_logprintf("Tworzenie tabeli "TABLE_NAME"...");
- const char * sqlCreateTable = "CREATE TABLE "TABLE_NAME"(id INTEGER PRIMARY KEY, value STRING);";
- rc = sqlite3_exec(db, sqlCreateTable, NULL, NULL, &error);
- if(rc) {
- sampgdk_logprintf("Wystąpił błąd podczas tworzenia bazy danych: %s", sqlite3_errmsg(db));
- sqlite3_free(error);
- } else sampgdk_logprintf("Stworzono tabelę "TABLE_NAME".");
- sampgdk_logprintf("Wstawianie wartości do tabeli "TABLE_NAME"...");
- const char * sqlInsert = "INSERT INTO "TABLE_NAME" VALUES(NULL, 'COCIETOINTERESI');";
- rc = sqlite3_exec(db, sqlInsert, NULL, NULL, &error);
- if(rc) {
- sampgdk_logprintf("Wystąpił błąd podczas tworzenia bazy danych: %s", sqlite3_errmsg(db));
- sqlite3_free(error);
- } else sampgdk_logprintf("Wstawiono wartości do tabeli "TABLE_NAME".");
- sampgdk_logprintf("Odczytywanie wartości z tabeli "TABLE_NAME"...");
- const char * sqlSelect = "SELECT * FROM "TABLE_NAME";";
- char ** results = NULL;
- int rows, columns;
- sqlite3_get_table(db, sqlSelect, &results, &rows, &columns, &error);
- if(rc) {
- sampgdk_logprintf("Wystąpił błąd podczas tworzenia bazy danych: %s", sqlite3_errmsg(db));
- sqlite3_free(error);
- } else {
- for(int rowCtr = 0; rowCtr <= rows; ++rowCtr) {
- for(int colCtr = 0; colCtr < columns; ++colCtr) {
- int cellPosition = (rowCtr * columns) + colCtr;
- cout.width(12);
- cout.setf(ios::left);
- cout << results[cellPosition] << " ";
- }
- cout << endl;
- if (0 == rowCtr) {
- for(int colCtr = 0; colCtr < columns; ++colCtr) {
- cout.width(12);
- cout.setf(ios::left);
- cout << "~~~~~~~~~~~~ ";
- }
- cout << endl;
- }
- }
- }
- sqlite3_free_table(results);
- sampgdk_logprintf("Zamykanie "DB_NAME"...");
- sqlite3_close(db);*/
- return true;
- }
- PUBLIC OnPlayerUpdate(int playerid) {
- char str[128];
- IsPlayerInAnyVehicle(playerid)? sprintf(str, "%0.2f km/h", GetSpeed(playerid)), UpdatePlayer3DTextLabelText(playerid, Speed3DText[playerid], -1, str): false;
- return true;
- return true;
- }
- PUBLIC OnPlayerStateChange(int playerid, int newstate, int oldstate) {
- 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;
- oldstate == PLAYER_STATE_DRIVER? DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]): false;
- return true;
- }
- PUBLIC OnPlayerKeyStateChange(int playerid, int newkeys, int oldkeys) {
- if(IsValidObject(CarFireObject[playerid]) == 0) {
- CarFireObject[playerid] = CreateObject(18694, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 500.0f);
- AttachObjectToVehicle(CarFireObject[playerid], GetPlayerVehicleID(playerid), 0.0f, -2.3f, 1.2f, 180.0f, 0.0f, 0.0f);
- AddVehicleComponent(GetPlayerVehicleID(playerid), 1010);
- }
- BindKey("submission") {
- RepairVehicle(GetPlayerVehicleID(playerid));
- GameTextForPlayer(playerid,"~y~Pojazd naprawiony!", 2000, 5);
- PlayerPlaySound(playerid, 1133, 0.0f, 0.0f, 0.0f);
- }
- return true;
- }
- PUBLIC OnPlayerDisconnect(int playerid, int reason) {
- !IsPlayerConnected(playerid)? DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]): false;
- return true;
- }
- // Exports:
- EXPORTING(PSD);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement