Advertisement
Shiny_

PSD

Sep 19th, 2013
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.52 KB | None | 0 0
  1. // Includes:
  2.     #include <cmath>
  3.     #include <iostream>
  4.     #include <string>
  5.  
  6.     /* SA-MP GDK: */
  7.     #include <sampgdk/a_objects.hpp>
  8.     #include <sampgdk/a_players.hpp>
  9.     #include <sampgdk/a_samp.hpp>
  10.     #include <sampgdk/a_vehicles.hpp>
  11.     #include <sampgdk/core.hpp>
  12.     #include <sampgdk/plugin.h>
  13.  
  14.     /* SQLite: */
  15.     // #include "SQLite3/sqlite3.h"
  16.  
  17.     /* Namespace: */
  18.     using namespace std;
  19.  
  20.     /* Pragmas: */
  21.     // #pragma comment(lib, "sqlite3.lib")
  22.     #pragma comment(lib, "sampgdk3.lib")
  23.  
  24. // Macros:
  25.     #define PUBLIC                                                                                                  \
  26.             PLUGIN_EXPORT bool PLUGIN_CALL
  27.     #define BindKey(key)                                                                                            \
  28.             if(newkeys & BindKey_(key))
  29.     #define EXPORTING(Plugin_Name)                                                                                  \
  30.             PLUGIN_EXPORT bool PLUGIN_CALL Load(void ** ppData) {return Plugin_Name.Load(ppData) >= NULL;}          \
  31.             PLUGIN_EXPORT void PLUGIN_CALL Unload() {Plugin_Name.Unload();}                                         \
  32.             PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {return SUPPORTS_VERSION | SUPPORTS_PROCESS_TICK;}    \
  33.             PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {Plugin_Name.ProcessTimers();}
  34. /*
  35.     #define DB_NAME                                                                                                 \
  36.             "scriptfiles/PSD.db"
  37.     #define TABLE_NAME                                                                                              \
  38.             "PSD"
  39. */
  40.  
  41. // Variables:
  42.     static ThisPlugin PSD;
  43.    
  44.     /* Char: */
  45.     char str[MAX_PLAYERS][128];
  46.     char Speed3DText[MAX_PLAYERS];
  47.     char CarFireObject[MAX_PLAYERS];
  48.     char gVehicleNames[212][32] = {
  49.         "Landstalker", "Bravura", "Buffalo", "Linerunner", "Pereniel", "Sentinel", "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana",
  50.         "Infernus", "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam", "Esperanto", "Taxi", "Washington", "Bobcat",
  51.         "Mr Whoopee", "BF Injection", "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus", "Rhino", "Barracks",
  52.         "Hotknife", "Trailer", "Previon", "Coach", "Cabbie", "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
  53.         "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder", "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy",
  54.         "Solair", "Berkley's RC Van", "Skimmer", "PCJ-600", "Faggio", "Harley", "RC Baron", "RC Raider", "Glendale", "Oceanic",
  55.         "Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy", "Hermes", "Sabre", "Rustler", "ZR3 50", "Walton", "Regina",
  56.         "Comet", "BMX", "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper", "Rancher", "FBI Rancher",
  57.         "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking", "Blista Compact", "Police Maverick", "Boxville", "Benson", "Mesa",
  58.         "RC Goblin", "Hotring Racer", "Hotring Racer", "Bloodring Banger", "Rancher", "Super GT", "Elegant", "Journey", "Bike",
  59.         "Mountain Bike", "Beagle", "Cropdust", "Stunt", "Tanker", "RoadTrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
  60.         "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune", "Cadrona", "FBI Truck", "Willard", "Forklift", "Traktor",
  61.         "Combine", "Feltzer", "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent", "Bullet", "Clover", "Sadler",
  62.         "Firetruck", "Hustler", "Intruder", "Primo", "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite", "Windsor",
  63.         "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratum", "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna",
  64.         "Bandito", "Freight", "Trailer", "Kart", "Mower", "Duneride", "Sweeper", "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley",
  65.         "Stafford", "BF-400", "Newsvan", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club", "Trailer", "Trailer",
  66.         "Andromeda", "Dodo", "RC Cam", "Launch", "Radiowoz", "Radiowoz", "Radiowoz", "Radiowoz", "Picador", "S.W.A.T. Van",
  67.         "Alpha", "Phoenix", "Glendale", "Sadler", "Luggage Trailer", "Luggage Trailer", "Stair Trailer", "Boxville", "Farm Plow", "Utility Trailer"
  68.     };
  69.    
  70.     /* Float: */
  71.     float Health[MAX_PLAYERS];
  72.     float xyz[MAX_PLAYERS][3];
  73.  
  74.     enum A {
  75.         test,
  76.     };
  77.  
  78. // Functions:
  79.     inline static int SetTimer(TimerCallback callback, int interval, bool repeat, void * param = 0) {
  80.         return SetTimer(interval, repeat, callback, param);
  81.     }
  82.  
  83.     int BindKey_(char * key) {
  84.         if(!strcmp("action", key)) return KEY_ACTION;
  85.         else if(!strcmp("crouch", key)) return KEY_CROUCH;
  86.         else if(!strcmp("fire", key)) return KEY_FIRE;
  87.         else if(!strcmp("sprint", key)) return KEY_SPRINT;
  88.         else if(!strcmp("attack", key)) return KEY_SECONDARY_ATTACK;
  89.         else if(!strcmp("jump", key)) return KEY_JUMP;
  90.         else if(!strcmp("lookr", key)) return KEY_LOOK_RIGHT;
  91.         else if(!strcmp("lookl", key)) return KEY_LOOK_LEFT;
  92.         else if(!strcmp("lookb", key)) return KEY_LOOK_BEHIND;
  93.         else if(!strcmp("handbrake", key)) return KEY_HANDBRAKE;
  94.         else if(!strcmp("submission", key)) return KEY_SUBMISSION;
  95.         else if(!strcmp("walk", key)) return KEY_WALK;
  96.         else if(!strcmp("aup", key)) return KEY_ANALOG_UP;
  97.         else if(!strcmp("adown", key)) return KEY_ANALOG_DOWN;
  98.         else if(!strcmp("aleft", key)) return KEY_ANALOG_LEFT;
  99.         else if(!strcmp("aright", key)) return KEY_ANALOG_RIGHT;
  100.         else if(!strcmp("yes", key)) return KEY_YES;
  101.         else if(!strcmp("no", key)) return KEY_NO;
  102.         else if(!strcmp("ctrlback", key)) return KEY_NO;
  103.         else if(!strcmp("up", key)) return KEY_UP;
  104.         else if(!strcmp("down", key)) return KEY_DOWN;
  105.         else if(!strcmp("left", key)) return KEY_LEFT;
  106.         else if(!strcmp("right", key)) return KEY_RIGHT;
  107.         else return false;
  108.     }
  109.    
  110.     float sub(float x, float y) {
  111.         return x - y;
  112.     }
  113.  
  114.     float GetPlayerDistanceToPointIn3D(int playerid, float x, float y, float z) {
  115.         float x1;
  116.         float y1;
  117.         float z1;
  118.         float mpt2dis;
  119.         GetPlayerPos(playerid, &x1, &y1, &z1);
  120.         mpt2dis = sqrtf(powf(abs(sub(x, x1)), 2) + powf(abs(sub(y, y1)), 2) + powf(abs(sub(z, z1)), 2));
  121.         return floorf(mpt2dis + (float) 0.5);
  122.     }
  123.    
  124.     bool IsPlayerInCircle(int playerid, float x, float y, float z, float radius) {
  125.         if(GetPlayerDistanceToPointIn3D(playerid, x, y, z) < radius) return true;
  126.         return false;
  127.     }
  128.  
  129.     float GetSpeed(int playerid) {
  130.         IsPlayerInAnyVehicle(playerid)? GetVehicleVelocity(GetPlayerVehicleID(playerid), &xyz[0][playerid], &xyz[1][playerid], &xyz[2][playerid]):
  131.             GetPlayerVelocity(playerid, &xyz[0][playerid], &xyz[1][playerid], &xyz[2][playerid]);
  132.         return /*235 */160 * sqrtf(powf(xyz[2][playerid], 2) + powf(xyz[1][playerid], 2) + powf(xyz[0][playerid], 2));
  133.     }
  134.  
  135. // Public functions:
  136.     PUBLIC OnPlayerUpdate(int playerid) {
  137.         GetVehicleHealth(GetPlayerVehicleID(playerid), &Health[playerid]);
  138.         IsPlayerInAnyVehicle(playerid)?
  139.             sprintf
  140.             (
  141.                 str[playerid], "[%s]\n%0.1f km/h\n%0.1f/1000.0",
  142.                 &gVehicleNames[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400],
  143.                 GetSpeed(playerid),
  144.                 Health[playerid]
  145.             ), UpdatePlayer3DTextLabelText(playerid, Speed3DText[playerid], -1, str[playerid]): false;
  146.         return true;
  147.     }
  148.    
  149.     PUBLIC OnPlayerStateChange(int playerid, int newstate, int oldstate) {
  150.         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;
  151.         oldstate == PLAYER_STATE_DRIVER? DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]): false;
  152.         return true;
  153.     }
  154.    
  155.     PUBLIC OnPlayerKeyStateChange(int playerid, int newkeys, int oldkeys) {
  156.         if((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
  157.             if(IsValidObject(CarFireObject[playerid]) == 0) {
  158.                 CarFireObject[playerid] = CreateObject(18694, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 500.0f);
  159.                 AttachObjectToVehicle(CarFireObject[playerid], GetPlayerVehicleID(playerid), 0.0f, -2.3f, 1.2f, 180.0f, 0.0f, 0.0f);
  160.             }
  161.             AddVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  162.             !IsPlayerInAnyVehicle(playerid)? RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010), DestroyObject(CarFireObject[playerid]): false;
  163.             return true;
  164.         }
  165.        
  166.         else if((oldkeys & KEY_FIRE) && !(newkeys & KEY_FIRE) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
  167.             DestroyObject(CarFireObject[playerid]);
  168.             RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  169.             return true;
  170.         }
  171.    
  172.         BindKey("submission") {
  173.             RepairVehicle(GetPlayerVehicleID(playerid));
  174.             GameTextForPlayer(playerid,"~y~Pojazd naprawiony!", 2000, 5);
  175.             PlayerPlaySound(playerid, 1133, 0.0f, 0.0f, 0.0f);
  176.         }
  177.         return true;
  178.     }
  179.  
  180.     PUBLIC OnPlayerDisconnect(int playerid, int reason) {
  181.         !IsPlayerConnected(playerid)? DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]): false;
  182.         IsValidObject(CarFireObject[playerid])? DestroyObject(CarFireObject[playerid]): false;
  183.         return true;
  184.     }
  185.  
  186. // Exports:
  187.     EXPORTING(PSD);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement