Advertisement
Shiny_

Untitled

Sep 22nd, 2013
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.88 KB | None | 0 0
  1. // Includes:
  2.     #include <a_samp>
  3.     #include <crashdetect>
  4.     #include <regex>
  5.     #include <YSF>
  6.     #include <YSI\y_iterate>
  7.     #include <zcmd>
  8.  
  9. // Macros:
  10.     #define function%0(%1)                          \
  11.             forward %0(%1);                         \
  12.             public %0(%1)
  13.     #define Timer::
  14.    
  15. // Variables:
  16.     new vehicle;
  17.     new text_[100];
  18.     new Float: Position[4];
  19.     new Name[MAX_PLAYER_NAME];
  20.     new RegEx: AntiAdvertisement;
  21.     new bool: Commanded[MAX_VEHICLES];
  22.     new PlayerText3D: Time3DText[MAX_PLAYERS];
  23.     new Timer:: Set_CameraPos_Timer[MAX_PLAYERS];
  24.     new gVehicleNames[212][] = {
  25.         "Landstalker", "Bravura", "Buffalo", "Linerunner", "Pereniel", "Sentinel", "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana",
  26.         "Infernus", "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam", "Esperanto", "Taxi", "Washington", "Bobcat",
  27.         "Mr Whoopee", "BF Injection", "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus", "Rhino", "Barracks",
  28.         "Hotknife", "Trailer", "Previon", "Coach", "Cabbie", "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
  29.         "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder", "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy",
  30.         "Solair", "Berkley's RC Van", "Skimmer", "PCJ-600", "Faggio", "Harley", "RC Baron", "RC Raider", "Glendale", "Oceanic",
  31.         "Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy", "Hermes", "Sabre", "Rustler", "ZR3 50", "Walton", "Regina",
  32.         "Comet", "BMX", "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper", "Rancher", "FBI Rancher",
  33.         "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking", "Blista Compact", "Police Maverick", "Boxville", "Benson", "Mesa",
  34.         "RC Goblin", "Hotring Racer", "Hotring Racer", "Bloodring Banger", "Rancher", "Super GT", "Elegant", "Journey", "Bike",
  35.         "Mountain Bike", "Beagle", "Cropdust", "Stunt", "Tanker", "RoadTrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
  36.         "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune", "Cadrona", "FBI Truck", "Willard", "Forklift", "Traktor",
  37.         "Combine", "Feltzer", "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent", "Bullet", "Clover", "Sadler",
  38.         "Firetruck", "Hustler", "Intruder", "Primo", "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite", "Windsor",
  39.         "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratum", "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna",
  40.         "Bandito", "Freight", "Trailer", "Kart", "Mower", "Duneride", "Sweeper", "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley",
  41.         "Stafford", "BF-400", "Newsvan", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club", "Trailer", "Trailer",
  42.         "Andromeda", "Dodo", "RC Cam", "Launch", "Radiowoz", "Radiowoz", "Radiowoz", "Radiowoz", "Picador", "S.W.A.T. Van",
  43.         "Alpha", "Phoenix", "Glendale", "Sadler", "Luggage Trailer", "Luggage Trailer", "Stair Trailer", "Boxville", "Farm Plow", "Utility Trailer"
  44.     };
  45.    
  46. // Static functions:
  47.     stock RespawnUnusedVehicles() {
  48.         new UsedVeh[MAX_VEHICLES] = {false, ...};
  49.         foreach(new playerid: Player) {
  50.             UsedVeh[GetPlayerVehicleID(playerid)] = true;
  51.         }
  52.        
  53.         for(new vehicleid = 1; vehicleid != MAX_VEHICLES; vehicleid++) {
  54.             if(UsedVeh[vehicleid]) continue;
  55.             else if(Commanded[vehicleid]) return DestroyVehicle(vehicleid), Commanded[vehicleid] = false;
  56.             SetVehicleToRespawn(vehicleid);
  57.         }
  58.         return true;
  59.     }
  60.  
  61.     stock CreatePlayerVehicle(playerid, modelid) {
  62.         if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
  63.             vehicle = GetPlayerVehicleID(playerid);
  64.             GetVehiclePos(vehicle, Position[0], Position[1], Position[2]);
  65.             GetVehicleZAngle(vehicle, Position[3]);
  66.             DestroyVehicle(vehicle);
  67.         } else {
  68.             GetPlayerPos(playerid, Position[0], Position[1], Position[2]);
  69.             GetPlayerFacingAngle(playerid, Position[3]);
  70.         }
  71.         vehicle = AddStaticVehicle(modelid, Position[0], Position[1], Position[2] + 1, Position[3], -1, -1);
  72.         LinkVehicleToInterior(vehicle, GetPlayerInterior(playerid));
  73.         SetVehicleVirtualWorld(vehicle, GetPlayerVirtualWorld(playerid));
  74.         SetVehicleNumberPlate(vehicle, PlayerName(playerid));
  75.         PutPlayerInVehicle(playerid, vehicle, 0);
  76.         Commanded[vehicle] = true;
  77.         return true;
  78.     }
  79.    
  80.     stock GetVehicleModelIDByName(vehiclename[]) {
  81.         for(new i = 0; i < 211; i++) {
  82.             if(strfind(gVehicleNames[i], vehiclename, true) != -1) return i + 400;
  83.         }
  84.         return -1;
  85.     }
  86.    
  87.     stock delete_free_space(string[], character = ' ') {
  88.         new len = strlen(string);
  89.         if(len) {
  90.             new begin = -1, end = len;
  91.             while(string[++begin] == character) {}
  92.             if(string[begin] == EOS) {
  93.                 string[0] = false;
  94.                 return true;
  95.             }
  96.             while(string[--end] == character) {}
  97.             strmid(string, string, begin, end + 1, len + 1);
  98.         }
  99.         return true;
  100.     }
  101.    
  102.     stock PlayerName(playerid) {
  103.         GetPlayerName(playerid, Name, sizeof(Name));
  104.         return Name;
  105.     }
  106.    
  107. // Dynamic functions:  
  108.     function RespawnVehicles(vehicleid) {
  109.         RespawnUnusedVehicles();
  110.         SendClientMessageToAll(-1, "Auta stworzone za pomocą komendy /v zostały usunięte!");
  111.         return true;
  112.     }
  113.    
  114.     function Time(playerid) {
  115.         new time[3];
  116.         new string__[128];
  117.         gettime(time[0], time[1], time[2]);
  118.         format(string__, sizeof(string__), "[%02d:%02d:%02d]", time[0], time[1], time[2]);
  119.         UpdatePlayer3DTextLabelText(playerid, Time3DText[playerid], -1, string__);
  120.         return true;
  121.     }
  122.    
  123.     function Set_CameraPos(playerid) {
  124.         SetPlayerCameraPos(playerid, -1410.462402, 2639.478271, 55.434036);
  125.         SetPlayerCameraLookAt(playerid, -1405.579956, 2639.294677, 56.371879);
  126.         SetPlayerPos(playerid, -1399.0179, 2640.7385, 55.6875);
  127.         SetPlayerFacingAngle(playerid, 90.0);
  128.     }
  129.    
  130. // Public functions:
  131.     main() {
  132.         AntiAdvertisement = regex_build("\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)+([(/|,.)?\\s]{1,})+(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)+([(/|,.)?\\s]{1,})+(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)+([(/|,.)?\\s]{1,})+(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b");
  133.         printf(regex_isvalid(AntiAdvertisement)? ("Kod regex antyreklamy jest poprawny!"): ("Kod regex antyreklamy jest niepoprawny!"));
  134.         SetTimer("RespawnVehicles", 15 * 60 * 1000, true);
  135.         SetModeRestartTime(0.1);
  136.         return false;
  137.     }
  138.    
  139.     public OnGameModeInit() {
  140.         for(new i; i <= 299; i++) {
  141.             AddPlayerClass(i, -1399.0179, 2640.7385, 55.6875, 0.0, 0, 0, 0, 0, 0, 0);
  142.         }
  143.         return true;
  144.     }
  145.    
  146.     public OnPlayerConnect(playerid) {
  147.         PlayAudioStreamForPlayer(playerid, "http://alldev.eu/mp3/april_showers.mp3");
  148.                
  149.         InterpolateCameraPos(playerid, -1635.208984, 2274.272460, 101.468925, -1428.462402, 2642.478271, 66.434036, 9000);
  150.         InterpolateCameraLookAt(playerid, -1633.167846, 2278.822753, 101.109863, -1423.579956, 2642.294677, 65.371879, 8000);
  151.        
  152.         ApplyAnimation(playerid, "RAPPING", "RAP_B_Loop", 4.0, 1, 0, 0, 0, 0);
  153.         Set_CameraPos_Timer[playerid] = SetTimerEx("Set_CameraPos", 9000, true, "d", playerid);
  154.         SetTimerEx("Time", 999, true, "d", playerid);
  155.         return true;
  156.     }
  157.    
  158.     public OnPlayerRequestClass(playerid, classid) {
  159.         switch(GetPVarInt(playerid, "Dance")) {
  160.             /*case 0: ApplyAnimation(playerid, "DANCING", "DAN_Down_A", 4.000000, 1, 1, 1, 1, 1);
  161.             case 1: ApplyAnimation(playerid, "DANCING", "DAN_Left_A", 4.000000, 1, 1, 1, 1, 1);
  162.             case 2: ApplyAnimation(playerid, "DANCING", "DAN_Right_A", 4.000000, 1, 1, 1, 1, 1);
  163.             case 3: ApplyAnimation(playerid, "DANCING", "DAN_Up_A", 4.000000, 1, 1, 1, 1, 1);
  164.             case 4: ApplyAnimation(playerid, "DANCING", "dnce_M_a", 4.000000, 1, 1, 1, 1, 1);
  165.             case 5: ApplyAnimation(playerid, "RAPPING", "Laugh_01", 4.0, 1, 0, 0, 0, 0);
  166.             case 6: ApplyAnimation(playerid, "RAPPING", "RAP_B_Loop", 4.0, 1, 0, 0, 0, 0);
  167.             case 7: ApplyAnimation(playerid, "DANCING", "DAN_Right_A", 4.000000, 1, 1, 1, 1, 1);*/
  168.             case 0: ApplyAnimation(playerid, "DANCING", "dnce_M_a", 4.1, 1, 1, 1, 1, 1, 1);
  169.             case 1: ApplyAnimation(playerid, "DANCING", "dnce_M_b", 4.1, 1, 1, 1, 1, 1, 1);
  170.             case 2: ApplyAnimation(playerid, "DANCING", "dnce_M_c", 4.1, 1, 1, 1, 1, 1, 1);
  171.             case 3: ApplyAnimation(playerid, "DANCING", "dnce_M_d", 4.1, 1, 1, 1, 1, 1, 1);
  172.             case 4: ApplyAnimation(playerid, "DANCING", "dnce_M_e", 4.1, 1, 1, 1, 1, 1, 1);
  173.         }
  174.         SetPVarInt(playerid, "Dance", GetPVarInt(playerid, "Dance") < /*7*/ 4? GetPVarInt(playerid, "Dance") + 1: 0);
  175.         return true;
  176.     }
  177.  
  178.     public OnPlayerSpawn(playerid) {
  179.         KillTimer(Set_CameraPos_Timer[playerid]);
  180.         SetCameraBehindPlayer(playerid);
  181.         StopAudioStreamForPlayer(playerid);
  182.         SetPlayerFacingAngle(playerid, 90.0);
  183.         SetPlayerPos(playerid, -1399.0179, 2640.7385, 55.6875);
  184.         SetPlayerWorldBounds(playerid, 20000.0000, -20000.0000, 20000.0000, -20000.0000);
  185.         return true;
  186.     }
  187.    
  188.     public OnPlayerText(playerid, text[]) {
  189.         new MSG[180];
  190.         new MSG_EX[180];
  191.         format(MSG_EX, sizeof(MSG_EX), "%s próbuje reklamować.", PlayerName(playerid));
  192.         regex_replace_exid(text, AntiAdvertisement, MSG_EX, MSG);
  193.         SendPlayerMessageToAll(playerid, MSG);
  194.         return false;
  195.     }
  196.    
  197.     public OnPlayerCommandPerformed(playerid, cmdtext[], success) {
  198.         if(!success) {
  199.             for(new i; i < sizeof(gVehicleNames); i++) {
  200.                 if(strlen(cmdtext) > 2 && !strcmp(cmdtext[1], gVehicleNames[i], true)) {
  201.                     delete_free_space(cmdtext);
  202.                     CreatePlayerVehicle(playerid, i + 400);
  203.                     format(text_, sizeof(text_), "Pojazd o nazwie {FF0000}%s{FFFFFF} zostaje utworzony.", gVehicleNames[i]);
  204.                     SendClientMessage(playerid, -1, text_);
  205.                     return true;
  206.                 }
  207.             }
  208.         }
  209.         format(text_, sizeof(text_), "Na serwerze nie ma takiej komendy jak %s!", cmdtext);
  210.         SendClientMessage(playerid, -1, text_);
  211.         printf("%s wpisuje komendę: %s", PlayerName(playerid), cmdtext);
  212.         return true;
  213.     }
  214.    
  215.     public OnPlayerStateChange(playerid, newstate, oldstate) {
  216.         format(text_, sizeof(text_), "%s", Time(playerid));
  217.         switch(newstate) {case PLAYER_STATE_DRIVER: Time3DText[playerid] = CreatePlayer3DTextLabel(playerid, text_, -1, 0, 0, 0, 15.0, INVALID_PLAYER_ID, GetPlayerVehicleID(playerid), 1);}
  218.         switch(oldstate) {case PLAYER_STATE_DRIVER: DeletePlayer3DTextLabel(playerid, Time3DText[playerid]);}
  219.         return true;
  220.     }
  221.    
  222.     public OnPlayerDisconnect(playerid, reason) {
  223.         if(!IsPlayerConnected(playerid)) return DeletePlayer3DTextLabel(playerid, Time3DText[playerid]), KillTimer(Set_CameraPos_Timer[playerid]);
  224.         return true;
  225.     }
  226.    
  227.     public OnGameModeExit() {
  228.         return regex_delete(AntiAdvertisement) && true;
  229.     }
  230.    
  231. // Commands:
  232.     CMD:v(playerid, params[]) {
  233.         delete_free_space(params);
  234.         if(isnull(params)) return SendClientMessage(playerid, -1, "Wpisz /v nazwa_pojazdu");
  235.         else if(GetVehicleModelIDByName(params) != -1) CreatePlayerVehicle(playerid, GetVehicleModelIDByName(params));
  236.         else return SendClientMessage(playerid, -1, "Zła nazwa pojazdu!");
  237.         return true;
  238.     }
  239.    
  240.     CMD:respawn(playerid) {
  241.         (!IsPlayerAdmin(playerid)? SendClientMessage(playerid, -1, "Tą komendę może wpisać tylko Administrator!"): SendClientMessage(playerid, -1, "Auta stworzone za pomocą komendy /v zostały usunięte!"),
  242.         RespawnUnusedVehicles());
  243.         return true;
  244.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement