Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Includes:
- #include <cmath>
- #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>
- /* SQLite: */
- // #include "SQLite3/sqlite3.h"
- /* Namespace: */
- using namespace std;
- /* Pragmas: */
- // #pragma comment(lib, "sqlite3.lib")
- #pragma comment(lib, "sampgdk3.lib")
- // Macros:
- #define PUBLIC \
- PLUGIN_EXPORT bool PLUGIN_CALL
- #define BindKey(key) \
- if(newkeys & BindKey_(key))
- #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();}
- /*
- #define DB_NAME \
- "scriptfiles/PSD.db"
- #define TABLE_NAME \
- "PSD"
- */
- // Variables:
- static ThisPlugin PSD;
- /* Char: */
- char str[MAX_PLAYERS][128];
- char Speed3DText[MAX_PLAYERS];
- char CarFireObject[MAX_PLAYERS];
- char gVehicleNames[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", "Harley", "RC Baron", "RC Raider", "Glendale", "Oceanic",
- "Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy", "Hermes", "Sabre", "Rustler", "ZR3 50", "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-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune", "Cadrona", "FBI Truck", "Willard", "Forklift", "Traktor",
- "Combine", "Feltzer", "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent", "Bullet", "Clover", "Sadler",
- "Firetruck", "Hustler", "Intruder", "Primo", "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite", "Windsor",
- "Monster", "Monster", "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", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club", "Trailer", "Trailer",
- "Andromeda", "Dodo", "RC Cam", "Launch", "Radiowoz", "Radiowoz", "Radiowoz", "Radiowoz", "Picador", "S.W.A.T. Van",
- "Alpha", "Phoenix", "Glendale", "Sadler", "Luggage Trailer", "Luggage Trailer", "Stair Trailer", "Boxville", "Farm Plow", "Utility Trailer"
- };
- /* Float: */
- float Health[MAX_PLAYERS];
- float xyz[MAX_PLAYERS][3];
- enum A {
- test,
- };
- // Functions:
- inline 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;
- }
- float sub(float x, float y) {
- return x - y;
- }
- float GetPlayerDistanceToPointIn3D(int playerid, float x, float y, float z) {
- float x1;
- float y1;
- float z1;
- float mpt2dis;
- GetPlayerPos(playerid, &x1, &y1, &z1);
- mpt2dis = sqrtf(powf(abs(sub(x, x1)), 2) + powf(abs(sub(y, y1)), 2) + powf(abs(sub(z, z1)), 2));
- return floorf(mpt2dis + (float) 0.5);
- }
- bool IsPlayerInCircle(int playerid, float x, float y, float z, float radius) {
- if(GetPlayerDistanceToPointIn3D(playerid, x, y, z) < radius) return true;
- return false;
- }
- float 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 /*235 */160 * sqrtf(powf(xyz[2][playerid], 2) + powf(xyz[1][playerid], 2) + powf(xyz[0][playerid], 2));
- }
- // Public functions:
- PUBLIC OnPlayerUpdate(int playerid) {
- GetVehicleHealth(GetPlayerVehicleID(playerid), &Health[playerid]);
- IsPlayerInAnyVehicle(playerid)?
- sprintf
- (
- str[playerid], "[%s]\n%0.1f km/h\n%0.1f/1000.0",
- &gVehicleNames[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400],
- GetSpeed(playerid),
- Health[playerid]
- ), UpdatePlayer3DTextLabelText(playerid, Speed3DText[playerid], -1, str[playerid]): false;
- return true;
- }
- 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;
- return true;
- }
- PUBLIC OnPlayerKeyStateChange(int playerid, int newkeys, int oldkeys) {
- if((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
- 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);
- !IsPlayerInAnyVehicle(playerid)? RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010), DestroyObject(CarFireObject[playerid]): false;
- return true;
- }
- else if((oldkeys & KEY_FIRE) && !(newkeys & KEY_FIRE) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
- DestroyObject(CarFireObject[playerid]);
- RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
- return true;
- }
- BindKey("submission") {
- RepairVehicle(GetPlayerVehicleID(playerid));
- GameTextForPlayer(playerid,"~y~Pojazd naprawiony!", 2000, 5);
- PlayerPlaySound(playerid, 1133, 0.0f, 0.0f, 0.0f);
- }
- return true;
- }
- PUBLIC OnPlayerDisconnect(int playerid, int reason) {
- !IsPlayerConnected(playerid)? DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]): false;
- IsValidObject(CarFireObject[playerid])? DestroyObject(CarFireObject[playerid]): false;
- return true;
- }
- // Exports:
- EXPORTING(PSD);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement