Advertisement
Shiny_

PSD

Aug 28th, 2013
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.86 KB | None | 0 0
  1. // Biblioteki:
  2.     #include <a_samp>
  3.     #include <YSF>
  4.     #include <zcmd>
  5.  
  6. // Makra i constansy:
  7.     #define Timer(%0)           forward %0(); public %0()
  8.     #define TimerEx(%0->%1)     forward %0(%1); public %0(%1)
  9.     #define dynamic(%0)         forward %0(); public %0()
  10.     #define dynamic_arg(%0->%1) forward %0(%1); public %0(%1)
  11.     #define dli(%1,%2,%3,%4)    ((%1 == 1)? (%2): (((%1 % 10 > 1) && (%1 % 10 < 5) && !((%1 % 100 >= 10) && (%1 % 100 <= 21)))? (%3): (%4)))
  12.     #define BindKey(%1)         if(newkeys & BindKey_(%1))
  13.     #define DRIFT_MINKAT        10.0
  14.     #define DRIFT_MAXKAT        90.0
  15.     #define DRIFT_SPEED         30.0
  16.     #define COLOR_LIGHTRED      0xFF0000FF
  17.     #define COLOR_LIGHTBLUE     0x33CCFFAA 
  18.    
  19. // Enumeratory:
  20.     enum Float:Pos {
  21.         Float:sX, Float:sY, Float:sZ
  22.     };
  23.  
  24.     enum Player {
  25.         Registered,
  26.         LoggedIn,
  27.     };
  28.    
  29. // Zmienne:
  30.     new
  31.         bool: UpdateSpeed[MAX_PLAYERS] = {false, ...},
  32.         Float: ppos[MAX_PLAYERS][3],
  33.         Float: SavedPos[MAX_PLAYERS][Pos],
  34.         PlayerText3D: Drift3DText[MAX_PLAYERS],
  35.         PlayerText3D: Speed3DText[MAX_PLAYERS],
  36.         Text: km[MAX_PLAYERS],
  37.         PointsFromDrift[MAX_PLAYERS],
  38.         PlayerDriftPoints[MAX_PLAYERS],
  39.         VehNames[212][32] = {
  40.             "/Landstalker", "/Bravura", "/Buffalo", "/Linerunner", "/Pereniel", "/Sentinel", "/Dumper", "/Firetruck", "/Trashmaster", "/Stretch",
  41.             "/Manana", "/Infernus", "/Voodoo", "/Pony", "/Mule", "/Cheetah", "/Ambulance", "/Leviathan", "/Moonbeam", "/Esperanto",
  42.             "/Taxi", "/Washington", "/Bobcat", "/Mr Whoopee", "/BF Injection", "/Hunter", "/Premier", "/Enforcer", "/Securicar", "/Banshee",
  43.             "/Predator", "/Bus", "/Rhino", "/Barracks", "/Hotknife", "/Trailer", "/Previon", "/Coach", "/Cabbie", "/Stallion",
  44.             "/Rumpo", "/RC Bandit", "/Romero", "/Packer", "/Monster", "/Admiral", "/Squalo", "/Seasparrow", "/Pizzaboy", "/Tram",
  45.             "/Trailer", "/Turismo", "/Speeder", "/Reefer", "/Tropic", "/Flatbed", "/Yankee", "/Caddy", "/Solair", "/Berkley's RC Van",
  46.             "/Skimmer", "/PCJ-600", "/Faggio", "/Freeway", "/RC Baron", "/RC Raider", "/Glendale", "/Oceanic", "/Sanchez", "/Sparrow",
  47.             "/Patriot", "/Quad", "/Coastguard", "/Dinghy", "/Hermes", "/Sabre", "/Rustler", "/ZR 350", "/Walton", "/Regina",
  48.             "/Comet", "/BMX", "/Burrito", "/Camper", "/Marquis", "/Baggage", "/Dozer", "/Maverick", "/News Chopper", "/Rancher",
  49.             "/FBI Rancher", "/Virgo", "/Greenwood", "/Jetmax", "/Hotring", "/Sandking", "/Blista Compact", "/Police Maverick", "/Boxville", "/Benson",
  50.             "/Mesa", "/RC Goblin", "/Hotring Racer", "/Hotring Racer", "/Bloodring Banger", "/Rancher", "/Super GT", "/Elegant", "/Journey", "/Bike",
  51.             "/Mountain Bike", "/Beagle", "/Cropdust", "/Stunt", "/Tanker", "/RoadTrain", "/Nebula", "/Majestic", "/Buccaneer", "/Shamal",
  52.             "/Hydra", "/FCR", "/NRG", "/HPV1000", "/Cement Truck", "/Tow Truck", "/Fortune", "/Cadrona", "/FBI Truck", "/Willard",
  53.             "/Forklift", "/Tractor", "/Combine", "/Feltzer", "/Remington", "/Slamvan", "/Blade", "/Freight", "/Streak", "/Vortex",
  54.             "/Vincent", "/Bullet", "/Clover", "/Sadler", "/Firetruck", "/Hustler", "/Intruder", "/Primo", "/Cargobob", "/Tampa",
  55.             "/Sunrise", "/Merit", "/Utility", "/Nevada", "/Yosemite", "/Windsor", "/Monstera", "/Monsterb", "/Uranus", "/Jester",
  56.             "/Sultan", "/Stratum", "/Elegy", "/Raindance", "/RC Tiger", "/Flash", "/Tahoma", "/Savanna", "/Bandito", "/Freight",
  57.             "/Trailer", "/Kart", "/Mower", "/Duneride", "/Sweeper", "/Broadway", "/Tornado", "/AT-400", "/DFT-30", "/Huntley",
  58.             "/Stafford", "/BF-400", "/Newsvan", "/Tug", "/Trailer2", "/Emperor", "/Wayfarer", "/Euros", "/Hotdog", "/Club",
  59.             "/Trailer3", "/Trailer4", "/Andromeda", "/Dodo", "/RC Cam", "/Launch", "/Police Car (LSPD)", "/Police Car (SFPD)", "/Police Car (LVPD)", "/Police Ranger",
  60.             "/Picador", "/S.W.A.T. Van", "/Alpha", "/Phoenix", "/Glendale", "/Sadler", "/Luggage Trailer", "/Luggage Trailer2", "/Stair Trailer", "/Boxville",
  61.             "/Farm Plow", "/Utility Trailer"
  62.         };
  63.  
  64. // Funkcje statyczne:
  65.     stock BindKey_(key[]) {
  66.         if(!strcmp("action", key, true)) return KEY_ACTION;
  67.         else if(!strcmp("crouch", key, true)) return KEY_CROUCH;
  68.         else if(!strcmp("fire", key, true)) return KEY_FIRE;
  69.         else if(!strcmp("sprint", key, true)) return KEY_SPRINT;
  70.         else if(!strcmp("attack", key, true)) return KEY_SECONDARY_ATTACK;
  71.         else if(!strcmp("jump", key, true)) return KEY_JUMP;
  72.         else if(!strcmp("lookr", key, true)) return KEY_LOOK_RIGHT;
  73.         else if(!strcmp("lookl", key, true)) return KEY_LOOK_LEFT;
  74.         else if(!strcmp("lookb", key, true)) return KEY_LOOK_BEHIND;
  75.         else if(!strcmp("handbrake", key, true)) return KEY_HANDBRAKE;
  76.         else if(!strcmp("submission", key, true)) return KEY_SUBMISSION;
  77.         else if(!strcmp("walk", key, true)) return KEY_WALK;
  78.         else if(!strcmp("aup", key, true)) return KEY_ANALOG_UP;
  79.         else if(!strcmp("adown", key, true)) return KEY_ANALOG_DOWN;
  80.         else if(!strcmp("aleft", key, true)) return KEY_ANALOG_LEFT;
  81.         else if(!strcmp("aright", key, true)) return KEY_ANALOG_RIGHT;
  82.         else if(!strcmp("yes", key, true)) return KEY_YES;
  83.         else if(!strcmp("no", key, true)) return KEY_NO;
  84.         else if(!strcmp("ctrlback", key, true)) return KEY_NO;
  85.         else if(!strcmp("up", key, true)) return KEY_UP;
  86.         else if(!strcmp("down", key, true)) return KEY_DOWN;
  87.         else if(!strcmp("left", key, true)) return KEY_LEFT;
  88.         else if(!strcmp("right", key, true)) return KEY_RIGHT;
  89.         else return false;
  90.     }
  91.    
  92.     stock rand(one, two) {    
  93.         return random(two - one) + one;
  94.     }
  95.    
  96.     stock GetPlayerSpeed(v) {
  97.         new Float: X, Float: Y, Float: Z;
  98.         GetVehicleVelocity(v, X, Y, Z);
  99.         return floatround(floatsqroot(floatpower(X, 2) + floatpower(Y, 2) + floatpower(Z, 2)) * 190);
  100.     }
  101.    
  102.     stock CreatePlayerVehicle(playerid, modelid) {
  103.         new vehicle, Float: X, Float: Y, Float: Z, Float: angle;
  104.         if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
  105.             vehicle = GetPlayerVehicleID(playerid);
  106.             GetVehiclePos(vehicle, X, Y, Z);
  107.             GetVehicleZAngle(vehicle, angle);
  108.             DestroyVehicle(vehicle);
  109.         } else {
  110.             GetPlayerPos(playerid, X, Y, Z);
  111.             GetPlayerFacingAngle(playerid, angle);
  112.         }
  113.         vehicle = AddStaticVehicle(modelid, X, Y, Z + 1, angle, -1, -1);
  114.         LinkVehicleToInterior(vehicle, GetPlayerInterior(playerid));
  115.         SetVehicleVirtualWorld(vehicle, GetPlayerVirtualWorld(playerid));
  116.         SetVehicleNumberPlate(vehicle, PlayerName(playerid));
  117.         PutPlayerInVehicle(playerid, vehicle, 0);
  118.         printf("%s tworzy pojazd %s", PlayerName(playerid), VehNames[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400][1]);
  119.         return 1;
  120.     }
  121.    
  122.     stock GetVehicleName(vehicleid) {
  123.         return VehNames[GetVehicleModel(vehicleid) - 400][1];
  124.     }
  125.    
  126.     stock PlayerName(playerid) {
  127.         new Name[MAX_PLAYER_NAME]; GetPlayerName(playerid, Name, sizeof(Name)); return Name;
  128.     }
  129.    
  130.     stock str_del_free_space(string_[], _char = ' ') {
  131.         new len = strlen(string_);
  132.         if(len) {
  133.             new begin = -1, end = len;
  134.             while(string_[++begin] == _char){}
  135.             if(string_[begin] == EOS) {
  136.                 string_[0] = 0;
  137.                 return 1;
  138.             }
  139.             while(string_[--end] == _char) {}
  140.             strmid(string_, string_, begin, end+1, len+1);
  141.         }
  142.         return true;
  143.     }
  144.    
  145.     stock GetVehicleModelIDByName(vehiclename[]) {
  146.         for(new i = 0; i < 211; i++)
  147.             if(strfind(VehNames[i], vehiclename, true) != -1) return i + 400;
  148.         return -1;
  149.     }
  150.    
  151.     stock Float:GetPlayerTheoreticAngle(i) {
  152.         new Float:sin;
  153.         new Float:dis;
  154.         new Float:angle2;
  155.         new Float:x, Float:y, Float:z;
  156.         new Float:tmp3;
  157.         new Float:tmp4;
  158.         new Float:MindAngle;
  159.         if(IsPlayerConnected(i)) {
  160.             GetPlayerPos(i, x, y, z);
  161.             dis = floatsqroot(floatpower(floatabs(floatsub(x, ppos[i][0])), 2)+floatpower(floatabs(floatsub(y, ppos[i][1])), 2));
  162.             if(IsPlayerInAnyVehicle(i))GetVehicleZAngle(GetPlayerVehicleID(i), angle2);
  163.             else GetPlayerFacingAngle(i, angle2);
  164.             if(x > ppos[i][0]) {
  165.                 tmp3 = x - ppos[i][0];
  166.             } else {
  167.                 tmp3 = ppos[i][0] - x;
  168.             }
  169.             if(y > ppos[i][1]) {
  170.                 tmp4 = y - ppos[i][1];
  171.             } else {
  172.                 tmp4 = ppos[i][1] - y;
  173.             }
  174.             if(ppos[i][1] > y && ppos[i][0] > x) {
  175.                 sin = asin(tmp3 / dis);
  176.                 MindAngle = floatsub(floatsub(floatadd(sin, 90), floatmul(sin, 2)), -90.0);
  177.             }
  178.             if(ppos[i][1] < y && ppos[i][0] > x) {
  179.                 sin = asin(tmp3 / dis);
  180.                 MindAngle = floatsub(floatadd(sin, 180), 180.0);
  181.             }
  182.             if(ppos[i][1] < y && ppos[i][0] < x) {
  183.                 sin = acos(tmp4 / dis);
  184.                 MindAngle = floatsub(floatadd(sin, 360), floatmul(sin, 2));
  185.             }
  186.             if(ppos[i][1] > y && ppos[i][0] < x) {
  187.                 sin = asin(tmp3 / dis);
  188.                 MindAngle = floatadd(sin, 180);
  189.             }
  190.         }
  191.         if(MindAngle == 0.0) {
  192.             return angle2;
  193.         } else return MindAngle;
  194.     }
  195.  
  196.     stock Float:ReturnPlayerAngle(playerid) {
  197.         new Float:Ang;
  198.         if(IsPlayerInAnyVehicle(playerid))GetVehicleZAngle(GetPlayerVehicleID(playerid), Ang);
  199.         else GetPlayerFacingAngle(playerid, Ang);
  200.         return Ang;
  201.     }
  202.    
  203.     stock IsCar(veh_id) {
  204.         new model = GetVehicleModel(veh_id);
  205.         switch(model) {
  206.             case 443, 448, 461, 462, 463, 468,
  207.                  521, 522, 523, 581, 586, 481,
  208.                  509, 510, 430, 446, 452, 453,
  209.                  454, 472, 473, 484, 493, 595,
  210.                  417, 425, 447, 465, 469, 487,
  211.                  488, 497, 501, 548, 563, 406,
  212.                  444, 556, 557, 573, 460, 464,
  213.                  476, 511, 512, 513, 519, 520,
  214.                  539, 553, 577, 592, 593, 471: return false;
  215.         }
  216.         return true;
  217.     }
  218.    
  219.     stock floatval(Float:val) {
  220.         new str[256];
  221.         format(str, 256, "%.0f", val);
  222.         return strval(str);
  223.     }
  224.    
  225.     stock GivePlayerScore(playerid, score) {
  226.         return SetPlayerScore(playerid, GetPlayerScore(playerid) + score);
  227.     }
  228.    
  229. // Funkcje dynamiczne:
  230.     TimerEx(LoadDrift -> playerid) {
  231.         PlayerDriftPoints[playerid] = 0;
  232.         GivePlayerMoney(playerid, PointsFromDrift[playerid] / 2);
  233.         GivePlayerScore(playerid, PointsFromDrift[playerid]);
  234.         PointsFromDrift[playerid] = 0;
  235.         SetTimerEx("Clear3DTexts", 100, false, "d", playerid);
  236.     }
  237.    
  238.     Timer(CountDrift) {
  239.         static Float: Angle[2];
  240.         static Float: Speed[2];
  241.         static Float: Position[3];
  242.         static s[64];
  243.        
  244.         for(new playerid; playerid < MAX_PLAYERS; playerid++) {
  245.             GetPlayerPos(playerid, Position[0], Position[1], Position[2]);
  246.             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)));
  247.             Angle[0] = ReturnPlayerAngle(playerid);
  248.             Angle[1] = GetPlayerTheoreticAngle(playerid);
  249.             Speed[0] = floatmul(Speed[1], 12);
  250.            
  251.             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) {
  252.                 if(PlayerDriftPoints[playerid] > 0) KillTimer(PlayerDriftPoints[playerid]);
  253.                 PlayerDriftPoints[playerid] = 0;
  254.                 PointsFromDrift[playerid] += floatval(floatabs(floatsub(Angle[0], Angle[1])) * 3 * (Speed[0] * 0.1)) / 10;
  255.                 PlayerDriftPoints[playerid] = SetTimerEx("LoadDrift", 3000, 0, "d", playerid);
  256.             }
  257.            
  258.             if(PointsFromDrift[playerid] > 0) {
  259.                 format(s, sizeof(s), "\n\n\n%d $\n%d %s", PointsFromDrift[playerid] / 2, PointsFromDrift[playerid], dli(PointsFromDrift[playerid], "Punkt", "Punkty", "Punktów"));
  260.                 UpdatePlayer3DTextLabelText(playerid, Drift3DText[playerid], -1, s);
  261.             }
  262.  
  263.             SavedPos[playerid][sX] = Position[0];
  264.             SavedPos[playerid][sY] = Position[1];
  265.             SavedPos[playerid][sZ] = Position[2];
  266.         }
  267.     }
  268.    
  269.     Timer(AngleUpdate) {
  270.         for(new g = 0; g < MAX_PLAYERS; g++) {
  271.             new Float:x;
  272.             new Float:y;
  273.             new Float:z;
  274.             if(IsPlayerInAnyVehicle(g)) {
  275.                 GetVehiclePos(GetPlayerVehicleID(g), x, y, z);
  276.             }
  277.             else {
  278.                 GetPlayerPos(g, x, y, z);
  279.             }
  280.             ppos[g][0] = x;
  281.             ppos[g][1] = y;
  282.             ppos[g][2] = z;
  283.         }
  284.     }
  285.    
  286.     TimerEx(Clear3DTexts -> playerid) {
  287.         UpdatePlayer3DTextLabelText(playerid, Drift3DText[playerid], -1, " ");
  288.         return true;
  289.     }
  290.  
  291. // Funkcje publiczne:
  292.     main() return false;
  293.    
  294.     public OnGameModeInit() {
  295.         new OGMI = 0;
  296.         while(OGMI <= MAX_PLAYERS - 201) {
  297.             AddPlayerClass(OGMI++, 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0);
  298.         }
  299.         SetModeRestartTime(0.1);
  300.         SetTimer("CountDrift", 80, true);
  301.         SetTimer("AngleUpdate", 700, true);
  302.         return true;
  303.     }
  304.    
  305.     public OnPlayerConnect(playerid) {
  306.         PlayAudioStreamForPlayer(playerid, "http://alldev.eu/mp3/FFF%20-%20MP3%20Stream%20Editor%203.2.2.231crk.xm");
  307.         // PlayAudioStreamForPlayer(playerid, "http://alldev.eu/mp3/intro.mp3");
  308.         UpdateSpeed[playerid] = false;
  309.         return true;
  310.     }
  311.  
  312.     public OnPlayerDisconnect(playerid, reason) {
  313.         if(!IsPlayerConnected(playerid)) return DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]), DeletePlayer3DTextLabel(playerid, Drift3DText[playerid]);
  314.         return true;
  315.     }
  316.  
  317.     public OnPlayerStateChange(playerid, newstate, oldstate) {
  318.         switch(newstate) {case PLAYER_STATE_DRIVER: {
  319.             Drift3DText[playerid] = CreatePlayer3DTextLabel(playerid, "Kasa: 0\nDrift: 0", 7, 0, 0, 0, 15.0, INVALID_PLAYER_ID, GetPlayerVehicleID(playerid), 1);
  320.             Speed3DText[playerid] = CreatePlayer3DTextLabel(playerid, "Infernus\n666 KM/H", -1, 0, 0, 0, 15.0, INVALID_PLAYER_ID, GetPlayerVehicleID(playerid), 1);
  321.             UpdateSpeed[playerid] = true;
  322.         }}
  323.         switch(oldstate) {case PLAYER_STATE_DRIVER: {
  324.             DeletePlayer3DTextLabel(playerid, Drift3DText[playerid]);
  325.             DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]);
  326.             UpdateSpeed[playerid] = false;
  327.         }}
  328.         return true;
  329.     }
  330.    
  331.     public OnPlayerUpdate(playerid) {
  332.         static str[128];
  333.         static Float: health;
  334.        
  335.         if(UpdateSpeed[playerid]) {
  336.             GetVehicleHealth(GetPlayerVehicleID(playerid), health);
  337.             format(str, sizeof(str), "[%s]\n%d km/h\n%.0f/1000", VehNames[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400][1],  GetPlayerSpeed(GetPlayerVehicleID(playerid)), health);
  338.             UpdatePlayer3DTextLabelText(playerid, Speed3DText[playerid], -1, str);
  339.         }
  340.         return true;
  341.     }
  342.  
  343.     public OnPlayerCommandReceived(playerid, cmdtext[]) {
  344.         new car = -1;
  345.         if(GetVehicleModelIDByName(cmdtext) != -1) {
  346.             car = GetPlayerVehicleID(playerid);
  347.         }
  348.         if(car == -1) return SendClientMessage(playerid, -1, "Zła nazwa pojazdu.");
  349.         str_del_free_space(cmdtext);
  350.         CreatePlayerVehicle(playerid, GetVehicleModelIDByName(cmdtext));
  351.         return false;
  352.     }
  353.    
  354.     public OnPlayerCommandPerformed(playerid, cmdtext[], success) {
  355.         new text[100];
  356.         if(!success) return format(text, sizeof(text), "Na serwerze nie ma takiej komendy jak %s!", cmdtext), SendClientMessage(playerid, -1, text);
  357.         printf("%s wpisuje komendę: %s", PlayerName(playerid), cmdtext);
  358.         return true;
  359.     }
  360.    
  361.     public OnPlayerSpawn(playerid) {
  362.         SetPlayerPos(playerid, 10.0, 5.0, 2.5);
  363.         SetPlayerWorldBounds(playerid, 20000.0, -20000.0, 20000.0, -20000.0);
  364.         StopAudioStreamForPlayer(playerid);
  365.         return 1;
  366.     }
  367.    
  368.     public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  369.         BindKey("submission") {
  370.             RepairVehicle(GetPlayerVehicleID(playerid));
  371.             GameTextForPlayer(playerid,"~y~Pojazd naprawiony!",2000,5);
  372.             PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
  373.         }
  374.         return false;
  375.     }
  376.  
  377.     public OnGameModeExit() {
  378.         new OGME = 0;
  379.         while(OGME < MAX_PLAYERS) {
  380.             TextDrawDestroy(km[OGME++]);
  381.         }
  382.         return true;
  383.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement