Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Biblioteki:
- #include <a_samp>
- #include <YSF>
- #include <zcmd>
- // Makra i constansy:
- #define Timer(%0) forward %0(); public %0()
- #define TimerEx(%0->%1) forward %0(%1); public %0(%1)
- #define dynamic(%0) forward %0(); public %0()
- #define dynamic_arg(%0->%1) forward %0(%1); public %0(%1)
- #define dli(%1,%2,%3,%4) ((%1 == 1)? (%2): (((%1 % 10 > 1) && (%1 % 10 < 5) && !((%1 % 100 >= 10) && (%1 % 100 <= 21)))? (%3): (%4)))
- #define BindKey(%1) if(newkeys & BindKey_(%1))
- #define DRIFT_MINKAT 10.0
- #define DRIFT_MAXKAT 90.0
- #define DRIFT_SPEED 30.0
- #define COLOR_LIGHTRED 0xFF0000FF
- #define COLOR_LIGHTBLUE 0x33CCFFAA
- // Enumeratory:
- enum Float:Pos {
- Float:sX, Float:sY, Float:sZ
- };
- enum Player {
- Registered,
- LoggedIn,
- };
- // Zmienne:
- new
- bool: UpdateSpeed[MAX_PLAYERS] = {false, ...},
- Float: ppos[MAX_PLAYERS][3],
- Float: SavedPos[MAX_PLAYERS][Pos],
- PlayerText3D: Drift3DText[MAX_PLAYERS],
- PlayerText3D: Speed3DText[MAX_PLAYERS],
- Text: km[MAX_PLAYERS],
- PointsFromDrift[MAX_PLAYERS],
- PlayerDriftPoints[MAX_PLAYERS],
- 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"
- };
- // Funkcje statyczne:
- stock BindKey_(key[]) {
- if(!strcmp("action", key, true)) return KEY_ACTION;
- else if(!strcmp("crouch", key, true)) return KEY_CROUCH;
- else if(!strcmp("fire", key, true)) return KEY_FIRE;
- else if(!strcmp("sprint", key, true)) return KEY_SPRINT;
- else if(!strcmp("attack", key, true)) return KEY_SECONDARY_ATTACK;
- else if(!strcmp("jump", key, true)) return KEY_JUMP;
- else if(!strcmp("lookr", key, true)) return KEY_LOOK_RIGHT;
- else if(!strcmp("lookl", key, true)) return KEY_LOOK_LEFT;
- else if(!strcmp("lookb", key, true)) return KEY_LOOK_BEHIND;
- else if(!strcmp("handbrake", key, true)) return KEY_HANDBRAKE;
- else if(!strcmp("submission", key, true)) return KEY_SUBMISSION;
- else if(!strcmp("walk", key, true)) return KEY_WALK;
- else if(!strcmp("aup", key, true)) return KEY_ANALOG_UP;
- else if(!strcmp("adown", key, true)) return KEY_ANALOG_DOWN;
- else if(!strcmp("aleft", key, true)) return KEY_ANALOG_LEFT;
- else if(!strcmp("aright", key, true)) return KEY_ANALOG_RIGHT;
- else if(!strcmp("yes", key, true)) return KEY_YES;
- else if(!strcmp("no", key, true)) return KEY_NO;
- else if(!strcmp("ctrlback", key, true)) return KEY_NO;
- else if(!strcmp("up", key, true)) return KEY_UP;
- else if(!strcmp("down", key, true)) return KEY_DOWN;
- else if(!strcmp("left", key, true)) return KEY_LEFT;
- else if(!strcmp("right", key, true)) return KEY_RIGHT;
- else return false;
- }
- stock rand(one, two) {
- return random(two - one) + one;
- }
- stock GetPlayerSpeed(v) {
- new Float: X, Float: Y, Float: Z;
- GetVehicleVelocity(v, X, Y, Z);
- return floatround(floatsqroot(floatpower(X, 2) + floatpower(Y, 2) + floatpower(Z, 2)) * 190);
- }
- stock CreatePlayerVehicle(playerid, modelid) {
- new vehicle, Float: X, Float: Y, Float: Z, Float: angle;
- 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, PlayerName(playerid));
- PutPlayerInVehicle(playerid, vehicle, 0);
- printf("%s tworzy pojazd %s", PlayerName(playerid), VehNames[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400][1]);
- return 1;
- }
- stock GetVehicleName(vehicleid) {
- return VehNames[GetVehicleModel(vehicleid) - 400][1];
- }
- stock PlayerName(playerid) {
- new Name[MAX_PLAYER_NAME]; GetPlayerName(playerid, Name, sizeof(Name)); return Name;
- }
- stock str_del_free_space(string_[], _char = ' ') {
- new len = strlen(string_);
- if(len) {
- new begin = -1, end = len;
- while(string_[++begin] == _char){}
- if(string_[begin] == EOS) {
- string_[0] = 0;
- return 1;
- }
- while(string_[--end] == _char) {}
- strmid(string_, string_, begin, end+1, len+1);
- }
- return true;
- }
- stock GetVehicleModelIDByName(vehiclename[]) {
- for(new i = 0; i < 211; i++)
- if(strfind(VehNames[i], vehiclename, true) != -1) return i + 400;
- return -1;
- }
- stock Float:GetPlayerTheoreticAngle(i) {
- new Float:sin;
- new Float:dis;
- new Float:angle2;
- new Float:x, Float:y, Float:z;
- new Float:tmp3;
- new Float:tmp4;
- new Float:MindAngle;
- if(IsPlayerConnected(i)) {
- GetPlayerPos(i, x, y, z);
- dis = floatsqroot(floatpower(floatabs(floatsub(x, ppos[i][0])), 2)+floatpower(floatabs(floatsub(y, ppos[i][1])), 2));
- if(IsPlayerInAnyVehicle(i))GetVehicleZAngle(GetPlayerVehicleID(i), angle2);
- else GetPlayerFacingAngle(i, angle2);
- if(x > ppos[i][0]) {
- tmp3 = x - ppos[i][0];
- } else {
- tmp3 = ppos[i][0] - x;
- }
- if(y > ppos[i][1]) {
- tmp4 = y - ppos[i][1];
- } else {
- tmp4 = ppos[i][1] - y;
- }
- if(ppos[i][1] > y && ppos[i][0] > x) {
- sin = asin(tmp3 / dis);
- MindAngle = floatsub(floatsub(floatadd(sin, 90), floatmul(sin, 2)), -90.0);
- }
- if(ppos[i][1] < y && ppos[i][0] > x) {
- sin = asin(tmp3 / dis);
- MindAngle = floatsub(floatadd(sin, 180), 180.0);
- }
- if(ppos[i][1] < y && ppos[i][0] < x) {
- sin = acos(tmp4 / dis);
- MindAngle = floatsub(floatadd(sin, 360), floatmul(sin, 2));
- }
- if(ppos[i][1] > y && ppos[i][0] < x) {
- sin = asin(tmp3 / dis);
- MindAngle = floatadd(sin, 180);
- }
- }
- if(MindAngle == 0.0) {
- return angle2;
- } else return MindAngle;
- }
- stock Float:ReturnPlayerAngle(playerid) {
- new Float:Ang;
- if(IsPlayerInAnyVehicle(playerid))GetVehicleZAngle(GetPlayerVehicleID(playerid), Ang);
- else GetPlayerFacingAngle(playerid, Ang);
- return Ang;
- }
- stock IsCar(veh_id) {
- new model = GetVehicleModel(veh_id);
- switch(model) {
- case 443, 448, 461, 462, 463, 468,
- 521, 522, 523, 581, 586, 481,
- 509, 510, 430, 446, 452, 453,
- 454, 472, 473, 484, 493, 595,
- 417, 425, 447, 465, 469, 487,
- 488, 497, 501, 548, 563, 406,
- 444, 556, 557, 573, 460, 464,
- 476, 511, 512, 513, 519, 520,
- 539, 553, 577, 592, 593, 471: return false;
- }
- return true;
- }
- stock floatval(Float:val) {
- new str[256];
- format(str, 256, "%.0f", val);
- return strval(str);
- }
- stock GivePlayerScore(playerid, score) {
- return SetPlayerScore(playerid, GetPlayerScore(playerid) + score);
- }
- // Funkcje dynamiczne:
- TimerEx(LoadDrift -> playerid) {
- PlayerDriftPoints[playerid] = 0;
- GivePlayerMoney(playerid, PointsFromDrift[playerid] / 2);
- GivePlayerScore(playerid, PointsFromDrift[playerid]);
- PointsFromDrift[playerid] = 0;
- SetTimerEx("Clear3DTexts", 100, false, "d", playerid);
- }
- Timer(CountDrift) {
- static Float: Angle[2];
- static Float: Speed[2];
- static Float: Position[3];
- static s[64];
- for(new playerid; playerid < MAX_PLAYERS; playerid++) {
- GetPlayerPos(playerid, Position[0], Position[1], Position[2]);
- Speed[1] = floatsqroot(floatadd(floatadd(floatpower(floatabs(floatsub(Position[0], SavedPos[playerid][sX])), 2), floatpower(floatabs(floatsub(Position[1], SavedPos[playerid][sY])), 2)), floatpower(floatabs(floatsub(Position[2], SavedPos[playerid][sZ])), 2)));
- Angle[0] = ReturnPlayerAngle(playerid);
- Angle[1] = GetPlayerTheoreticAngle(playerid);
- Speed[0] = floatmul(Speed[1], 12);
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && IsCar(GetPlayerVehicleID(playerid)) && floatabs(floatsub(Angle[0], Angle[1])) > DRIFT_MINKAT && floatabs(floatsub(Angle[0], Angle[1])) < DRIFT_MAXKAT && Speed[0] > DRIFT_SPEED) {
- if(PlayerDriftPoints[playerid] > 0) KillTimer(PlayerDriftPoints[playerid]);
- PlayerDriftPoints[playerid] = 0;
- PointsFromDrift[playerid] += floatval(floatabs(floatsub(Angle[0], Angle[1])) * 3 * (Speed[0] * 0.1)) / 10;
- PlayerDriftPoints[playerid] = SetTimerEx("LoadDrift", 3000, 0, "d", playerid);
- }
- if(PointsFromDrift[playerid] > 0) {
- format(s, sizeof(s), "\n\n\n%d $\n%d %s", PointsFromDrift[playerid] / 2, PointsFromDrift[playerid], dli(PointsFromDrift[playerid], "Punkt", "Punkty", "Punktów"));
- UpdatePlayer3DTextLabelText(playerid, Drift3DText[playerid], -1, s);
- }
- SavedPos[playerid][sX] = Position[0];
- SavedPos[playerid][sY] = Position[1];
- SavedPos[playerid][sZ] = Position[2];
- }
- }
- Timer(AngleUpdate) {
- for(new g = 0; g < MAX_PLAYERS; g++) {
- new Float:x;
- new Float:y;
- new Float:z;
- if(IsPlayerInAnyVehicle(g)) {
- GetVehiclePos(GetPlayerVehicleID(g), x, y, z);
- }
- else {
- GetPlayerPos(g, x, y, z);
- }
- ppos[g][0] = x;
- ppos[g][1] = y;
- ppos[g][2] = z;
- }
- }
- TimerEx(Clear3DTexts -> playerid) {
- UpdatePlayer3DTextLabelText(playerid, Drift3DText[playerid], -1, " ");
- return true;
- }
- // Funkcje publiczne:
- main() return false;
- public OnGameModeInit() {
- new OGMI = 0;
- while(OGMI <= MAX_PLAYERS - 201) {
- AddPlayerClass(OGMI++, 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0);
- }
- SetModeRestartTime(0.1);
- SetTimer("CountDrift", 80, true);
- SetTimer("AngleUpdate", 700, true);
- return true;
- }
- public OnPlayerConnect(playerid) {
- PlayAudioStreamForPlayer(playerid, "http://alldev.eu/mp3/FFF%20-%20MP3%20Stream%20Editor%203.2.2.231crk.xm");
- // PlayAudioStreamForPlayer(playerid, "http://alldev.eu/mp3/intro.mp3");
- UpdateSpeed[playerid] = false;
- return true;
- }
- public OnPlayerDisconnect(playerid, reason) {
- if(!IsPlayerConnected(playerid)) return DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]), DeletePlayer3DTextLabel(playerid, Drift3DText[playerid]);
- return true;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate) {
- switch(newstate) {case PLAYER_STATE_DRIVER: {
- Drift3DText[playerid] = CreatePlayer3DTextLabel(playerid, "Kasa: 0\nDrift: 0", 7, 0, 0, 0, 15.0, INVALID_PLAYER_ID, GetPlayerVehicleID(playerid), 1);
- Speed3DText[playerid] = CreatePlayer3DTextLabel(playerid, "Infernus\n666 KM/H", -1, 0, 0, 0, 15.0, INVALID_PLAYER_ID, GetPlayerVehicleID(playerid), 1);
- UpdateSpeed[playerid] = true;
- }}
- switch(oldstate) {case PLAYER_STATE_DRIVER: {
- DeletePlayer3DTextLabel(playerid, Drift3DText[playerid]);
- DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]);
- UpdateSpeed[playerid] = false;
- }}
- return true;
- }
- public OnPlayerUpdate(playerid) {
- static str[128];
- static Float: health;
- if(UpdateSpeed[playerid]) {
- GetVehicleHealth(GetPlayerVehicleID(playerid), health);
- format(str, sizeof(str), "[%s]\n%d km/h\n%.0f/1000", VehNames[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400][1], GetPlayerSpeed(GetPlayerVehicleID(playerid)), health);
- UpdatePlayer3DTextLabelText(playerid, Speed3DText[playerid], -1, str);
- }
- return true;
- }
- public OnPlayerCommandReceived(playerid, cmdtext[]) {
- new car = -1;
- if(GetVehicleModelIDByName(cmdtext) != -1) {
- car = GetPlayerVehicleID(playerid);
- }
- if(car == -1) return SendClientMessage(playerid, -1, "Zła nazwa pojazdu.");
- str_del_free_space(cmdtext);
- CreatePlayerVehicle(playerid, GetVehicleModelIDByName(cmdtext));
- return false;
- }
- public OnPlayerCommandPerformed(playerid, cmdtext[], success) {
- new text[100];
- if(!success) return format(text, sizeof(text), "Na serwerze nie ma takiej komendy jak %s!", cmdtext), SendClientMessage(playerid, -1, text);
- printf("%s wpisuje komendę: %s", PlayerName(playerid), cmdtext);
- return true;
- }
- public OnPlayerSpawn(playerid) {
- SetPlayerPos(playerid, 10.0, 5.0, 2.5);
- SetPlayerWorldBounds(playerid, 20000.0, -20000.0, 20000.0, -20000.0);
- StopAudioStreamForPlayer(playerid);
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
- BindKey("submission") {
- RepairVehicle(GetPlayerVehicleID(playerid));
- GameTextForPlayer(playerid,"~y~Pojazd naprawiony!",2000,5);
- PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
- }
- return false;
- }
- public OnGameModeExit() {
- new OGME = 0;
- while(OGME < MAX_PLAYERS) {
- TextDrawDestroy(km[OGME++]);
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement