Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Includes:
- #include <conio.h>
- #include <cstdlib>
- #include <ctime>
- #include <iostream>
- #include <string>
- /* SA-MP GDK: */
- #include <sampgdk/a_objects.hpp>
- #include <sampgdk/a_players.hpp>
- #include <sampgdk/a_samp.hpp>
- #include <sampgdk/a_vehicles.hpp>
- #include <sampgdk/core.hpp>
- #include <sampgdk/plugin.h>
- /* Namespace: */
- using namespace std;
- /* Pragmas: */
- #pragma comment(lib, "sampgdk3.lib")
- // Macros:
- #ifndef foreach
- #define foreach(integer, value) \
- for(int integer = NULL; integer != value; integer++)
- #endif
- #ifndef PUBLIC
- #define PUBLIC \
- PLUGIN_EXPORT bool PLUGIN_CALL
- #endif
- #ifndef Bindkey
- #define BindKey(key) \
- if(newkeys & PSD.BindKey_(key))
- #endif
- #ifndef EXPORTING
- #define EXPORTING(Plugin_Name) \
- PLUGIN_EXPORT bool PLUGIN_CALL Load(void ** ppData) {return Plugin_Name.Load(ppData) >= NULL;} \
- PLUGIN_EXPORT void PLUGIN_CALL Unload() {Plugin_Name.Unload();} \
- PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {return SUPPORTS_VERSION | SUPPORTS_PROCESS_TICK;} \
- PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {Plugin_Name.ProcessTimers();}
- #endif
- #ifndef TIMER
- #define TIMER \
- static void SAMPGDK_CALL
- #endif
- // Classess:
- class c_PSD {
- public:
- // Variables:
- /* Integers: */
- int VelocityTimer[MAX_PLAYERS];
- /* Chars: */
- char str[MAX_PLAYERS][170];
- char Speed3DText[MAX_PLAYERS];
- char CarFireObject[MAX_PLAYERS];
- char Name[MAX_PLAYERS][MAX_PLAYER_NAME];
- /* Floats: */
- float Pos[MAX_PLAYERS][3];
- float Health[MAX_PLAYERS];
- float xyz[MAX_PLAYERS][3];
- float Vel[MAX_PLAYERS][3];
- // Functions:
- ~c_PSD();
- int BindKey_(char * key);
- int IsVehiclePlaneOrHelicopter(int vehicleid);
- float GetSpeed(int playerid);
- float SetSpeed(int playerid);
- inline bool PlayAudioStreamForPlayer(int playerid, const char * url);
- inline bool ApplyAnimation(int playerid, const char * animlib, const char * animname, float fDelta, bool loop, bool lockx, bool locky, bool freeze, int time);
- };
- c_PSD PSD;
- c_PSD::~c_PSD() {
- strcpy(* str, "");
- strcpy(Speed3DText, "");
- strcpy(CarFireObject, "");
- strcpy(* Name, "");
- * Health = 0.0;
- strcpy((char *)xyz, "");
- }
- int c_PSD::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;
- }
- int c_PSD::IsVehiclePlaneOrHelicopter(int vehicleid) {
- switch(vehicleid) {
- 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;
- }
- return false;
- }
- float c_PSD::GetSpeed(int playerid) {
- 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]);
- return 160 * sqrtf(powf(xyz[2][playerid], 2) + powf(xyz[1][playerid], 2) + powf(xyz[0][playerid], 2));
- }
- float c_PSD::SetSpeed(int playerid) {
- 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]);
- // return 160 * sqrtf(powf(xyz[2][playerid], 2) + powf(xyz[1][playerid], 2) + powf(xyz[0][playerid], 2));
- }
- inline bool c_PSD::PlayAudioStreamForPlayer(int playerid, const char * url) {
- float posX = 0.0;
- float posY = 0.0;
- float posZ = 0.0;
- float distance = 0.0;
- bool usepos = false;
- return ::sampgdk_PlayAudioStreamForPlayer(playerid, url, posX, posY, posZ, distance, usepos);
- }
- 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) {
- bool forcesync = false;
- return ::sampgdk_ApplyAnimation(playerid, animlib, animname, fDelta, loop, lockx, locky, freeze, time, forcesync);
- }
- // Variables:
- static ThisPlugin PSD_PLUGIN;
- char gVehicleNames[212][32] = {
- "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "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 1", "Previon",
- "Coach", "Cabbie", "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster",
- "Admiral", "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer 2", "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 A", "Hotring Racer B", "Bloodring Banger", "Rancher",
- "Super GT", "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropdust", "Stunt",
- "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra", "FCR-900",
- "NRG-500", "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 LA", "Hustler", "Intruder", "Primo", "Cargobob", "Tampa", "Sunrise", "Merit",
- "Utility", "Nevada", "Yosemite", "Windsor", "Monster A", "Monster B", "Uranus", "Jester",
- "Sultan", "Stratum", "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna",
- "Bandito", "Freight Flat", "Streak Carriage", "Kart", "Mower", "Duneride", "Sweeper",
- "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400", "Newsvan",
- "Tug", "Trailer 3", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club", "Freight Carriage",
- "Trailer 3", "Andromada", "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 A", "Luggage Trailer B", "Stair Trailer", "Boxville", "Farm Plow",
- "Utility Trailer"
- };
- inline int SetTimer(TimerCallback callback, int interval, bool repeat, void * param = NULL) {
- return SetTimer(interval, repeat, callback, param);
- }
- inline int SetTimerEx(TimerCallback callback, int interval, bool repeat, void * param = NULL) {
- return SetTimer(interval, repeat, callback, (void *) param);
- }
- void SAMPGDK_CALL SetVelocity(int timerid, void * param) {
- if(GetVehicleModel(GetPlayerVehicleID((int) param)) == 520) {
- GetVehicleVelocity(GetPlayerVehicleID((int) param), &PSD.Vel[(int) param][0], &PSD.Vel[(int) param][1], &PSD.Vel[(int) param][2]);
- SetVehicleVelocity(GetPlayerVehicleID((int) param), PSD.Vel[(int) param][0] + (float) 0.01, PSD.Vel[(int) param][1], PSD.Vel[(int) param][2]);
- }
- else if(PSD.Vel[(int) param][0] > 2.0) {// Około 480 KMH {
- SetVehicleVelocity(GetPlayerVehicleID((int) param), PSD.Vel[(int) param][0], PSD.Vel[(int) param][1], PSD.Vel[(int) param][2]);
- }
- }
- // Public functions:
- PUBLIC OnGameModeInit() {
- UsePlayerPedAnims();
- for(int i = 0; i <= 299; i++) {
- AddPlayerClass(i, -1399.0179f, 2640.7385f, 55.6875f, 0.0, 0, 0, 0, 0, 0, 0);
- }
- return true;
- }
- PUBLIC OnPlayerUpdate(int playerid) {
- GetPlayerName(playerid, PSD.Name[playerid], sizeof(PSD.Name[playerid]));
- GetVehicleHealth(GetPlayerVehicleID(playerid), &PSD.Health[playerid]);
- GetVehiclePos(GetPlayerVehicleID(playerid), &PSD.Pos[playerid][0], &PSD.Pos[playerid][1], &PSD.Pos[playerid][2]);
- //GetVehicleZAngle(GetPlayerVehicleID(playerid), &PSD.Angle[playerid]);
- if(IsPlayerInAnyVehicle(playerid)) {
- if(PSD.IsVehiclePlaneOrHelicopter(GetVehicleModel(GetPlayerVehicleID(playerid)))) {
- 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]);
- UpdatePlayer3DTextLabelText(playerid, PSD.Speed3DText[playerid], -1, PSD.str[playerid]);
- } else {
- 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]);
- UpdatePlayer3DTextLabelText(playerid, PSD.Speed3DText[playerid], -1, PSD.str[playerid]);
- }
- }
- return true;
- }
- PUBLIC OnPlayerCommandText(int playerid, const char * cmdtext) {
- if(!strcmp(cmdtext, "/life")) {
- SetPlayerHealth(playerid, 100.0);
- SetPlayerArmour(playerid, 100.0);
- SendClientMessage(playerid, -1, "Dostajesz 100 punktów życia i pancerza.");
- return true;
- }
- else if(!strcmp(cmdtext, "/kill")) {
- SetPlayerHealth(playerid, -100.0);
- return true;
- }
- else if(!strcmp(cmdtext, "/invisible")) {
- if(GetPlayerColor(playerid) == 0xFFFFFF00) {
- return SendClientMessage(playerid, -1, "Masz już włączoną niewidzialność.");
- }
- SetPlayerColor(playerid, 0xFFFFFF00);
- SendClientMessage(playerid, -1, "Włączasz niewidzialność.");
- return true;
- }
- else if(!strcmp(cmdtext, "/visible")) {
- SetPlayerColor(playerid, 0xFF000000);
- SendClientMessage(playerid, -1, "Wyłączasz niewidzialność.");
- return true;
- }
- else if(!strcmp(cmdtext, "/turbo")) {
- PSD.VelocityTimer[playerid] = SetTimerEx(SetVelocity, 20, true, (void *) playerid);
- SendClientMessage(playerid, -1, "Włączasz turbo w Hydrze.");
- return true;
- }
- else if(!strcmp(cmdtext, "/turbo-off")) {
- KillTimer(PSD.VelocityTimer[playerid]);
- SendClientMessage(playerid, -1, "Wyłączasz dopalacz w Hydrze.");
- return true;
- }
- return false;
- }
- PUBLIC OnPlayerStateChange(int playerid, int newstate, int oldstate) {
- 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;
- oldstate == PLAYER_STATE_DRIVER? DeletePlayer3DTextLabel(playerid, PSD.Speed3DText[playerid]): false;
- return true;
- }
- PUBLIC OnPlayerKeyStateChange(int playerid, int newkeys, int oldkeys) {
- if((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
- if(IsValidObject(PSD.CarFireObject[playerid]) == 0) {
- PSD.CarFireObject[playerid] = CreateObject(18694, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 500.0f);
- AttachObjectToVehicle(PSD.CarFireObject[playerid], GetPlayerVehicleID(playerid), 0.0f, -2.3f, 1.2f, 180.0f, 0.0f, 0.0f);
- }
- AddVehicleComponent(GetPlayerVehicleID(playerid), 1010);
- !IsPlayerInAnyVehicle(playerid)? RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010), DestroyObject(PSD.CarFireObject[playerid]): false;
- return true;
- }
- else if((oldkeys & KEY_FIRE) && !(newkeys & KEY_FIRE) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
- DestroyObject(PSD.CarFireObject[playerid]);
- RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
- return true;
- }
- BindKey("submission") {
- IsPlayerInAnyVehicle(playerid)?
- RepairVehicle(GetPlayerVehicleID(playerid)),
- GameTextForPlayer(playerid,"~y~Pojazd naprawiony!", 2000, 5),
- PlayerPlaySound(playerid, 1133, 0.0f, 0.0f, 0.0f):
- false;
- }
- return true;
- }
- PUBLIC OnPlayerRequestClass(int playerid, int classid) {
- switch(GetPVarInt(playerid, "Dance")) {
- case 0: ApplyAnimation(playerid, "DANCING", "dnce_M_a", 4.1f, 1, 1, 1, 1, 1, 1); break;
- case 1: ApplyAnimation(playerid, "DANCING", "dnce_M_b", 4.1f, 1, 1, 1, 1, 1, 1); break;
- case 2: ApplyAnimation(playerid, "DANCING", "dnce_M_c", 4.1f, 1, 1, 1, 1, 1, 1); break;
- case 3: ApplyAnimation(playerid, "DANCING", "dnce_M_d", 4.1f, 1, 1, 1, 1, 1, 1); break;
- case 4: ApplyAnimation(playerid, "DANCING", "dnce_M_e", 4.1f, 1, 1, 1, 1, 1, 1); break;
- }
- SetPVarInt(playerid, "Dance", GetPVarInt(playerid, "Dance") < 4? GetPVarInt(playerid, "Dance") + 1: 0);
- return true;
- }
- PUBLIC OnPlayerDisconnect(int playerid, int reason) {
- !IsPlayerConnected(playerid)? DeletePlayer3DTextLabel(playerid, PSD.Speed3DText[playerid]), KillTimer(PSD.VelocityTimer[playerid]): false;
- IsValidObject(PSD.CarFireObject[playerid])? DestroyObject(PSD.CarFireObject[playerid]): false;
- return true;
- }
- PUBLIC OnGameModeExit() {
- return true;
- }
- // Exports:
- EXPORTING(PSD_PLUGIN);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement