Advertisement
Shiny_

IG

Sep 7th, 2013
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.40 KB | None | 0 0
  1. /* Infinity-Gaming
  2.     © 2013 by Shiny
  3.     Licence: BSD
  4. */
  5.  
  6. // Includes:
  7.     #include <cstdio>
  8.     #include <cstring>
  9.     #include <cmath>
  10.     #include <string>
  11.  
  12.     /* SA:MP GDK Includes: */
  13.     #include <sampgdk/a_players.hpp>
  14.     #include <sampgdk/a_samp.hpp>
  15.     #include <sampgdk/a_objects.hpp>
  16.     #include <sampgdk/a_vehicles.hpp>
  17.     #include <sampgdk/core.hpp>
  18.     #include <sampgdk/plugin.h>
  19.  
  20.     /* Namespace: */
  21.     using namespace std;
  22.  
  23. // Macros:
  24.     #define function                        \
  25.             PLUGIN_EXPORT
  26.     #define foreach_P(integer,value)        \
  27.             for(integer; integer != value; integer++) if(IsPlayerConnected(integer))
  28.     #define foreach(integer,value)          \
  29.             for(integer; integer != value; integer++)
  30.     #define PUBLIC                          \
  31.             PLUGIN_EXPORT bool PLUGIN_CALL
  32.     #define strcmp_n(string_1,string_2)     \
  33.             strcmp(string_1, string_2) == 0
  34.     #define BindKey(key)                    \
  35.             if(newkeys & BindKey_(key))
  36.     #define KEY_PRESSED(KEY)                \
  37.             (((newkeys & (KEY)) == (KEY)) && ((oldkeys & (KEY)) != (KEY)))
  38.     #define KEY_RELEASED(KEY)               \
  39.             (((newkeys & (KEY)) != (KEY)) && ((oldkeys & (KEY)) == (KEY)))
  40.  
  41. // Floats:
  42.     float posX;
  43.     float posY;
  44.     float posZ;
  45.     float SavedPos[MAX_PLAYERS];
  46.  
  47. // Variables:
  48.     char Vehicle[MAX_PLAYERS] = {-1};
  49.     char Speed3DText[MAX_PLAYERS];
  50.     char Drift3DText[MAX_PLAYERS];
  51.     char CarFireObject[MAX_PLAYERS];
  52.     char PointsFromDrift[MAX_PLAYERS];
  53.     char Timer_CountDrift[MAX_PLAYERS];
  54.     char Timer_Clear3DTexts[MAX_PLAYERS];
  55.     char Timer_PlayerDriftPoints[MAX_PLAYERS];
  56.     static ThisPlugin IG;
  57.  
  58. // Constanses:
  59.     const float MinAngle_Drift = 10.0;
  60.     const float MaxAngle_Drift = 90.0;
  61.     const float MaxSpeed_Drift = 30.0;
  62.     const int EOS = '\0';
  63.  
  64. // Tables:
  65.     char VehNames[212][32] = {
  66.         "/Landstalker", "/Bravura", "/Buffalo", "/Linerunner", "/Pereniel", "/Sentinel", "/Dumper", "/Firetruck", "/Trashmaster", "/Stretch",
  67.         "/Manana", "/Infernus", "/Voodoo", "/Pony", "/Mule", "/Cheetah", "/Ambulance", "/Leviathan", "/Moonbeam", "/Esperanto",
  68.         "/Taxi", "/Washington", "/Bobcat", "/Mr Whoopee", "/BF Injection", "/Hunter", "/Premier", "/Enforcer", "/Securicar", "/Banshee",
  69.         "/Predator", "/Bus", "/Rhino", "/Barracks", "/Hotknife", "/Trailer", "/Previon", "/Coach", "/Cabbie", "/Stallion",
  70.         "/Rumpo", "/RC Bandit", "/Romero", "/Packer", "/Monster", "/Admiral", "/Squalo", "/Seasparrow", "/Pizzaboy", "/Tram",
  71.         "/Trailer", "/Turismo", "/Speeder", "/Reefer", "/Tropic", "/Flatbed", "/Yankee", "/Caddy", "/Solair", "/Berkley's RC Van",
  72.         "/Skimmer", "/PCJ-600", "/Faggio", "/Freeway", "/RC Baron", "/RC Raider", "/Glendale", "/Oceanic", "/Sanchez", "/Sparrow",
  73.         "/Patriot", "/Quad", "/Coastguard", "/Dinghy", "/Hermes", "/Sabre", "/Rustler", "/ZR 350", "/Walton", "/Regina",
  74.         "/Comet", "/BMX", "/Burrito", "/Camper", "/Marquis", "/Baggage", "/Dozer", "/Maverick", "/News Chopper", "/Rancher",
  75.         "/FBI Rancher", "/Virgo", "/Greenwood", "/Jetmax", "/Hotring", "/Sandking", "/Blista Compact", "/Police Maverick", "/Boxville", "/Benson",
  76.         "/Mesa", "/RC Goblin", "/Hotring Racer", "/Hotring Racer", "/Bloodring Banger", "/Rancher", "/Super GT", "/Elegant", "/Journey", "/Bike",
  77.         "/Mountain Bike", "/Beagle", "/Cropdust", "/Stunt", "/Tanker", "/RoadTrain", "/Nebula", "/Majestic", "/Buccaneer", "/Shamal",
  78.         "/Hydra", "/FCR", "/NRG", "/HPV1000", "/Cement Truck", "/Tow Truck", "/Fortune", "/Cadrona", "/FBI Truck", "/Willard",
  79.         "/Forklift", "/Tractor", "/Combine", "/Feltzer", "/Remington", "/Slamvan", "/Blade", "/Freight", "/Streak", "/Vortex",
  80.         "/Vincent", "/Bullet", "/Clover", "/Sadler", "/Firetruck", "/Hustler", "/Intruder", "/Primo", "/Cargobob", "/Tampa",
  81.         "/Sunrise", "/Merit", "/Utility", "/Nevada", "/Yosemite", "/Windsor", "/Monstera", "/Monsterb", "/Uranus", "/Jester",
  82.         "/Sultan", "/Stratum", "/Elegy", "/Raindance", "/RC Tiger", "/Flash", "/Tahoma", "/Savanna", "/Bandito", "/Freight",
  83.         "/Trailer", "/Kart", "/Mower", "/Duneride", "/Sweeper", "/Broadway", "/Tornado", "/AT-400", "/DFT-30", "/Huntley",
  84.         "/Stafford", "/BF-400", "/Newsvan", "/Tug", "/Trailer2", "/Emperor", "/Wayfarer", "/Euros", "/Hotdog", "/Club",
  85.         "/Trailer3", "/Trailer4", "/Andromeda", "/Dodo", "/RC Cam", "/Launch", "/Police Car (LSPD)", "/Police Car (SFPD)", "/Police Car (LVPD)", "/Police Ranger",
  86.         "/Picador", "/S.W.A.T. Van", "/Alpha", "/Phoenix", "/Glendale", "/Sadler", "/Luggage Trailer", "/Luggage Trailer2", "/Stair Trailer", "/Boxville",
  87.         "/Farm Plow", "/Utility Trailer"
  88.     };
  89.  
  90. // Functions:  
  91.     float GetSpeed(int playerid) {
  92.         float xyz[3];
  93.         (IsPlayerInAnyVehicle(playerid)? GetVehicleVelocity(GetPlayerVehicleID(playerid), &xyz[0], &xyz[1], &xyz[2]): GetPlayerVelocity(playerid, &xyz[0], &xyz[1], &xyz[2]));
  94.         return (235 * sqrtf(powf(xyz[2], 2) + powf(xyz[1], 2) + powf(xyz[0], 2)));
  95.     }
  96.    
  97.     static int GivePlayerScore(int playerid, int score) {
  98.         return SetPlayerScore(playerid, GetPlayerScore(playerid) + score);
  99.     }
  100.  
  101.     // Overloading SetTimer with a new-style-function:
  102.     static int SetTimer(TimerCallback callback, int interval, bool repeat, void * param = 0) {
  103.         return SetTimer(interval, repeat, callback, param);
  104.     }
  105.  
  106.     int BindKey_(char * key) {
  107.         if(!strcmp("action", key)) return KEY_ACTION;
  108.         else if(!strcmp("crouch", key)) return KEY_CROUCH;
  109.         else if(!strcmp("fire", key)) return KEY_FIRE;
  110.         else if(!strcmp("sprint", key)) return KEY_SPRINT;
  111.         else if(!strcmp("attack", key)) return KEY_SECONDARY_ATTACK;
  112.         else if(!strcmp("jump", key)) return KEY_JUMP;
  113.         else if(!strcmp("lookr", key)) return KEY_LOOK_RIGHT;
  114.         else if(!strcmp("lookl", key)) return KEY_LOOK_LEFT;
  115.         else if(!strcmp("lookb", key)) return KEY_LOOK_BEHIND;
  116.         else if(!strcmp("handbrake", key)) return KEY_HANDBRAKE;
  117.         else if(!strcmp("submission", key)) return KEY_SUBMISSION;
  118.         else if(!strcmp("walk", key)) return KEY_WALK;
  119.         else if(!strcmp("aup", key)) return KEY_ANALOG_UP;
  120.         else if(!strcmp("adown", key)) return KEY_ANALOG_DOWN;
  121.         else if(!strcmp("aleft", key)) return KEY_ANALOG_LEFT;
  122.         else if(!strcmp("aright", key)) return KEY_ANALOG_RIGHT;
  123.         else if(!strcmp("yes", key)) return KEY_YES;
  124.         else if(!strcmp("no", key)) return KEY_NO;
  125.         else if(!strcmp("ctrlback", key)) return KEY_NO;
  126.         else if(!strcmp("up", key)) return KEY_UP;
  127.         else if(!strcmp("down", key)) return KEY_DOWN;
  128.         else if(!strcmp("left", key)) return KEY_LEFT;
  129.         else if(!strcmp("right", key)) return KEY_RIGHT;
  130.         else return false;
  131.     }
  132.    
  133.     static int CreatePlayerVehicle(int playerid, int modelid) {
  134.         int vehicle;
  135.         float X;
  136.         float Y;
  137.         float Z;
  138.         float angle;
  139.         char Name[MAX_PLAYER_NAME];
  140.         GetPlayerName(playerid, Name, sizeof(Name));
  141.  
  142.         if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
  143.             vehicle = GetPlayerVehicleID(playerid);
  144.             GetVehiclePos(vehicle, &X, &Y, &Z);
  145.             GetVehicleZAngle(vehicle, &angle);
  146.             DestroyVehicle(vehicle);
  147.         } else {
  148.             GetPlayerPos(playerid, &X, &Y, &Z);
  149.             GetPlayerFacingAngle(playerid, &angle);
  150.         }
  151.         vehicle = AddStaticVehicle(modelid, X, Y, Z + 1, angle, -1, -1);
  152.         LinkVehicleToInterior(vehicle, GetPlayerInterior(playerid));
  153.         SetVehicleVirtualWorld(vehicle, GetPlayerVirtualWorld(playerid));
  154.         SetVehicleNumberPlate(vehicle, Name);
  155.         PutPlayerInVehicle(playerid, vehicle, 0);
  156.         printf("%s tworzy pojazd %s", Name, VehNames[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400][1]);
  157.         return true;
  158.     }
  159.  
  160.     int GetVehicleModelIDFromName(string vname) {
  161.         int i = 0;
  162.         foreach(i, 211) {
  163.             if(vname.find(VehNames[i]) != string::npos) {
  164.                 return i + 400;
  165.             }
  166.         }
  167.         return -1;
  168.     }
  169.  
  170. // Timers:
  171.     function bool SAMPGDK_CALL Clear3DTexts(int, void *) {
  172.         int playerid;
  173.         foreach(playerid, MAX_PLAYERS + 1) {
  174.             UpdatePlayer3DTextLabelText(playerid, Drift3DText[playerid], -1, " ");
  175.             IsValidObject(CarFireObject[playerid])? DestroyObject(CarFireObject[playerid]): false;
  176.             RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  177.         }
  178.         return true;
  179.     }
  180.  
  181.     function void SAMPGDK_CALL LoadDrift(int, void *) {
  182.         int playerid;
  183.         foreach(playerid, MAX_PLAYERS + 1) {
  184.             Timer_PlayerDriftPoints[playerid] = 0;
  185.             GivePlayerMoney(playerid, PointsFromDrift[playerid] / 2);
  186.             GivePlayerScore(playerid, PointsFromDrift[playerid]);
  187.             PointsFromDrift[playerid] = 0;
  188.             Timer_Clear3DTexts[playerid];// = SetTimer(Clear3DTexts, 100, false);
  189.         }
  190.     }
  191.  
  192.     // function SAMPGDK_CALL RefreshSpeed(int, void *) {
  193.     PUBLIC OnPlayerUpdate(int playerid) {
  194.         char str[128];
  195.         (IsPlayerInAnyVehicle(playerid)? sprintf(str, "%0.1f km/h\n", GetSpeed(playerid)), UpdatePlayer3DTextLabelText(playerid, Speed3DText[playerid], -1, str), printf(str): false);
  196.         return true;
  197.     }
  198.  
  199.     PUBLIC OnPlayerSpawn(int playerid) {
  200.         SetPlayerPos(playerid, 10.0, 10.0, 10.0);
  201.         return true;
  202.     }
  203.  
  204.     PUBLIC OnGameModeInit() {
  205.         SetGameModeText("Infinity-Gaming");
  206.  
  207.         int i = 0;
  208.         foreach(i, 300) {
  209.             AddPlayerClass(i, -10.0f, -10.0f, -10.0f, -10.0f, 0, 0, 0, 0, 0, 0);
  210.         }
  211.  
  212.         sampgdk_logprintf("-------------------------\nInfinity-Gaming Loaded!\n-------------------------");
  213.         /* SetTimer(RepeatingTimer, 1000, true); */
  214.         // SetTimer(RefreshSpeed, 150, true);
  215.         return true;
  216.     }
  217.  
  218.     PUBLIC OnPlayerConnect(int playerid) {
  219.         SendClientMessage(playerid, -1, "YO, NYGA.");
  220.         return true;
  221.     }
  222.  
  223.     PUBLIC OnPlayerRequestClass(int playerid, int classid) {
  224.         SetPlayerPos(playerid, -10.0f, -10.0f, -10.0f);
  225.         SetPlayerCameraPos(playerid, -15.0f, -15.0f, -15.0f);
  226.         SetPlayerCameraLookAt(playerid, -15.0f, -15.0f, -15.0f, CAMERA_CUT);
  227.         return true;
  228.     }
  229.  
  230.     PUBLIC OnPlayerCommandText(int playerid, const char * cmdtext) {
  231.         char str[128];
  232.         if(strcmp_n(cmdtext, "/yo")) {
  233.             char Name[MAX_PLAYER_NAME];
  234.             GetPlayerName(playerid, Name, sizeof(Name));
  235.            
  236.             char MSG[128];
  237.             sprintf(MSG, "Yo, %s", Name);
  238.             SendClientMessage(playerid, -1, MSG);
  239.             return true;
  240.         }
  241.         else if(strcmp_n(cmdtext, "/infernus")) {
  242.             float Pos[4];
  243.             GetPlayerPos(playerid, &Pos[0], &Pos[1], &Pos[2]);
  244.             GetVehicleZAngle(GetPlayerVehicleID(playerid), &Pos[3]);
  245.             CreateVehicle(411, Pos[0], Pos[1], Pos[2], Pos[3], -1, -1, 1500);
  246.             SendClientMessage(playerid, -1, "Tworzysz Infernusa.");
  247.             return true;
  248.         }
  249.         else if(strcmp_n(cmdtext, (char *)VehNames)) {
  250.             CreatePlayerVehicle(playerid, GetVehicleModelIDFromName(cmdtext));
  251.             return false;
  252.         }
  253.         else return sprintf(str, "Komenda %s nie istnieje.", cmdtext), SendClientMessage(playerid, -1, str);
  254.     }
  255.    
  256.     PUBLIC OnPlayerStateChange(int playerid, int newstate, int oldstate) {
  257.         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;
  258.         oldstate == PLAYER_STATE_DRIVER? DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]): false;
  259.         /*if(newstate == PLAYER_STATE_DRIVER) {
  260.             Speed3DText[playerid] = CreatePlayer3DTextLabel(playerid, "Infernus\n666 KM/H", -1, 0, 0, 0, 15.0, INVALID_PLAYER_ID, GetPlayerVehicleID(playerid), 1);
  261.         }
  262.         else if(oldstate == PLAYER_STATE_DRIVER) {
  263.             DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]);
  264.         }*/
  265.         return true;
  266.     }
  267.  
  268.     PUBLIC OnPlayerKeyStateChange(int playerid, int newkeys, int oldkeys) {
  269.         if(PointsFromDrift[playerid] > 0) {
  270.             if(IsValidObject(CarFireObject[playerid]) == 0) {
  271.                 CarFireObject[playerid] = CreateObject(18694, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 500.0f);
  272.                 AttachObjectToVehicle(CarFireObject[playerid], GetPlayerVehicleID(playerid), 0.0f, -2.3f, 1.2f, 180.0f, 0.0f, 0.0f);
  273.             }
  274.             AddVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  275.         }
  276.        
  277.          BindKey("submission") {
  278.             RepairVehicle(GetPlayerVehicleID(playerid));
  279.             GameTextForPlayer(playerid,"~y~Pojazd naprawiony!", 2000, 5);
  280.             PlayerPlaySound(playerid, 1133, 0.0f, 0.0f, 0.0f);
  281.         }
  282.         /*if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && KEY_PRESSED(KEY_SUBMISSION)) {
  283.             RepairVehicle(GetPlayerVehicleID(playerid));
  284.             GameTextForPlayer(playerid,"~y~Pojazd naprawiony!", 2000, 5);
  285.             PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
  286.             return false;
  287.         }*/
  288.         return true;
  289.     }
  290.  
  291.     PUBLIC OnPlayerDisconnect(int playerid, int reason) {
  292.         !IsPlayerConnected(playerid)? DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]): false;
  293.         // if(!IsPlayerConnected(playerid)) return DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]);
  294.         return true;
  295.     }
  296.  
  297.     PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {
  298.         return SUPPORTS_VERSION | SUPPORTS_PROCESS_TICK;
  299.     }
  300.  
  301.     PLUGIN_EXPORT bool PLUGIN_CALL Load(void ** ppData) {
  302.         return IG.Load(ppData) >= 0;
  303.     }
  304.  
  305.     PLUGIN_EXPORT void PLUGIN_CALL Unload() {
  306.         IG.Unload();
  307.     }
  308.  
  309.     PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {
  310.         IG.ProcessTimers();
  311.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement