Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Infinity-Gaming
- © 2013 by Shiny
- Licence: BSD
- */
- // Includes:
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <string>
- /* SA:MP GDK Includes: */
- #include <sampgdk/a_players.hpp>
- #include <sampgdk/a_samp.hpp>
- #include <sampgdk/a_objects.hpp>
- #include <sampgdk/a_vehicles.hpp>
- #include <sampgdk/core.hpp>
- #include <sampgdk/plugin.h>
- /* Namespace: */
- using namespace std;
- // Macros:
- #define function \
- PLUGIN_EXPORT
- #define foreach_P(integer,value) \
- for(integer; integer != value; integer++) if(IsPlayerConnected(integer))
- #define foreach(integer,value) \
- for(integer; integer != value; integer++)
- #define PUBLIC \
- PLUGIN_EXPORT bool PLUGIN_CALL
- #define strcmp_n(string_1,string_2) \
- strcmp(string_1, string_2) == 0
- #define BindKey(key) \
- if(newkeys & BindKey_(key))
- #define KEY_PRESSED(KEY) \
- (((newkeys & (KEY)) == (KEY)) && ((oldkeys & (KEY)) != (KEY)))
- #define KEY_RELEASED(KEY) \
- (((newkeys & (KEY)) != (KEY)) && ((oldkeys & (KEY)) == (KEY)))
- // Floats:
- float posX;
- float posY;
- float posZ;
- float SavedPos[MAX_PLAYERS];
- // Variables:
- char Vehicle[MAX_PLAYERS] = {-1};
- char Speed3DText[MAX_PLAYERS];
- char Drift3DText[MAX_PLAYERS];
- char CarFireObject[MAX_PLAYERS];
- char PointsFromDrift[MAX_PLAYERS];
- char Timer_CountDrift[MAX_PLAYERS];
- char Timer_Clear3DTexts[MAX_PLAYERS];
- char Timer_PlayerDriftPoints[MAX_PLAYERS];
- static ThisPlugin IG;
- // Constanses:
- const float MinAngle_Drift = 10.0;
- const float MaxAngle_Drift = 90.0;
- const float MaxSpeed_Drift = 30.0;
- const int EOS = '\0';
- // Tables:
- char VehNames[212][32] = {
- "/Landstalker", "/Bravura", "/Buffalo", "/Linerunner", "/Pereniel", "/Sentinel", "/Dumper", "/Firetruck", "/Trashmaster", "/Stretch",
- "/Manana", "/Infernus", "/Voodoo", "/Pony", "/Mule", "/Cheetah", "/Ambulance", "/Leviathan", "/Moonbeam", "/Esperanto",
- "/Taxi", "/Washington", "/Bobcat", "/Mr Whoopee", "/BF Injection", "/Hunter", "/Premier", "/Enforcer", "/Securicar", "/Banshee",
- "/Predator", "/Bus", "/Rhino", "/Barracks", "/Hotknife", "/Trailer", "/Previon", "/Coach", "/Cabbie", "/Stallion",
- "/Rumpo", "/RC Bandit", "/Romero", "/Packer", "/Monster", "/Admiral", "/Squalo", "/Seasparrow", "/Pizzaboy", "/Tram",
- "/Trailer", "/Turismo", "/Speeder", "/Reefer", "/Tropic", "/Flatbed", "/Yankee", "/Caddy", "/Solair", "/Berkley's RC Van",
- "/Skimmer", "/PCJ-600", "/Faggio", "/Freeway", "/RC Baron", "/RC Raider", "/Glendale", "/Oceanic", "/Sanchez", "/Sparrow",
- "/Patriot", "/Quad", "/Coastguard", "/Dinghy", "/Hermes", "/Sabre", "/Rustler", "/ZR 350", "/Walton", "/Regina",
- "/Comet", "/BMX", "/Burrito", "/Camper", "/Marquis", "/Baggage", "/Dozer", "/Maverick", "/News Chopper", "/Rancher",
- "/FBI Rancher", "/Virgo", "/Greenwood", "/Jetmax", "/Hotring", "/Sandking", "/Blista Compact", "/Police Maverick", "/Boxville", "/Benson",
- "/Mesa", "/RC Goblin", "/Hotring Racer", "/Hotring Racer", "/Bloodring Banger", "/Rancher", "/Super GT", "/Elegant", "/Journey", "/Bike",
- "/Mountain Bike", "/Beagle", "/Cropdust", "/Stunt", "/Tanker", "/RoadTrain", "/Nebula", "/Majestic", "/Buccaneer", "/Shamal",
- "/Hydra", "/FCR", "/NRG", "/HPV1000", "/Cement Truck", "/Tow Truck", "/Fortune", "/Cadrona", "/FBI Truck", "/Willard",
- "/Forklift", "/Tractor", "/Combine", "/Feltzer", "/Remington", "/Slamvan", "/Blade", "/Freight", "/Streak", "/Vortex",
- "/Vincent", "/Bullet", "/Clover", "/Sadler", "/Firetruck", "/Hustler", "/Intruder", "/Primo", "/Cargobob", "/Tampa",
- "/Sunrise", "/Merit", "/Utility", "/Nevada", "/Yosemite", "/Windsor", "/Monstera", "/Monsterb", "/Uranus", "/Jester",
- "/Sultan", "/Stratum", "/Elegy", "/Raindance", "/RC Tiger", "/Flash", "/Tahoma", "/Savanna", "/Bandito", "/Freight",
- "/Trailer", "/Kart", "/Mower", "/Duneride", "/Sweeper", "/Broadway", "/Tornado", "/AT-400", "/DFT-30", "/Huntley",
- "/Stafford", "/BF-400", "/Newsvan", "/Tug", "/Trailer2", "/Emperor", "/Wayfarer", "/Euros", "/Hotdog", "/Club",
- "/Trailer3", "/Trailer4", "/Andromeda", "/Dodo", "/RC Cam", "/Launch", "/Police Car (LSPD)", "/Police Car (SFPD)", "/Police Car (LVPD)", "/Police Ranger",
- "/Picador", "/S.W.A.T. Van", "/Alpha", "/Phoenix", "/Glendale", "/Sadler", "/Luggage Trailer", "/Luggage Trailer2", "/Stair Trailer", "/Boxville",
- "/Farm Plow", "/Utility Trailer"
- };
- // Functions:
- float GetSpeed(int playerid) {
- float xyz[3];
- (IsPlayerInAnyVehicle(playerid)? GetVehicleVelocity(GetPlayerVehicleID(playerid), &xyz[0], &xyz[1], &xyz[2]): GetPlayerVelocity(playerid, &xyz[0], &xyz[1], &xyz[2]));
- return (235 * sqrtf(powf(xyz[2], 2) + powf(xyz[1], 2) + powf(xyz[0], 2)));
- }
- static int GivePlayerScore(int playerid, int score) {
- return SetPlayerScore(playerid, GetPlayerScore(playerid) + score);
- }
- // Overloading SetTimer with a new-style-function:
- 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;
- }
- static int CreatePlayerVehicle(int playerid, int modelid) {
- int vehicle;
- float X;
- float Y;
- float Z;
- float angle;
- char Name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, Name, sizeof(Name));
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
- vehicle = GetPlayerVehicleID(playerid);
- GetVehiclePos(vehicle, &X, &Y, &Z);
- GetVehicleZAngle(vehicle, &angle);
- DestroyVehicle(vehicle);
- } else {
- GetPlayerPos(playerid, &X, &Y, &Z);
- GetPlayerFacingAngle(playerid, &angle);
- }
- vehicle = AddStaticVehicle(modelid, X, Y, Z + 1, angle, -1, -1);
- LinkVehicleToInterior(vehicle, GetPlayerInterior(playerid));
- SetVehicleVirtualWorld(vehicle, GetPlayerVirtualWorld(playerid));
- SetVehicleNumberPlate(vehicle, Name);
- PutPlayerInVehicle(playerid, vehicle, 0);
- printf("%s tworzy pojazd %s", Name, VehNames[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400][1]);
- return true;
- }
- int GetVehicleModelIDFromName(string vname) {
- int i = 0;
- foreach(i, 211) {
- if(vname.find(VehNames[i]) != string::npos) {
- return i + 400;
- }
- }
- return -1;
- }
- // Timers:
- function bool SAMPGDK_CALL Clear3DTexts(int, void *) {
- int playerid;
- foreach(playerid, MAX_PLAYERS + 1) {
- UpdatePlayer3DTextLabelText(playerid, Drift3DText[playerid], -1, " ");
- IsValidObject(CarFireObject[playerid])? DestroyObject(CarFireObject[playerid]): false;
- RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
- }
- return true;
- }
- function void SAMPGDK_CALL LoadDrift(int, void *) {
- int playerid;
- foreach(playerid, MAX_PLAYERS + 1) {
- Timer_PlayerDriftPoints[playerid] = 0;
- GivePlayerMoney(playerid, PointsFromDrift[playerid] / 2);
- GivePlayerScore(playerid, PointsFromDrift[playerid]);
- PointsFromDrift[playerid] = 0;
- Timer_Clear3DTexts[playerid];// = SetTimer(Clear3DTexts, 100, false);
- }
- }
- // function SAMPGDK_CALL RefreshSpeed(int, void *) {
- PUBLIC OnPlayerUpdate(int playerid) {
- char str[128];
- (IsPlayerInAnyVehicle(playerid)? sprintf(str, "%0.1f km/h\n", GetSpeed(playerid)), UpdatePlayer3DTextLabelText(playerid, Speed3DText[playerid], -1, str), printf(str): false);
- return true;
- }
- PUBLIC OnPlayerSpawn(int playerid) {
- SetPlayerPos(playerid, 10.0, 10.0, 10.0);
- return true;
- }
- PUBLIC OnGameModeInit() {
- SetGameModeText("Infinity-Gaming");
- int i = 0;
- foreach(i, 300) {
- AddPlayerClass(i, -10.0f, -10.0f, -10.0f, -10.0f, 0, 0, 0, 0, 0, 0);
- }
- sampgdk_logprintf("-------------------------\nInfinity-Gaming Loaded!\n-------------------------");
- /* SetTimer(RepeatingTimer, 1000, true); */
- // SetTimer(RefreshSpeed, 150, true);
- return true;
- }
- PUBLIC OnPlayerConnect(int playerid) {
- SendClientMessage(playerid, -1, "YO, NYGA.");
- return true;
- }
- PUBLIC OnPlayerRequestClass(int playerid, int classid) {
- SetPlayerPos(playerid, -10.0f, -10.0f, -10.0f);
- SetPlayerCameraPos(playerid, -15.0f, -15.0f, -15.0f);
- SetPlayerCameraLookAt(playerid, -15.0f, -15.0f, -15.0f, CAMERA_CUT);
- return true;
- }
- PUBLIC OnPlayerCommandText(int playerid, const char * cmdtext) {
- char str[128];
- if(strcmp_n(cmdtext, "/yo")) {
- char Name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, Name, sizeof(Name));
- char MSG[128];
- sprintf(MSG, "Yo, %s", Name);
- SendClientMessage(playerid, -1, MSG);
- return true;
- }
- else if(strcmp_n(cmdtext, "/infernus")) {
- float Pos[4];
- GetPlayerPos(playerid, &Pos[0], &Pos[1], &Pos[2]);
- GetVehicleZAngle(GetPlayerVehicleID(playerid), &Pos[3]);
- CreateVehicle(411, Pos[0], Pos[1], Pos[2], Pos[3], -1, -1, 1500);
- SendClientMessage(playerid, -1, "Tworzysz Infernusa.");
- return true;
- }
- else if(strcmp_n(cmdtext, (char *)VehNames)) {
- CreatePlayerVehicle(playerid, GetVehicleModelIDFromName(cmdtext));
- return false;
- }
- else return sprintf(str, "Komenda %s nie istnieje.", cmdtext), SendClientMessage(playerid, -1, str);
- }
- 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;
- /*if(newstate == PLAYER_STATE_DRIVER) {
- Speed3DText[playerid] = CreatePlayer3DTextLabel(playerid, "Infernus\n666 KM/H", -1, 0, 0, 0, 15.0, INVALID_PLAYER_ID, GetPlayerVehicleID(playerid), 1);
- }
- else if(oldstate == PLAYER_STATE_DRIVER) {
- DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]);
- }*/
- return true;
- }
- PUBLIC OnPlayerKeyStateChange(int playerid, int newkeys, int oldkeys) {
- if(PointsFromDrift[playerid] > 0) {
- 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);
- }
- /*if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && KEY_PRESSED(KEY_SUBMISSION)) {
- RepairVehicle(GetPlayerVehicleID(playerid));
- GameTextForPlayer(playerid,"~y~Pojazd naprawiony!", 2000, 5);
- PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
- return false;
- }*/
- return true;
- }
- PUBLIC OnPlayerDisconnect(int playerid, int reason) {
- !IsPlayerConnected(playerid)? DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]): false;
- // if(!IsPlayerConnected(playerid)) return DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]);
- return true;
- }
- PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {
- return SUPPORTS_VERSION | SUPPORTS_PROCESS_TICK;
- }
- PLUGIN_EXPORT bool PLUGIN_CALL Load(void ** ppData) {
- return IG.Load(ppData) >= 0;
- }
- PLUGIN_EXPORT void PLUGIN_CALL Unload() {
- IG.Unload();
- }
- PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {
- IG.ProcessTimers();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement