Advertisement
Shiny_

Untitled

Sep 27th, 2013
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.13 KB | None | 0 0
  1. // Includes:
  2.     #include <conio.h>
  3.     #include <cstdlib>
  4.     #include <ctime>
  5.     #include <iostream>
  6.     #include <string>
  7.  
  8.     /* SA-MP GDK: */
  9.     #include <sampgdk/a_objects.hpp>
  10.     #include <sampgdk/a_players.hpp>
  11.     #include <sampgdk/a_samp.hpp>
  12.     #include <sampgdk/a_vehicles.hpp>
  13.     #include <sampgdk/core.hpp>
  14.     #include <sampgdk/plugin.h>
  15.  
  16.     /* Namespace: */
  17.     using namespace std;
  18.  
  19.     /* Pragmas: */
  20.     #pragma comment(lib, "sampgdk3.lib")
  21.  
  22. // Macros:
  23.     #ifndef foreach
  24.         #define foreach(integer, value)                                                                                 \
  25.                 for(int integer = NULL; integer != value; integer++)
  26.     #endif
  27.     #ifndef PUBLIC
  28.         #define PUBLIC                                                                                                  \
  29.                 PLUGIN_EXPORT bool PLUGIN_CALL
  30.     #endif
  31.     #ifndef Bindkey
  32.         #define BindKey(key)                                                                                            \
  33.                 if(newkeys & PSD.BindKey_(key))
  34.     #endif
  35.     #ifndef EXPORTING
  36.         #define EXPORTING(Plugin_Name)                                                                                  \
  37.                 PLUGIN_EXPORT bool PLUGIN_CALL Load(void ** ppData) {return Plugin_Name.Load(ppData) >= NULL;}          \
  38.                 PLUGIN_EXPORT void PLUGIN_CALL Unload() {Plugin_Name.Unload();}                                         \
  39.                 PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {return SUPPORTS_VERSION | SUPPORTS_PROCESS_TICK;}    \
  40.                 PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {Plugin_Name.ProcessTimers();}
  41.     #endif
  42.     #ifndef TIMER
  43.         #define TIMER                                                                                                   \
  44.                 static void SAMPGDK_CALL
  45.     #endif
  46.  
  47. // Classess:
  48.     class c_PSD {
  49.         public:
  50.         // Variables:
  51.             /* Integers: */
  52.             int VelocityTimer[MAX_PLAYERS];
  53.  
  54.             /* Chars: */
  55.             char str[MAX_PLAYERS][170];
  56.             char Speed3DText[MAX_PLAYERS];
  57.             char CarFireObject[MAX_PLAYERS];
  58.             char Name[MAX_PLAYERS][MAX_PLAYER_NAME];
  59.  
  60.             /* Floats: */
  61.             float Pos[MAX_PLAYERS][3];
  62.             float Health[MAX_PLAYERS];
  63.             float xyz[MAX_PLAYERS][3];
  64.             float Vel[MAX_PLAYERS][3];
  65.  
  66.         // Functions:
  67.             ~c_PSD();
  68.             int BindKey_(char * key);
  69.             int IsVehiclePlaneOrHelicopter(int vehicleid);
  70.             float GetSpeed(int playerid);
  71.             float SetSpeed(int playerid);
  72.             inline bool PlayAudioStreamForPlayer(int playerid, const char * url);
  73.             inline bool ApplyAnimation(int playerid, const char * animlib, const char * animname, float fDelta, bool loop, bool lockx, bool locky, bool freeze, int time);
  74.     };
  75.     c_PSD PSD;
  76.  
  77.     c_PSD::~c_PSD() {
  78.         strcpy(* str, "");
  79.         strcpy(Speed3DText, "");
  80.         strcpy(CarFireObject, "");
  81.         strcpy(* Name, "");
  82.         * Health = 0.0;
  83.         strcpy((char *)xyz, "");
  84.     }
  85.  
  86.     int c_PSD::BindKey_(char * key) {
  87.         if(!strcmp("action", key)) return KEY_ACTION;
  88.         else if(!strcmp("crouch", key)) return KEY_CROUCH;
  89.         else if(!strcmp("fire", key)) return KEY_FIRE;
  90.         else if(!strcmp("sprint", key)) return KEY_SPRINT;
  91.         else if(!strcmp("attack", key)) return KEY_SECONDARY_ATTACK;
  92.         else if(!strcmp("jump", key)) return KEY_JUMP;
  93.         else if(!strcmp("lookr", key)) return KEY_LOOK_RIGHT;
  94.         else if(!strcmp("lookl", key)) return KEY_LOOK_LEFT;
  95.         else if(!strcmp("lookb", key)) return KEY_LOOK_BEHIND;
  96.         else if(!strcmp("handbrake", key)) return KEY_HANDBRAKE;
  97.         else if(!strcmp("submission", key)) return KEY_SUBMISSION;
  98.         else if(!strcmp("walk", key)) return KEY_WALK;
  99.         else if(!strcmp("aup", key)) return KEY_ANALOG_UP;
  100.         else if(!strcmp("adown", key)) return KEY_ANALOG_DOWN;
  101.         else if(!strcmp("aleft", key)) return KEY_ANALOG_LEFT;
  102.         else if(!strcmp("aright", key)) return KEY_ANALOG_RIGHT;
  103.         else if(!strcmp("yes", key)) return KEY_YES;
  104.         else if(!strcmp("no", key)) return KEY_NO;
  105.         else if(!strcmp("ctrlback", key)) return KEY_NO;
  106.         else if(!strcmp("up", key)) return KEY_UP;
  107.         else if(!strcmp("down", key)) return KEY_DOWN;
  108.         else if(!strcmp("left", key)) return KEY_LEFT;
  109.         else if(!strcmp("right", key)) return KEY_RIGHT;
  110.         else return false;
  111.     }
  112.  
  113.     int c_PSD::IsVehiclePlaneOrHelicopter(int vehicleid) {
  114.         switch(vehicleid) {
  115.             case 417: case 425: case 447: case 460: case 464: case 465: case 469: case 476: case 487: case 488: case 497: case 501: case 511: case 512: case 513: case 519: case 520: case 539: case 553: case 548: case 563: case 577: case 592: case 593: return true; break;
  116.         }
  117.         return false;
  118.     }
  119.  
  120.     float c_PSD::GetSpeed(int playerid) {
  121.         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]);
  122.         return 160 * sqrtf(powf(xyz[2][playerid], 2) + powf(xyz[1][playerid], 2) + powf(xyz[0][playerid], 2));
  123.     }
  124.  
  125.     float c_PSD::SetSpeed(int playerid) {
  126.         IsPlayerInAnyVehicle(playerid)? SetVehicleVelocity(GetPlayerVehicleID(playerid), xyz[0][playerid], xyz[1][playerid], xyz[2][playerid]): SetPlayerVelocity(playerid, xyz[0][playerid], xyz[1][playerid], xyz[2][playerid]);
  127.         // return 160 * sqrtf(powf(xyz[2][playerid], 2) + powf(xyz[1][playerid], 2) + powf(xyz[0][playerid], 2));
  128.     }
  129.  
  130.     inline bool c_PSD::PlayAudioStreamForPlayer(int playerid, const char * url) {
  131.         float posX = 0.0;
  132.         float posY = 0.0;
  133.         float posZ = 0.0;
  134.         float distance = 0.0;
  135.         bool usepos = false;
  136.         return ::sampgdk_PlayAudioStreamForPlayer(playerid, url, posX, posY, posZ, distance, usepos);
  137.     }
  138.  
  139.     inline bool c_PSD::ApplyAnimation(int playerid, const char * animlib, const char * animname, float fDelta, bool loop, bool lockx, bool locky, bool freeze, int time) {
  140.         bool forcesync = false;
  141.         return ::sampgdk_ApplyAnimation(playerid, animlib, animname, fDelta, loop, lockx, locky, freeze, time, forcesync);
  142.     }
  143.  
  144. // Variables:
  145.     static ThisPlugin PSD_PLUGIN;
  146.  
  147.     char gVehicleNames[212][32] = {
  148.         "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel", "Dumper",
  149.         "Firetruck", "Trashmaster", "Stretch", "Manana", "Infernus", "Voodoo", "Pony", "Mule",
  150.         "Cheetah", "Ambulance", "Leviathan", "Moonbeam", "Esperanto", "Taxi", "Washington",
  151.         "Bobcat", "Mr Whoopee", "BF Injection", "Hunter", "Premier", "Enforcer", "Securicar",
  152.         "Banshee", "Predator", "Bus", "Rhino", "Barracks", "Hotknife", "Trailer 1", "Previon",
  153.         "Coach", "Cabbie", "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster",
  154.         "Admiral", "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer 2", "Turismo",
  155.         "Speeder", "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van",
  156.         "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale", "Oceanic",
  157.         "Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy", "Hermes", "Sabre",
  158.         "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX", "Burrito", "Camper", "Marquis",
  159.         "Baggage", "Dozer", "Maverick", "News Chopper", "Rancher", "FBI Rancher", "Virgo", "Greenwood",
  160.         "Jetmax", "Hotring", "Sandking", "Blista Compact", "Police Maverick", "Boxville", "Benson",
  161.         "Mesa", "RC Goblin", "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher",
  162.         "Super GT", "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropdust", "Stunt",
  163.         "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra", "FCR-900",
  164.         "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune", "Cadrona", "FBI Truck",
  165.         "Willard", "Forklift", "Tractor", "Combine", "Feltzer", "Remington", "Slamvan",
  166.         "Blade", "Freight", "Streak", "Vortex", "Vincent", "Bullet", "Clover", "Sadler",
  167.         "Firetruck LA", "Hustler", "Intruder", "Primo", "Cargobob", "Tampa", "Sunrise", "Merit",
  168.         "Utility", "Nevada", "Yosemite", "Windsor", "Monster A", "Monster B", "Uranus", "Jester",
  169.         "Sultan", "Stratum", "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna",
  170.         "Bandito", "Freight Flat", "Streak Carriage", "Kart", "Mower", "Duneride", "Sweeper",
  171.         "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400", "Newsvan",
  172.         "Tug", "Trailer 3", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club", "Freight Carriage",
  173.         "Trailer 3", "Andromada", "Dodo", "RC Cam", "Launch", "Police Car (LSPD)", "Police Car (SFPD)",
  174.         "Police Car (LVPD)", "Police Ranger", "Picador", "S.W.A.T. Van", "Alpha", "Phoenix", "Glendale",
  175.         "Sadler", "Luggage Trailer A", "Luggage Trailer B", "Stair Trailer", "Boxville", "Farm Plow",
  176.         "Utility Trailer"
  177.     };
  178.  
  179.     inline int SetTimer(TimerCallback callback, int interval, bool repeat, void * param = NULL) {
  180.         return SetTimer(interval, repeat, callback, param);
  181.     }
  182.    
  183.     inline int SetTimerEx(TimerCallback callback, int interval, bool repeat, void * param = NULL) {
  184.         return SetTimer(interval, repeat, callback, (void *) param);
  185.     }
  186.  
  187.     void SAMPGDK_CALL SetVelocity(int timerid, void * param) {
  188.         if(GetVehicleModel(GetPlayerVehicleID((int) param)) == 520) {
  189.             GetVehicleVelocity(GetPlayerVehicleID((int) param), &PSD.Vel[(int) param][0], &PSD.Vel[(int) param][1], &PSD.Vel[(int) param][2]);
  190.             SetVehicleVelocity(GetPlayerVehicleID((int) param), PSD.Vel[(int) param][0] + (float) 0.01, PSD.Vel[(int) param][1], PSD.Vel[(int) param][2]);
  191.         }
  192.         else if(PSD.Vel[(int) param][0] > 2.0) {// Około 480 KMH  {
  193.             SetVehicleVelocity(GetPlayerVehicleID((int) param), PSD.Vel[(int) param][0], PSD.Vel[(int) param][1], PSD.Vel[(int) param][2]);
  194.         }
  195.     }
  196.  
  197.    
  198. // Public functions:
  199.     PUBLIC OnGameModeInit() {
  200.         UsePlayerPedAnims();
  201.         for(int i = 0; i <= 299; i++) {
  202.             AddPlayerClass(i, -1399.0179f, 2640.7385f, 55.6875f, 0.0, 0, 0, 0, 0, 0, 0);
  203.         }
  204.         return true;
  205.     }
  206.  
  207.     PUBLIC OnPlayerUpdate(int playerid) {
  208.         GetPlayerName(playerid, PSD.Name[playerid], sizeof(PSD.Name[playerid]));
  209.         GetVehicleHealth(GetPlayerVehicleID(playerid), &PSD.Health[playerid]);
  210.         GetVehiclePos(GetPlayerVehicleID(playerid), &PSD.Pos[playerid][0], &PSD.Pos[playerid][1], &PSD.Pos[playerid][2]);
  211.         //GetVehicleZAngle(GetPlayerVehicleID(playerid), &PSD.Angle[playerid]);
  212.  
  213.         if(IsPlayerInAnyVehicle(playerid)) {
  214.             if(PSD.IsVehiclePlaneOrHelicopter(GetVehicleModel(GetPlayerVehicleID(playerid)))) {
  215.                 sprintf(PSD.str[playerid], "\n[%s]\n%0.0f KMH >\t< ALT %0.0f\n%0.1f/1000.0", &gVehicleNames[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400], PSD.GetSpeed(playerid), PSD.Pos[playerid][2], PSD.Health[playerid]);
  216.                 UpdatePlayer3DTextLabelText(playerid, PSD.Speed3DText[playerid], -1, PSD.str[playerid]);
  217.             } else {
  218.                 sprintf(PSD.str[playerid], "\n[%s]\n%0.1f km/h\n%0.1f/1000.0", &gVehicleNames[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400], PSD.GetSpeed(playerid), PSD.Health[playerid]);
  219.                 UpdatePlayer3DTextLabelText(playerid, PSD.Speed3DText[playerid], -1, PSD.str[playerid]);
  220.             }
  221.         }
  222.         return true;
  223.     }
  224.  
  225.     PUBLIC OnPlayerCommandText(int playerid, const char * cmdtext) {
  226.         if(!strcmp(cmdtext, "/life")) {
  227.             SetPlayerHealth(playerid, 100.0);
  228.             SetPlayerArmour(playerid, 100.0);
  229.             SendClientMessage(playerid, -1, "Dostajesz 100 punktów życia i pancerza.");
  230.             return true;
  231.         }
  232.         else if(!strcmp(cmdtext, "/kill")) {
  233.             SetPlayerHealth(playerid, -100.0);
  234.             return true;
  235.         }
  236.         else if(!strcmp(cmdtext, "/invisible")) {
  237.             if(GetPlayerColor(playerid) == 0xFFFFFF00) {
  238.                 return SendClientMessage(playerid, -1, "Masz już włączoną niewidzialność.");
  239.             }
  240.             SetPlayerColor(playerid, 0xFFFFFF00);
  241.             SendClientMessage(playerid, -1, "Włączasz niewidzialność.");
  242.             return true;
  243.         }
  244.         else if(!strcmp(cmdtext, "/visible")) {
  245.             SetPlayerColor(playerid, 0xFF000000);
  246.             SendClientMessage(playerid, -1, "Wyłączasz niewidzialność.");
  247.             return true;
  248.         }
  249.         else if(!strcmp(cmdtext, "/turbo")) {
  250.             PSD.VelocityTimer[playerid] = SetTimerEx(SetVelocity, 20, true, (void *) playerid);
  251.             SendClientMessage(playerid, -1, "Włączasz turbo w Hydrze.");
  252.             return true;
  253.         }
  254.         else if(!strcmp(cmdtext, "/turbo-off")) {
  255.             KillTimer(PSD.VelocityTimer[playerid]);
  256.             SendClientMessage(playerid, -1, "Wyłączasz dopalacz w Hydrze.");
  257.             return true;
  258.         }
  259.         return false;
  260.     }
  261.    
  262.     PUBLIC OnPlayerStateChange(int playerid, int newstate, int oldstate) {
  263.         newstate == PLAYER_STATE_DRIVER? PSD.Speed3DText[playerid] = CreatePlayer3DTextLabel(playerid, "Infernus\n666 KM/H", -1, 0, 0, 0, 15.0, INVALID_PLAYER_ID, GetPlayerVehicleID(playerid), 1): false;
  264.         oldstate == PLAYER_STATE_DRIVER? DeletePlayer3DTextLabel(playerid, PSD.Speed3DText[playerid]): false;
  265.         return true;
  266.     }
  267.    
  268.     PUBLIC OnPlayerKeyStateChange(int playerid, int newkeys, int oldkeys) {    
  269.         if((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
  270.             if(IsValidObject(PSD.CarFireObject[playerid]) == 0) {
  271.                 PSD.CarFireObject[playerid] = CreateObject(18694, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 500.0f);
  272.                 AttachObjectToVehicle(PSD.CarFireObject[playerid], GetPlayerVehicleID(playerid), 0.0f, -2.3f, 1.2f, 180.0f, 0.0f, 0.0f);
  273.             }
  274.             AddVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  275.             !IsPlayerInAnyVehicle(playerid)? RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010), DestroyObject(PSD.CarFireObject[playerid]): false;
  276.             return true;
  277.         }
  278.        
  279.         else if((oldkeys & KEY_FIRE) && !(newkeys & KEY_FIRE) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
  280.             DestroyObject(PSD.CarFireObject[playerid]);
  281.             RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  282.             return true;
  283.         }
  284.    
  285.         BindKey("submission") {
  286.             IsPlayerInAnyVehicle(playerid)?
  287.                     RepairVehicle(GetPlayerVehicleID(playerid)),
  288.                     GameTextForPlayer(playerid,"~y~Pojazd naprawiony!", 2000, 5),
  289.                     PlayerPlaySound(playerid, 1133, 0.0f, 0.0f, 0.0f):
  290.             false;
  291.         }
  292.         return true;
  293.     }
  294.  
  295.     PUBLIC OnPlayerRequestClass(int playerid, int classid) {
  296.         switch(GetPVarInt(playerid, "Dance")) {
  297.             case 0: ApplyAnimation(playerid, "DANCING", "dnce_M_a", 4.1f, 1, 1, 1, 1, 1, 1); break;
  298.             case 1: ApplyAnimation(playerid, "DANCING", "dnce_M_b", 4.1f, 1, 1, 1, 1, 1, 1); break;
  299.             case 2: ApplyAnimation(playerid, "DANCING", "dnce_M_c", 4.1f, 1, 1, 1, 1, 1, 1); break;
  300.             case 3: ApplyAnimation(playerid, "DANCING", "dnce_M_d", 4.1f, 1, 1, 1, 1, 1, 1); break;
  301.             case 4: ApplyAnimation(playerid, "DANCING", "dnce_M_e", 4.1f, 1, 1, 1, 1, 1, 1); break;
  302.         }
  303.         SetPVarInt(playerid, "Dance", GetPVarInt(playerid, "Dance") < 4? GetPVarInt(playerid, "Dance") + 1: 0);
  304.         return true;
  305.     }
  306.  
  307.     PUBLIC OnPlayerDisconnect(int playerid, int reason) {
  308.         !IsPlayerConnected(playerid)? DeletePlayer3DTextLabel(playerid, PSD.Speed3DText[playerid]), KillTimer(PSD.VelocityTimer[playerid]): false;
  309.         IsValidObject(PSD.CarFireObject[playerid])? DestroyObject(PSD.CarFireObject[playerid]): false;
  310.         return true;
  311.     }
  312.  
  313.     PUBLIC OnGameModeExit() {
  314.         return true;
  315.     }
  316.  
  317. // Exports:
  318.     EXPORTING(PSD_PLUGIN);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement