pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

cueballstopusingy-lesspastebinplease private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Cueball on Sun 18 May 04:26
report abuse | View followups from Anonymous | download | new post

  1. /*******************************************************************************************************
  2.  
  3.     Command Generator by ~Cueball~
  4.        A Guide For The Community
  5.    
  6.    Change The Following Five Defines
  7.  To Configure The Script To Your Needs
  8.    Read readme.html For Information
  9.    
  10. ******************************************************************************************************/
  11.  
  12. #define VehicleTele             1 // 1 = Allow vehicle teleports to be saved to a file, as well as used in saved commands.
  13. #define PrintInConsole          1 // 1 = Send a '[generator]' message to the console when a command is successfully generated.
  14. #define SendAdminMessage        1 // 1 = Send a message to all logged-in RCON admins when a command is successfully generated.
  15. #define SaveCommands        1 // 1 = Allow generated commands to be used immediately in the same session.
  16. #define SendTeleMessage     1 // 1 = Send a message stating the name of the command and its creator to the player when the command is used.
  17.  
  18. //******************************************************************************************************
  19.  
  20. #include <a_samp>                // Necessary include which holds all of SA-MP's native functions.
  21. #define FILTERSCRIPT     // This is a filterscript, so we define it as one.
  22. #if defined FILTERSCRIPT // If we have defined 'FILTERSCRIPT', do all the code until the first '#endif'.
  23.  
  24. //******************************************************************************************************
  25.  
  26. new File:GenCmds,   // Create a global file handle variable, so that we don't create alot of local variables which do the same thing.
  27.         CurrentCommand, // Create a global variable (integer), which holds the current command count.
  28.         string[500];    // Create a global variable (string), with a maximum length of 500 characters. Saves memory instead of creating strings after every '/cgen'.
  29.  
  30. //******************************************************************************************************
  31. // ARRAY CREATION - MAIN
  32. //******************************************************************************************************
  33.  
  34. #define MAX_COMMANDS            150 // The maximum amount of commands that can be used at one time. KEEP AROUND THIS VALUE TO SAVE MEMORY.
  35. #define MAX_COMMAND_NAME        15  // The maximum command name length you want your commands to be. '/cgen hello' = Command length of 5 characters.
  36.  
  37. enum COMMAND_MAIN { // Enumerating 'COMMAND_MAIN'.
  38.     NAME[MAX_COMMAND_NAME],   // A string with a maximum length of MAX_COMMAND_NAME characters.
  39.         CREATOR[MAX_PLAYER_NAME], // A string with a maximum length of MAX_PLAYER_NAME (24) characters.
  40.         Float:POS[4],             // 4 floats with a single name: 'POS'.
  41.         INTERIOR                  // An integer.
  42. }
  43.  
  44. new gCommands[MAX_COMMANDS][COMMAND_MAIN]; // Creating a global variable with MAX_COMMANDS ammount of cells, and each set of cells holding our 'COMMAND_MAIN' enumeration.
  45.  
  46. //******************************************************************************************************
  47. // ARRAY CREATION - INVALID NAMES
  48. //******************************************************************************************************
  49.  
  50. #define MAX_INVALID_COMMANDS    21 // The amount of invalid command names you have. Must be an exact value, or else you will recieve errors.
  51. #define MAX_INVALID_NAME        9  // The maximum invalid command name length you have. Remember to add an extra value for the trailing 0. 'cmd' = 3 + 1.
  52.  
  53. new gInvalidCommands[MAX_INVALID_COMMANDS][MAX_INVALID_NAME] = { // Add all your invalid command names here (but remember to change the value of 'MAX_INVALID_COMMANDS' when you are finished.
  54.         "rules", "commands", "cmds", "cmd", "register", "login", "logout", "signup",
  55.         "signin", "signout", "admins", "kick", "ban", "wire", "unwire", "mute", "unmute",
  56.         "explode", "goto", "gethere", "tele"
  57. };
  58.  
  59. //******************************************************************************************************
  60. // CALLBACKS
  61. //******************************************************************************************************
  62.  
  63. public OnFilterScriptInit()
  64. {
  65.         print("\n****************************************"); // Give credit to the creator of the script.
  66.     print("*    Command_Generator by ~Cueball~    *");
  67.     print("****************************************\n");
  68.    
  69.         if(!fexist("Generated_Commands.txt")) // Check if 'Generated_Commands.txt' exists in the 'scriptfiles' folder. If it doesn't, do the following:
  70.         {
  71.                 GenCmds = fopen("Generated_Commands.txt", io_append); // Create the file 'Generated_Commands.txt' with the filemode being 'io_append'. We store the variable returned by the function into our 'GenCmds' global variable, as we will use this as a file handle.
  72.                 fclose(GenCmds); // Close the file handle 'GenCmds'. This will successfully close 'Generated_Commands.txt', which will stop our server from crashing.
  73.         }
  74.        
  75.         return 1; // Return 1 to the server, which will allow information to be processed after this script has been looped through.
  76. }
  77.  
  78. #endif
  79.  
  80. //******************************************************************************************************
  81.  
  82. public OnPlayerConnect(playerid)
  83.         return SendClientMessage(playerid, 0x33CCFFAA, "Running Command_Generator Script by ~Cueball~ || To get started type \'/cgen\' at your wanted location"); // Let the player know that the script is running, and tell them how to save a command.
  84.  
  85. //******************************************************************************************************
  86.  
  87. public OnPlayerCommandText(playerid, cmdtext[])
  88. {
  89.         if(strcmp (cmdtext, "/cgen", true, 5) == 0) // '/cgen'.
  90.     {
  91.         if (strlen(cmdtext) < 7 || cmdtext[6] == '/') // If the player's command name wasn't given, or if they tried to do (FOR EXAMPLE): '/cgen /chiliad', tell them how to use the command correctly.
  92.                         return SendClientMessage(playerid, 0xFF9900AA, "USAGE: /cgen [teleport/command name] (DO NOT INCLUDE THE '/'!)");
  93.  
  94.                 if(strlen(cmdtext) > (MAX_COMMAND_NAME + 6)) // If their command name is too long, tell them that they have made a mistake.
  95.                     return SendClientMessage(playerid, 0xFF9900AA, "ERROR: You're command name is too long!");
  96.  
  97.         format(string, MAX_COMMAND_NAME, "%s", cmdtext[6]); // Formatting 'string' to hold their command name, so that we can successfully compare strings later.
  98.  
  99.                 if(strcmp(string, "help", true, 4) == 0) // '/cgen help'.
  100.                 {
  101.                     SendClientMessage(playerid, 0x33CCFFAA, "Command Generator Help by ~Cueball~"); // Show helpful information about Command Generator
  102.                     SendClientMessage(playerid, 0xFF9900AA, "Go to a location and type \'/cgen [command name]\'. The command will be sent to the server owner.");
  103.                     SendClientMessage(playerid, 0xFF9900AA, "If enabled by the server, you can then type \'/[command name]\',");
  104.                     SendClientMessage(playerid, 0xFF9900AA, "where \'[command name]\' is the name of a previously generated command.");
  105.                     SendClientMessage(playerid, 0x33CCFFAA, "PLEASE NOTE: Do not try to generate any frequently used command names such as \'/help\'.");
  106.                     return SendClientMessage(playerid, 0x33CCFFAA, "Administrators keep constant watch over generated commands, so it is unwise to flood the system.");
  107.                 }
  108.  
  109.                 for(new i = 0; i < MAX_COMMANDS; i++) // A for loop which runs a maximum of MAX_COMMANDS - 1 times.
  110.                 {
  111.                     if(gCommands[i][NAME][0] != '\0' && strcmp(string, gCommands[i][NAME], true, strlen(gCommands[i][NAME])) == 0) // If the current cell of 'gCommands[*][NAME][0]' is not empty AND it is the same as the command name the player supplied (if that command name is already in use), tell them that they must use a different command name.
  112.                             return SendClientMessage(playerid, 0xFF9900AA, "ERROR: Somebody has already generated a command with that name! Please use a different one.");
  113.                 }
  114.  
  115.                 for(new i = 0; i < MAX_INVALID_COMMANDS; i++) // A for loop which runs a maximum of MAX_INVALID_COMMANDS - 1 times.
  116.                 {
  117.                         if(strcmp(string, gInvalidCommands[i], true, strlen(gInvalidCommands[i])) == 0) // If the command name that the player supplied is the same as one in our 'gInvalidCommands' array, tell them that that command name is disabled.
  118.                             return SendClientMessage(playerid, 0xFF9900AA, "ERROR: The server owner has disabled generating a command with that name!");
  119.                 }
  120.  
  121.         new Float:x, Float:y, Float:z, Float:Ang, Interior, // Create 4 floats which will hold the players position and facing angle, as well as an integer.
  122.                         PlayerIp[16], PlayerName[MAX_PLAYER_NAME],      // Create 2 strings, with a maximum length of 16 and 24 characters (the value of 'MAX_PLAYER_NAME') respectively.
  123.                         hour, minute, second, year, month, day;         // Create 6 integers which will hold the servers current time and date.
  124.  
  125.                 GetPlayerPos(playerid, x, y, z);                         // Store the players current X, Y and Z co-ordinates into our 'x', 'y' and 'z' variables respectively.
  126.                 GetPlayerFacingAngle(playerid, Ang);                     // Store the players current angle that they are facing into our 'Ang' variable.
  127.                 Interior = GetPlayerInterior(playerid);                  // Store the players current interior into our 'Interior' variable.
  128.                 GetPlayerName(playerid, PlayerName, sizeof(PlayerName)); // Store the players name into our 'PlayerName' variable, with a maximum length of the size of 'PlayerName' (24, or 'MAX_PLAYER_NAME').
  129.                 GetPlayerIp(playerid, PlayerIp, sizeof(PlayerIp));       // Store the players IP address into our 'PlayerIp' variable, with a maximum length of the size of 'PlayerIp' (24).
  130.                 gettime(hour, minute, second);                           // Store the servers current time in our 'hour', 'minute' and 'second' variables.
  131.                 getdate(year, month, day);                               // Store the servers current date in our 'year', 'month' and 'day' variables.
  132.                        
  133.                 GenCmds = fopen("Generated_Commands.txt", io_append); // Open the file 'Generated_Commands.txt' with the filemode being 'io_append'. We store the variable returned by the function into our 'GenCmds' global variable, as we will use this as a file handle.
  134.                 format(string, sizeof(string), "if(strcmp(\"/%s\", cmdtext, true, %d) == 0) // Requested by player '%s' (IP: %s) on the %d/%d/%d. Time: %d:%d:%d\r\n{\r\n", cmdtext[6], strlen(cmdtext) - 5, PlayerName, PlayerIp, day, month, year, hour, minute, second); // Formatting 'string' to hold a valid command check.
  135.                 fwrite(GenCmds, string); // Writing the formatted 'string' to our 'GenCmds' file.
  136.                
  137.                 #if VehicleTele == 1 // If 'VehicleTele' is defined as 1, do the following:
  138.                 format(string, sizeof(string), "    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)\r\n    {\r\n        SetPlayerInterior(playerid, %d);\r\n        LinkVehicleToInterior(GetPlayerVehicleID(playerid), %d);\r\n        SetVehiclePos(GetPlayerVehicleID(playerid), %f, %f, %f);\r\n        SetVehicleZAngle(GetPlayerVehicleID(playerid), %f);\r\n        return 1;\r\n    }\r\n", Interior, Interior, x, y, z, Ang); // Formatting 'string' to hold a valid set of functions.
  139.                 fwrite(GenCmds, string); // Writing the formatted 'string' to our 'GenCmds' file.
  140.                 format(string, sizeof(string), "    else\r\n    {\r\n        SetPlayerInterior(playerid, %d);\r\n        SetPlayerPos(playerid, %f, %f, %f);\r\n        SetPlayerFacingAngle(playerid, %f);\r\n        return 1;\r\n    }\r\n}\r\n", Interior, x, y, z, Ang); // Formatting 'string' to hold a valid set of functions.
  141.                 fwrite(GenCmds, string); // Writing the formatted 'string' to our 'GenCmds' file.
  142.         #else // If 'VehicleTele' was NOT 1, do the following:
  143.                 format(string, sizeof(string), "    SetPlayerInterior(playerid, %d);\r\n    SetPlayerPos(playerid, %f, %f, %f);\r\n    SetPlayerFacingAngle(playerid, %f);\r\n    return 1;\r\n}\r\n", Interior, x, y, z, Ang); // Formatting 'string' to hold a valid set of functions.
  144.                 fwrite(GenCmds, string); // Writing the formatted 'string' to our 'GenCmds' file.
  145.         #endif // End the check for 'VehicleTele == 1'. This will prevent errors.
  146.        
  147.         fwrite(GenCmds, "\r\n// ******************* Command Generator By ~Cueball~ ******************* \\\\\r\n\r\n"); // Write a little command separator comment to the file.
  148.         fclose(GenCmds); // Close the file handle 'GenCmds'. This will successfully close 'Generated_Commands.txt', which will stop our server from crashing.
  149.  
  150.         #if PrintInConsole == 1 // If 'PrintInConsole' is defined as 1, do the following:
  151.                         printf("[generator] Player '%s' (IP: %s) requested '/%s'.", PlayerName, PlayerIp, cmdtext[6]); // Format a string with the necessary info, and then print it to the server console.
  152.                 #endif // End the check for 'PrintInConsole == 1'. This will prevent errors.
  153.                
  154.                 #if SendAdminMessage == 1 // If 'SendAdminMessage' is defined as 1, do the following:
  155.                         format(string, sizeof(string), "Command Generator: Player \'%s\' (ID: %d) requested \'/%s\'", PlayerName, playerid, cmdtext[6]); // Formatting 'string' to hold a set of information about the player who generated the command.
  156.                         for(new i = 0; i <= MAX_PLAYERS; i++) // A for loop which runs a maximum of MAX_PLAYERS (200) times.
  157.                         if(IsPlayerConnected(i)) // If the current iteration is connected:
  158.                         if(IsPlayerAdmin(i)) // If the current iteration is logged in as an RCON admin:
  159.                                 SendClientMessage(i, 0x33CCFFAA, string); // Sending the formatted 'string' to the player.
  160.                 #endif // End the check for 'SendAdminMessage == 1'. This will prevent errors.
  161.                
  162.                 format(string, sizeof(string), "Command Generator: Your command \'/%s\' has been generated and sent to the server owner.", cmdtext[6]); // Formatting 'string' to hold a message containing the command name.
  163.                 SendClientMessage(playerid, 0x33CCFFAA, string); // Sending the formatted 'string' to the player.
  164.                 SendClientMessage(playerid, 0x33CCFFAA, "Your command statistics are:"); // Sending a message to the player.
  165.                 format(string, sizeof(string), "Command Name: /%s | Interior: %d | Angle Value: %.2f", cmdtext[6], Interior, Ang); // Formatting 'string' to hold a message containing relevant command information.
  166.                 SendClientMessage(playerid, 0x33CCFFAA, string); // Sending the formatted 'string' to the player.
  167.                 format(string, sizeof(string), "X Value: %.2f | Y Value: %.2f | Z Value: %.2f", x, y, z, Ang, Interior); // Formatting 'string' to hold a message containing relevant command information.
  168.                 SendClientMessage(playerid, 0x33CCFFAA, string); // Sending the formatted 'string' to the player.
  169.                
  170.                 #if SaveCommands == 1 // If 'SaveCommands' is defined as 1, do the following:
  171.                     if(CurrentCommand == MAX_COMMANDS) // If 'CurrentCommand' is equal to 'MAX_COMMANDS' (ie: The amount of commands has reached its maximum):
  172.                         CurrentCommand = 0; // Set 'CurrentCommand' to equal 0.
  173.                     format(gCommands[CurrentCommand][NAME], MAX_COMMAND_NAME, "%s", cmdtext[6]);   // Change the current command's 'NAME' cell of our 'gCommands' array to the name of the command.
  174.                     format(gCommands[CurrentCommand][CREATOR], MAX_PLAYER_NAME, "%s", PlayerName); // Change the current command's 'CREATOR' cell of our 'gCommands' array to the name of the command creator.
  175.             gCommands[CurrentCommand][POS][0] = x;   // Store the 'x' co-ordinate of our command in the first cell of our current command's 'POS' cell of our 'gCommands' array.
  176.             gCommands[CurrentCommand][POS][1] = y;   // Store the 'y' co-ordinate of our command in the second cell of our current command's 'POS' cell of our 'gCommands' array.
  177.             gCommands[CurrentCommand][POS][2] = z;   // Store the 'z' co-ordinate of our command in the third cell of our current command's 'POS' cell of our 'gCommands' array.
  178.             gCommands[CurrentCommand][POS][3] = Ang; // Store the 'angle' co-ordinate of our command in the fourth cell of our current command's 'POS' cell of our 'gCommands' array.
  179.             gCommands[CurrentCommand][INTERIOR] = GetPlayerInterior(playerid); // Store the interior of our command in our current command's 'INTERIOR' cell of our 'gCommands' array.
  180.             format(string, sizeof(string), "The server has allowed your command to be used immediately. Type \'/%s\' to teleport to this current location.", cmdtext[6]); // Formatting 'string' to hold a message containing the command name.
  181.             SendClientMessage(playerid, 0xFF9900AA, string); // Sending the formatted 'string' to the player.
  182.             CurrentCommand++;
  183.                 #endif // End the check for 'SaveCommands == 1'. This will prevent errors.
  184.                
  185.                 return 1; // Return 1 to the server, and stop the 'SERVER: Unknown command.' message being sent to the player.
  186.         }
  187.        
  188.     #if SaveCommands == 1 // If 'SaveCommands' is defined as 1, do the following:
  189.         format(string, MAX_COMMAND_NAME, "%s", cmdtext[1]); // Formatting 'string' to hold their command name, so that we can successfully compare strings later.
  190.    
  191.                 for(new i = 0; i <= MAX_COMMANDS; i++) // A for loop which runs a maximum of MAX_COMMANDS times.
  192.                 {
  193.                 if(gCommands[i][NAME][0] != '\0' && strcmp(string, gCommands[i][NAME], true, strlen(gCommands[i][NAME])) == 0) // If the current cell of 'gCommands[*][NAME][0]' is not empty AND it is the same as the command name the player supplied, do the following:
  194.                 {
  195.                         #if VehicleTele == 1 // If 'VehicleTele' is defined as 1, do the following:
  196.                         if(IsPlayerInAnyVehicle(playerid)) // If the player is in ANY vehicle, do the following:
  197.                         {
  198.                                 SetPlayerInterior(playerid, gCommands[i][INTERIOR]); // Set the player's interior to the correct value for our command.
  199.                                 LinkVehicleToInterior(GetPlayerVehicleID(playerid), gCommands[i][INTERIOR]); // Get the player's vehicle id, and set its interior to the correct value for our command.
  200.                                 SetVehiclePos(GetPlayerVehicleID(playerid), gCommands[i][POS][0], gCommands[i][POS][1], gCommands[i][POS][2]); // Get the player's vehicle id, and set its position to the correct co-ordinate for our command.
  201.                                         SetVehicleZAngle(GetPlayerVehicleID(playerid), gCommands[i][POS][3]); // Get the player's vehicle id, and set it to face the correct angle for our command.
  202.                                         }
  203.                                         else // If the player is NOT in a vehicle, do the following:
  204.                                         {
  205.                                         SetPlayerInterior(playerid, gCommands[i][INTERIOR]); // Set the player's interior to the correct value for our command.
  206.                                                 SetPlayerPos(playerid, gCommands[i][POS][0], gCommands[i][POS][1], gCommands[i][POS][2]); // Set the player's position to the correct co-ordinate for our command.
  207.                                         SetPlayerFacingAngle(playerid, gCommands[i][POS][3]); // Set the player to face the correct angle for our command.
  208.                                         }
  209.                         #else // If 'VehicleTele' was NOT 1, do the following:
  210.                                 SetPlayerInterior(playerid, gCommands[i][INTERIOR]); // Set the player's interior to the correct value for our command.
  211.                                 SetPlayerPos(playerid, gCommands[i][POS][0], gCommands[i][POS][1], gCommands[i][POS][2]); // Set the player's position to the correct co-ordinate for our command.
  212.                                 SetPlayerFacingAngle(playerid, gCommands[i][POS][3]); // Set the player to face the correct angle for our command.
  213.                         #endif // End the check for 'VehicleTele == 1'. This will prevent errors.
  214.                
  215.                         #if SendTeleMessage == 1 // If 'VehicleTele' is defined as 1, do the following:
  216.                         format(string, sizeof(string), "Command \'/%s\' was created by \'%s\'. You can create your own commands by typing \'/cgen\' at your wanted location.", gCommands[i][NAME], gCommands[i][CREATOR]); // Formatting 'string' to hold a message containing the command name and the creator of the command's name.
  217.                         SendClientMessage(playerid, 0x33CCFFAA, string); // Sending the formatted 'string' to the player.
  218.                                 #endif // End the check for 'SendTeleMessage == 1'. This will prevent errors.
  219.                        
  220.                         return 1; // Return 1 to the server, and stop the 'SERVER: Unknown command.' message being sent to the player.
  221.                         }
  222.                 }
  223.         #endif // End the check for 'SaveCommands == 1'. This will prevent errors.
  224.  
  225.         return 0; // Send the 'SERVER: Unknown command.' message for any other commands.
  226. }
  227.  
  228. //******************************************************************************************************
  229.  
  230. public OnVehicleSpawn(vehicleid)
  231.         return LinkVehicleToInterior(vehicleid, 0); // Set the vehicle's interior to 0, which will prevent cars from being invisible if they were used in a generated command with an interior other than 0 (inside a building).

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post