Advertisement
Shiny_

coś

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