Advertisement
Shiny_

HIPER OPTYMALIZANCJA

Aug 23rd, 2013
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.50 KB | None | 0 0
  1. // Biblioteki:
  2.     #include <a_samp>
  3.     #include <YSF>
  4.     #include <zcmd>
  5.  
  6. // Makra i constansy:
  7.     #define function%0(%1)      forward%0(%1);      public%0(%1)
  8.     #define BindKey(%1) if(newkeys & BindKey_(%1))
  9.    
  10. // Zmienne:
  11.     new
  12.         i__[MAX_PLAYERS],
  13.         bool:UpdateSpeed[MAX_PLAYERS] = {false, ...},
  14.         PlayerText3D: Speed3DText[MAX_PLAYERS],
  15.         Text: km[MAX_PLAYERS],
  16.         VehicleCmdNames[212][32] = {
  17.             "/Landstalker", "/Bravura", "/Buffalo", "/Linerunner", "/Pereniel", "/Sentinel", "/Dumper", "/Firetruck", "/Trashmaster", "/Stretch",
  18.             "/Manana", "/Infernus", "/Voodoo", "/Pony", "/Mule", "/Cheetah", "/Ambulance", "/Leviathan", "/Moonbeam", "/Esperanto",
  19.             "/Taxi", "/Washington", "/Bobcat", "/Mr Whoopee", "/BF Injection", "/Hunter", "/Premier", "/Enforcer", "/Securicar", "/Banshee",
  20.             "/Predator", "/Bus", "/Rhino", "/Barracks", "/Hotknife", "/Trailer", "/Previon", "/Coach", "/Cabbie", "/Stallion",
  21.             "/Rumpo", "/RC Bandit", "/Romero", "/Packer", "/Monster", "/Admiral", "/Squalo", "/Seasparrow", "/Pizzaboy", "/Tram",
  22.             "/Trailer", "/Turismo", "/Speeder", "/Reefer", "/Tropic", "/Flatbed", "/Yankee", "/Caddy", "/Solair", "/Berkley's RC Van",
  23.             "/Skimmer", "/PCJ-600", "/Faggio", "/Freeway", "/RC Baron", "/RC Raider", "/Glendale", "/Oceanic", "/Sanchez", "/Sparrow",
  24.             "/Patriot", "/Quad", "/Coastguard", "/Dinghy", "/Hermes", "/Sabre", "/Rustler", "/ZR 350", "/Walton", "/Regina",
  25.             "/Comet", "/BMX", "/Burrito", "/Camper", "/Marquis", "/Baggage", "/Dozer", "/Maverick", "/News Chopper", "/Rancher",
  26.             "/FBI Rancher", "/Virgo", "/Greenwood", "/Jetmax", "/Hotring", "/Sandking", "/Blista Compact", "/Police Maverick", "/Boxville", "/Benson",
  27.             "/Mesa", "/RC Goblin", "/Hotring Racer", "/Hotring Racer", "/Bloodring Banger", "/Rancher", "/Super GT", "/Elegant", "/Journey", "/Bike",
  28.             "/Mountain Bike", "/Beagle", "/Cropdust", "/Stunt", "/Tanker", "/RoadTrain", "/Nebula", "/Majestic", "/Buccaneer", "/Shamal",
  29.             "/Hydra", "/FCR", "/NRG", "/HPV1000", "/Cement Truck", "/Tow Truck", "/Fortune", "/Cadrona", "/FBI Truck", "/Willard",
  30.             "/Forklift", "/Tractor", "/Combine", "/Feltzer", "/Remington", "/Slamvan", "/Blade", "/Freight", "/Streak", "/Vortex",
  31.             "/Vincent", "/Bullet", "/Clover", "/Sadler", "/Firetruck", "/Hustler", "/Intruder", "/Primo", "/Cargobob", "/Tampa",
  32.             "/Sunrise", "/Merit", "/Utility", "/Nevada", "/Yosemite", "/Windsor", "/Monstera", "/Monsterb", "/Uranus", "/Jester",
  33.             "/Sultan", "/Stratum", "/Elegy", "/Raindance", "/RC Tiger", "/Flash", "/Tahoma", "/Savanna", "/Bandito", "/Freight",
  34.             "/Trailer", "/Kart", "/Mower", "/Duneride", "/Sweeper", "/Broadway", "/Tornado", "/AT-400", "/DFT-30", "/Huntley",
  35.             "/Stafford", "/BF-400", "/Newsvan", "/Tug", "/Trailer2", "/Emperor", "/Wayfarer", "/Euros", "/Hotdog", "/Club",
  36.             "/Trailer3", "/Trailer4", "/Andromeda", "/Dodo", "/RC Cam", "/Launch", "/Police Car (LSPD)", "/Police Car (SFPD)", "/Police Car (LVPD)", "/Police Ranger",
  37.             "/Picador", "/S.W.A.T. Van", "/Alpha", "/Phoenix", "/Glendale", "/Sadler", "/Luggage Trailer", "/Luggage Trailer2", "/Stair Trailer", "/Boxville",
  38.             "/Farm Plow", "/Utility Trailer"
  39.         }
  40.     ;
  41.  
  42. // Funkcje statyczne:
  43.     stock BindKey_(key[]) {
  44.         if(!strcmp("action", key, true)) return KEY_ACTION;
  45.         else if(!strcmp("crouch", key, true)) return KEY_CROUCH;
  46.         else if(!strcmp("fire", key, true)) return KEY_FIRE;
  47.         else if(!strcmp("sprint", key, true)) return KEY_SPRINT;
  48.         else if(!strcmp("attack", key, true)) return KEY_SECONDARY_ATTACK;
  49.         else if(!strcmp("jump", key, true)) return KEY_JUMP;
  50.         else if(!strcmp("lookr", key, true)) return KEY_LOOK_RIGHT;
  51.         else if(!strcmp("lookl", key, true)) return KEY_LOOK_LEFT;
  52.         else if(!strcmp("lookb", key, true)) return KEY_LOOK_BEHIND;
  53.         else if(!strcmp("handbrake", key, true)) return KEY_HANDBRAKE;
  54.         else if(!strcmp("submission", key, true)) return KEY_SUBMISSION;
  55.         else if(!strcmp("walk", key, true)) return KEY_WALK;
  56.         else if(!strcmp("aup", key, true)) return KEY_ANALOG_UP;
  57.         else if(!strcmp("adown", key, true)) return KEY_ANALOG_DOWN;
  58.         else if(!strcmp("aleft", key, true)) return KEY_ANALOG_LEFT;
  59.         else if(!strcmp("aright", key, true)) return KEY_ANALOG_RIGHT;
  60.         else if(!strcmp("yes", key, true)) return KEY_YES;
  61.         else if(!strcmp("no", key, true)) return KEY_NO;
  62.         else if(!strcmp("ctrlback", key, true)) return KEY_NO;
  63.         else if(!strcmp("up", key, true)) return KEY_UP;
  64.         else if(!strcmp("down", key, true)) return KEY_DOWN;
  65.         else if(!strcmp("left", key, true)) return KEY_LEFT;
  66.         else if(!strcmp("right", key, true)) return KEY_RIGHT;
  67.         else return false;
  68.     }
  69.     stock rand(one, two) {    
  70.         return random(two - one) + one;
  71.     }
  72.     stock GetPlayerSpeed(v) {
  73.         new Float: X, Float: Y, Float: Z;
  74.         GetVehicleVelocity(v, X, Y, Z);
  75.         return floatround(floatsqroot(floatpower(X, 2) + floatpower(Y, 2) + floatpower(Z, 2)) * 190);
  76.     }
  77.  
  78.     stock CreateVehicleEx(playerid, vehiclemodel, color1, color2) {
  79.         new Float: x, Float: y, Float: z;
  80.         new Float: facing;
  81.         new Float: distance;
  82.        
  83.         GetPlayerPos(playerid, x, y, z);
  84.         GetPlayerFacingAngle(playerid, facing);
  85.        
  86.         new Float: size_x, Float: size_y, Float: size_z;
  87.         GetVehicleModelInfo(vehiclemodel, VEHICLE_MODEL_INFO_SIZE, size_x, size_y, size_z);
  88.        
  89.         distance = size_x + 0.5;
  90.        
  91.         x += (distance * floatsin(- facing, degrees));
  92.         y += (distance * floatcos(- facing, degrees));
  93.        
  94.         facing += 90.0;
  95.         if(facing > 360.0) facing -= 360.0;
  96.        
  97.         return CreateVehicle(vehiclemodel, x, y, z + (size_z * 0.25), facing, color1, color2, -1);
  98.     }
  99.     stock GetVehicleName(vehicleid) {
  100.         static String[30];
  101.         format(String,sizeof(String),"%s",VehicleCmdNames[GetVehicleModel(vehicleid) - 400][1]);
  102.         return String;
  103.     }
  104.  
  105. // Funkcje publiczne:
  106.     main();
  107.    
  108.     public OnGameModeInit() {
  109.         new OGMI = 0;
  110.         while(OGMI++ <= 299) {
  111.             AddPlayerClass(OGMI, 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0);
  112.         }
  113.         SetModeRestartTime(0.1);
  114.         printf("Random między liczbami %d a %d to: %d", 5, 10, rand(5, 10));
  115.         return true;
  116.     }
  117.    
  118.     public OnPlayerConnect(playerid) {
  119.         UpdateSpeed[playerid] = false;
  120.         return true;
  121.     }
  122.  
  123.     public OnPlayerDisconnect(playerid, reason) {
  124.         if(!IsPlayerConnected(playerid)) return DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]);
  125.         return true;
  126.     }
  127.  
  128.     public OnPlayerUpdate(playerid) {
  129.         if(UpdateSpeed[playerid]) {
  130.             new str[MAX_PLAYERS][128];
  131.             format(str[playerid], sizeof(str), "[%s]\n%d km/h", GetVehicleName(GetPlayerVehicleID(playerid)), GetPlayerSpeed(GetPlayerVehicleID(playerid)));
  132.             UpdatePlayer3DTextLabelText(playerid, Speed3DText[playerid], -1, str[playerid]);
  133.         }
  134.     }
  135.  
  136.     public OnPlayerStateChange(playerid, newstate, oldstate) {
  137.         switch(newstate) {case PLAYER_STATE_DRIVER: {
  138.             Speed3DText[playerid] = CreatePlayer3DTextLabel(playerid, "Infernus\n666 KM/H", -1, 0, 0, 0, 15.0, INVALID_PLAYER_ID, GetPlayerVehicleID(playerid), 1);
  139.             UpdateSpeed[playerid] = true;
  140.         }}
  141.         switch(oldstate) {case PLAYER_STATE_DRIVER: {
  142.             DeletePlayer3DTextLabel(playerid, Speed3DText[playerid]);
  143.             UpdateSpeed[playerid] = false;
  144.         }}
  145.         return true;
  146.     }
  147.  
  148.     public OnPlayerCommandReceived(playerid, cmdtext[]) {
  149.         new
  150.             vid[MAX_PLAYERS],
  151.             string[MAX_PLAYERS][64];
  152.        
  153.         while(i__[playerid]++ < sizeof(VehicleCmdNames)) {
  154.             if(strfind(VehicleCmdNames[i__[playerid]], cmdtext, true) != -1) {
  155.                 if(!IsPlayerAdmin(playerid)) {
  156.                     switch(i__[playerid] + 400) {case 425, 432, 441, 406, 449, 464, 465, 501, 520, 537, 538, 564, 569, 570, 590, 591, 594, 606 .. 608, 610, 611: return SendClientMessage(playerid, -1, "Tego pojazdu nie możesz stworzyć nie będąc administratorem!");}
  157.                 }
  158.                 vid[playerid] = CreateVehicleEx(playerid, i__[playerid] + 400, -1, -1);
  159.                 LinkVehicleToInterior(vid[playerid], GetPlayerInterior(playerid));
  160.                 SetVehicleVirtualWorld(vid[playerid], GetPlayerVirtualWorld(playerid));
  161.                 format(string[playerid], sizeof(string), "Tworzysz %s", VehicleCmdNames[i__[playerid]]);
  162.                 printf(string[playerid]);
  163.                 PutPlayerInVehicle(playerid, vid[playerid], 0);
  164.                 return false;
  165.             }
  166.         }
  167.         return true;
  168.     }
  169.    
  170.     public OnGameModeExit() {
  171.         new OGME = 0;
  172.         while(OGME++ < MAX_PLAYERS) {
  173.             TextDrawDestroy(km[OGME]);
  174.         }
  175.         return true;
  176.     }
  177.  
  178.     public OnPlayerSpawn(playerid) {
  179.         SetPlayerPos(playerid, 0.0, 0.0, 0.0);
  180.         SetPlayerWorldBounds(playerid, 20000.0, -20000.0, 20000.0, -20000.0);
  181.         return 1;
  182.     }
  183.    
  184.     public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  185.         BindKey("submission") {
  186.             RepairVehicle(GetPlayerVehicleID(playerid));
  187.             GameTextForPlayer(playerid,"~y~Pojazd naprawiony!",2000,5);
  188.             PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
  189.         }
  190.         return false;
  191.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement