Advertisement
Shiny_

Untitled

Oct 2nd, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 15.71 KB | None | 0 0
  1. // Includes:
  2.     #include <a_samp>
  3.     #include <crashdetect>
  4.     #include <mapandreas>
  5.     #include <regex>
  6.     #include <sscanf2>
  7.     #include <YSF>
  8.     #include <YSI\y_ini>
  9.     #include <YSI\y_iterate>
  10.     #include <zcmd>
  11.  
  12.     native WP_Hash(buffer[], len, const str[]);
  13.  
  14. // Macros:
  15.     #undef INI_String
  16.     #if defined _inc_sscanf && 0
  17.         #define INI_String(%1,%2,%3)                \
  18.                 if(!strcmp((%1), name, false) && !sscanf(value, "s["#%3"]", %2)) return;
  19.     #else
  20.         #define INI_String(%1,%2,%3)                \
  21.                 if(!strcmp((%1), name, false)) return strcpy(%2, value, %3)
  22.     #endif
  23.     // #define INI_String(%1,%2,%3) if(!strcmp((%1),name,false) && !sscanf(value,"s["#%3"]",%2)) return;
  24.     #define function%0(%1)                          \
  25.             forward %0(%1);                         \
  26.             public %0(%1)
  27.     #define Timer::
  28.    
  29.     #if !defined INTERPOLATIONTIME
  30.             #define INTERPOLATIONTIME                                                               \
  31.                     16500
  32.     #endif
  33.     #define PATH                                    \
  34.             "/Users/%s.ini"
  35.    
  36.     enum {
  37.         DIALOG_REG = 50,
  38.         DIALOG_LOGIN,
  39.         DIALOG_SUCC,
  40.     };
  41.    
  42.     enum pInfo {
  43.         pCash,
  44.         pAdmin,
  45.         pKills,
  46.         pDeaths,
  47.         pPass[129],
  48.     };
  49.    
  50. // Variables:
  51.     new vehicle;
  52.     new STR_[128];
  53.     new STR_2[128];
  54.     new text_[100];
  55.     new Float: Position[4];
  56.     new Name[MAX_PLAYER_NAME];
  57.     new RegEx: AntiAdvertisement;
  58.     new bool: Commanded[MAX_VEHICLES];
  59.     new PlayerInfo[MAX_PLAYERS][pInfo];
  60.     new Set_CameraPos_Timer[MAX_PLAYERS];
  61.     new PlayerText3D: Time3DText[MAX_PLAYERS];
  62.     new gVehicleNames[212][] = {
  63.         "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perennial", "Sentinel", "Dumper",
  64.         "Firetruck", "Trashmaster", "Stretch", "Manana", "Infernus", "Voodoo", "Pony", "Mule",
  65.         "Cheetah", "Ambulance", "Leviathan", "Moonbeam", "Esperanto", "Taxi", "Washington",
  66.         "Bobcat", "Mr Whoopee", "BF Injection", "Hunter", "Premier", "Enforcer", "Securicar",
  67.         "Banshee", "Predator", "Bus", "Rhino", "Barracks", "Hotknife", "Trailer 1", "Previon",
  68.         "Coach", "Cabbie", "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster",
  69.         "Admiral", "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer 2", "Turismo",
  70.         "Speeder", "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van",
  71.         "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale", "Oceanic",
  72.         "Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy", "Hermes", "Sabre",
  73.         "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX", "Burrito", "Camper", "Marquis",
  74.         "Baggage", "Dozer", "Maverick", "News Chopper", "Rancher", "FBI Rancher", "Virgo", "Greenwood",
  75.         "Jetmax", "Hotring", "Sandking", "Blista Compact", "Police Maverick", "Boxville", "Benson",
  76.         "Mesa", "RC Goblin", "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher",
  77.         "Super GT", "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropdust", "Stunt",
  78.         "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra", "FCR-900",
  79.         "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune", "Cadrona", "FBI Truck",
  80.         "Willard", "Forklift", "Tractor", "Combine", "Feltzer", "Remington", "Slamvan",
  81.         "Blade", "Freight", "Streak", "Vortex", "Vincent", "Bullet", "Clover", "Sadler",
  82.         "Firetruck LA", "Hustler", "Intruder", "Primo", "Cargobob", "Tampa", "Sunrise", "Merit",
  83.         "Utility", "Nevada", "Yosemite", "Windsor", "Monster A", "Monster B", "Uranus", "Jester",
  84.         "Sultan", "Stratum", "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna",
  85.         "Bandito", "Freight Flat", "Streak Carriage", "Kart", "Mower", "Duneride", "Sweeper",
  86.         "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400", "Newsvan",
  87.         "Tug", "Trailer 3", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club", "Freight Carriage",
  88.         "Trailer 3", "Andromada", "Dodo", "RC Cam", "Launch", "Police Car (LSPD)", "Police Car (SFPD)",
  89.         "Police Car (LVPD)", "Police Ranger", "Picador", "S.W.A.T. Van", "Alpha", "Phoenix", "Glendale",
  90.         "Sadler", "Luggage Trailer A", "Luggage Trailer B", "Stair Trailer", "Boxville", "Farm Plow",
  91.         "Utility Trailer"
  92.     };
  93.    
  94. // Static functions:
  95.     stock RespawnUnusedVehicles() {
  96.         new UsedVeh[MAX_VEHICLES] = {false, ...};
  97.         foreach(new playerid: Player) {
  98.             UsedVeh[GetPlayerVehicleID(playerid)] = true;
  99.         }
  100.        
  101.         for(new vehicleid = 1; vehicleid != MAX_VEHICLES; vehicleid++) {
  102.             if(UsedVeh[vehicleid]) continue;
  103.             if(Commanded[vehicleid]) {
  104.                 DestroyVehicle(vehicleid);
  105.                 Commanded[vehicleid] = false;
  106.             }
  107.             SetVehicleToRespawn(vehicleid);
  108.         }
  109.         return true;
  110.     }
  111.  
  112.     stock CreatePlayerVehicle(playerid, modelid) {
  113.         if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
  114.             vehicle = GetPlayerVehicleID(playerid);
  115.             GetVehiclePos(vehicle, Position[0], Position[1], Position[2]);
  116.             GetVehicleZAngle(vehicle, Position[3]);
  117.             DestroyVehicle(vehicle);
  118.         } else {
  119.             GetPlayerPos(playerid, Position[0], Position[1], Position[2]);
  120.             GetPlayerFacingAngle(playerid, Position[3]);
  121.         }
  122.         vehicle = AddStaticVehicle(modelid, Position[0], Position[1], Position[2] + 1, Position[3], -1, -1);
  123.         LinkVehicleToInterior(vehicle, GetPlayerInterior(playerid));
  124.         SetVehicleVirtualWorld(vehicle, GetPlayerVirtualWorld(playerid));
  125.         SetVehicleNumberPlate(vehicle, PlayerName(playerid));
  126.         PutPlayerInVehicle(playerid, vehicle, 0);
  127.         Commanded[vehicle] = true;
  128.         return true;
  129.     }
  130.    
  131.     stock GetVehicleModelIDByName(vehiclename[]) {
  132.         for(new i = 0; i < 211; i++) {
  133.             if(strfind(gVehicleNames[i], vehiclename, true) != -1) return i + 400;
  134.         }
  135.         return -1;
  136.     }
  137.    
  138.     stock delete_free_space(string[], character = ' ') {
  139.         new len = strlen(string);
  140.         if(len) {
  141.             new begin = -1, end = len;
  142.             while(string[++begin] == character) {}
  143.             if(string[begin] == EOS) {
  144.                 string[0] = false;
  145.                 return true;
  146.             }
  147.             while(string[--end] == character) {}
  148.             strmid(string, string, begin, end + 1, len + 1);
  149.         }
  150.         return true;
  151.     }
  152.    
  153.     stock PlayerName(playerid) {
  154.         GetPlayerName(playerid, Name, sizeof(Name));
  155.         return Name;
  156.     }
  157.    
  158.     stock Path(playerid) {
  159.         new STR[128];
  160.         format(STR, sizeof(STR), PATH, PlayerName(playerid));
  161.         return STR;
  162.     }
  163.    
  164. // Dynamic functions:  
  165.     function RespawnVehicles(vehicleid) {
  166.         RespawnUnusedVehicles();
  167.         SendClientMessageToAll(-1, "Auta stworzone za pomocą komendy /v zostały usunięte!");
  168.         return true;
  169.     }
  170.    
  171.     function Time(playerid) {
  172.         new time[3];
  173.         new string__[128];
  174.         gettime(time[0], time[1], time[2]);
  175.         format(string__, sizeof(string__), "[%02d:%02d:%02d]", time[0], time[1], time[2]);
  176.         UpdatePlayer3DTextLabelText(playerid, Time3DText[playerid], -1, string__);
  177.         return true;
  178.     }
  179.    
  180.     function SetCameraPosEx(playerid) {
  181.         SetPlayerInterior(playerid, 0);
  182.         SetPlayerFacingAngle(playerid, 90.0);
  183.         SetPlayerPos(playerid, -1399.0179, 2640.7385, 55.6875);
  184.         SetPlayerCameraPos(playerid, -1410.462402, 2640.7385, 55.6875);
  185.         SetPlayerCameraLookAt(playerid, -1410.462402, 2640.7385, 55.6875, CAMERA_CUT);
  186.         ApplyAnimation(playerid, "RAPPING", "RAP_B_Loop", 4.0, 1, 0, 0, 0, 0);
  187.     }
  188.    
  189.     function Load_User_Data(playerid, name[], value[]) {
  190.         INI_Int("Cash", PlayerInfo[playerid][pCash]);
  191.         INI_Int("Admin", PlayerInfo[playerid][pAdmin]);
  192.         INI_Int("Kills", PlayerInfo[playerid][pKills]);
  193.         INI_Int("Deaths", PlayerInfo[playerid][pDeaths]);
  194.         INI_String("Password", PlayerInfo[playerid][pPass], 129);
  195.         return true;
  196.     }
  197.    
  198. // Public functions:
  199.     main() {
  200.         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");
  201.         printf(regex_isvalid(AntiAdvertisement)? ("Kod regex antyreklamy jest poprawny!"): ("Kod regex antyreklamy jest niepoprawny!"));
  202.         SetTimer("RespawnVehicles", 15 * 60 * 1000, true);
  203.         SetModeRestartTime(0.1);
  204.         return false;
  205.     }
  206.    
  207.     public OnPlayerConnect(playerid) {
  208.         PlayAudioStreamForPlayer(playerid, "http://alldev.eu/mp3/sleepwalking.mp3");
  209.        
  210.         InterpolateCameraPos(playerid, -2662.6853, 1933.7972, 225.7578, -1409.489868, 2642.814697, 58.506492, INTERPOLATIONTIME, CAMERA_MOVE);
  211.         InterpolateCameraLookAt(playerid, -2662.6853, 1933.7972, 225.7578, -1404.622924, 2642.720458, 57.364322, INTERPOLATIONTIME, CAMERA_MOVE);
  212.  
  213.         ApplyAnimation(playerid, "RAPPING", "RAP_B_Loop", 4.0, 1, 0, 0, 0, 0);
  214.         Set_CameraPos_Timer[playerid] = SetTimerEx("SetCameraPosEx", INTERPOLATIONTIME, false, "d", playerid);
  215.        
  216.         SetTimerEx("Time", 999, true, "d", playerid);
  217.         SendDeathMessage(INVALID_PLAYER_ID, playerid, 200);
  218.         SendClientMessage(playerid, -1, "W każdej chwili możesz zalogować się lub zarejestrować. Wystarczy, że wpiszesz /zaloguj bądź /zarejestruj.");
  219.         return true;
  220.     }
  221.    
  222.     public OnPlayerSpawn(playerid) {
  223.         KillTimer(Set_CameraPos_Timer[playerid]);
  224.         SetCameraBehindPlayer(playerid);
  225.         StopAudioStreamForPlayer(playerid);
  226.         SetPlayerFacingAngle(playerid, 90.0);
  227.         SetPlayerPos(playerid, -1399.0179, 2640.7385, 55.6875);
  228.         SetPlayerWorldBounds(playerid, 20000.0000, -20000.0000, 20000.0000, -20000.0000);
  229.         return true;
  230.     }
  231.    
  232.     public OnPlayerText(playerid, text[]) {
  233.         new MSG_EX[180];
  234.         new STRING[180];
  235.         format(MSG_EX, sizeof(MSG_EX), "%s próbuje reklamować.", PlayerName(playerid));
  236.         regex_replace_exid(text, AntiAdvertisement, MSG_EX, STRING);
  237.        
  238.         format(STRING, sizeof(STRING), "(ID: %d): %s", playerid, text);
  239.         SendPlayerMessageToAll(playerid, STRING);
  240.         printf("%s: %s", PlayerName(playerid), text);
  241.         return false;
  242.        
  243.         // Kolory:
  244.         // - zielony: #339933
  245.         // - pomarańczowy: #FF5917
  246.         // - bordowy: #BB0000
  247.     }
  248.    
  249.     public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  250.         format(STR_, sizeof(STR_), "Witaj z powrotem %s.\nMasz już konto na tym serwerze, więc pozostaje Ci tylko wpisanie hasła w polu poniżej.", PlayerName(playerid));
  251.         format(STR_2, sizeof(STR_2), "Witaj %s.\nNie masz konta na tym serwerze, więc musisz wpisać hasło w polu poniżej aby kontynuować grę.", PlayerName(playerid));
  252.         switch(dialogid) {
  253.             case DIALOG_REG: {
  254.                 switch(response) {
  255.                     case 0: Kick(playerid);
  256.                     case 1: {
  257.                         new HashPass[129];
  258.                         new INI: File_;
  259.                         WP_Hash(HashPass, sizeof(HashPass), inputtext);
  260.                         File_ = INI_Open(Path(playerid));
  261.                         INI_SetTag(File_, "Dane Graczy");
  262.                         INI_WriteInt(File_, "Cash", 0);
  263.                         INI_WriteInt(File_, "Admin", 0);
  264.                         INI_WriteInt(File_, "Kills", 0);
  265.                         INI_WriteInt(File_, "Deaths", 0);
  266.                         INI_WriteString(File_, "Password", HashPass);
  267.                         INI_Close(File_);
  268.                         if(!strlen(inputtext)) {
  269.                             return ShowPlayerDialog(playerid, DIALOG_REG, DIALOG_STYLE_PASSWORD, "Rejestracja", STR_2, "Zarejestruj", "Wyjdź");
  270.                         }
  271.                     }
  272.                 }
  273.             }
  274.             case DIALOG_LOGIN: {
  275.                 switch(response) {
  276.                     case 0: Kick(playerid);
  277.                     case 1: {
  278.                         new HashPass[129];
  279.                         WP_Hash(HashPass, sizeof(HashPass), inputtext);
  280.                         if(!strcmp(HashPass, PlayerInfo[playerid][pPass], false)) {
  281.                             GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
  282.                             INI_ParseFile(Path(playerid), "Load_User_%s", .bExtra = true, .extra = playerid);
  283.                             SendClientMessage(playerid, -1, "Zalogowano poprawnie.");
  284.                         } else {
  285.                             return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Logowanie", STR_, "Zaloguj", "Wyjdź");
  286.                         }
  287.                     }
  288.                 }
  289.             }
  290.         }
  291.         return true;
  292.     }
  293.    
  294.     public OnPlayerCommandPerformed(playerid, cmdtext[], success) {
  295.         if(!success) {
  296.             if(strlen(cmdtext) > 2) {
  297.                 strdel(cmdtext, 0, 1);
  298.                 for(new i = 400; i <= 611; i++) {
  299.                     if(strfind(gVehicleNames[i - 400], cmdtext, true) != -1) {
  300.                         CreatePlayerVehicle(playerid, i);
  301.                         format(text_, sizeof(text_), "Pojazd o nazwie {FF0000}%s{FFFFFF} zostaje utworzony.", gVehicleNames[i - 400]);
  302.                         SendClientMessage(playerid, -1, text_);
  303.                         return true;
  304.                     }
  305.                 }
  306.             }
  307.             format(text_, sizeof(text_), "Na serwerze nie ma takiej komendy jak /%s!", cmdtext);
  308.             SendClientMessage(playerid, -1, text_);
  309.             printf("%s wpisuje komendę: /%s", PlayerName(playerid), cmdtext);
  310.         }
  311.         return true;
  312.     }
  313.    
  314.     public OnPlayerStateChange(playerid, newstate, oldstate) {
  315.         format(text_, sizeof(text_), "%s", Time(playerid));
  316.         switch(newstate) {case PLAYER_STATE_DRIVER: Time3DText[playerid] = CreatePlayer3DTextLabel(playerid, text_, -1, 0, 0, 0, 15.0, INVALID_PLAYER_ID, GetPlayerVehicleID(playerid), 1);}
  317.         switch(oldstate) {case PLAYER_STATE_DRIVER: DeletePlayer3DTextLabel(playerid, Time3DText[playerid]);}
  318.         return true;
  319.     }
  320.    
  321.     public OnPlayerDeath(playerid, killerid, reason) {
  322.         SendDeathMessage(killerid, playerid, reason);
  323.         PlayerInfo[killerid][pKills]++;
  324.         PlayerInfo[playerid][pDeaths]++;
  325.         SetPlayerAmmo(playerid, 223, 0);
  326.         return true;
  327.     }
  328.  
  329.     public OnPlayerDisconnect(playerid, reason) {
  330.         new INI: File_;
  331.         File_ = INI_Open(Path(playerid));
  332.         if(!IsPlayerConnected(playerid)) {
  333.             DeletePlayer3DTextLabel(playerid, Time3DText[playerid]), KillTimer(Set_CameraPos_Timer[playerid]);
  334.             INI_SetTag(File_, "Dane Graczy");
  335.             INI_WriteInt(File_, "Cash", 0);
  336.             INI_WriteInt(File_, "Admin", 0);
  337.             INI_WriteInt(File_, "Kills", 0);
  338.             INI_WriteInt(File_, "Deaths", 0);
  339.             INI_Close(File_);
  340.         }
  341.         SendDeathMessage(INVALID_PLAYER_ID, playerid, 201);
  342.         return true;
  343.     }
  344.    
  345.     public OnGameModeExit() {
  346.         return regex_delete(AntiAdvertisement) && true;
  347.     }
  348.    
  349. // Commands:
  350.     CMD:zaloguj(playerid) {
  351.         format(STR_, sizeof(STR_), "Witaj z powrotem %s.\nMasz już konto na tym serwerze, więc pozostaje Ci tylko wpisanie hasła w polu poniżej.", PlayerName(playerid));
  352.         format(STR_2, sizeof(STR_2), "Witaj %s.\nNie masz konta na tym serwerze, więc musisz wpisać hasło w polu poniżej aby kontynuować grę.", PlayerName(playerid));
  353.         switch(fexist(Path(playerid))) {
  354.             case 0: ShowPlayerDialog(playerid, DIALOG_REG, DIALOG_STYLE_PASSWORD, "Rejestracja", STR_2, "Zarejestruj", "Wyjdź");
  355.             case 1: {
  356.                 INI_ParseFile(Path(playerid), "Load_User_%s", .bExtra = true, .extra = playerid);
  357.                 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Logowanie", STR_, "Zaloguj", "Wyjdź");
  358.             }
  359.         }
  360.         return true;
  361.     }
  362.    
  363.     CMD:zarejestruj(playerid) {
  364.         format(STR_, sizeof(STR_), "Witaj z powrotem %s.\nMasz już konto na tym serwerze, więc pozostaje Ci tylko wpisanie hasła w polu poniżej.", PlayerName(playerid));
  365.         format(STR_2, sizeof(STR_2), "Witaj %s.\nNie masz konta na tym serwerze, więc musisz wpisać hasło w polu poniżej aby kontynuować grę.", PlayerName(playerid));
  366.         switch(fexist(Path(playerid))) {
  367.             case 0: ShowPlayerDialog(playerid, DIALOG_REG, DIALOG_STYLE_PASSWORD, "Rejestracja", STR_2, "Zarejestruj", "Wyjdź");
  368.             case 1: {
  369.                 INI_ParseFile(Path(playerid), "Load_User_%s", .bExtra = true, .extra = playerid);
  370.                 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Logowanie", STR_, "Zaloguj", "Wyjdź");
  371.             }
  372.         }
  373.         return true;
  374.     }
  375.    
  376.     CMD:v(playerid, params[]) {
  377.         new GetVehicleModelVariable = GetVehicleModelIDByName(params);
  378.         delete_free_space(params);
  379.         if(isnull(params)) return SendClientMessage(playerid, -1, "Wpisz /v nazwa_pojazdu");
  380.         else if(GetVehicleModelVariable != -1) CreatePlayerVehicle(playerid, GetVehicleModelVariable), format(text_, sizeof(text_), "Pojazd o nazwie {FF0000}%s{FFFFFF} zostaje utworzony.", gVehicleNames[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400]), SendClientMessage(playerid, -1, text_);
  381.         else SendClientMessage(playerid, -1, "Zła nazwa pojazdu!");
  382.         return true;
  383.     }
  384.    
  385.     CMD:respawn(playerid) {
  386.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Tą komendę może wpisać tylko Administrator!");
  387.         RespawnUnusedVehicles();
  388.         return true;
  389.     }
  390.    
  391.     CMD:flip(playerid) {
  392.         new Float: x, Float: y, Float: z, Float: Angle;
  393.         if(IsPlayerInAnyVehicle(playerid)) {
  394.             GetPlayerPos(playerid, x, y, z);
  395.             GetVehicleZAngle(GetPlayerVehicleID(playerid), Angle);
  396.             SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z + 1);
  397.             SetVehicleZAngle(GetPlayerVehicleID(playerid), Angle);
  398.         }
  399.         return true;
  400.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement