Advertisement
Kar

RyDeR`'s class selection maker

Kar
May 17th, 2018
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.40 KB | None | 0 0
  1. /*
  2.     Release:
  3.             » OnPlayerRequestClass Maker Filterscript
  4.  
  5.     Version:
  6.             » v0.1a
  7.  
  8.     Functions:
  9.             » isNumeric(const string[]);
  10.  
  11.     Credits:
  12.             » Credits to the maker of isNumeric
  13. */
  14.  
  15. #include <a_samp>
  16.    
  17. #define GREEN \
  18.     0x33AA33AA
  19.    
  20. #define RED \
  21.     0xE60000FF
  22.  
  23. #define SHORT \
  24.     5
  25.    
  26. #define MEDIUM \
  27.     10
  28.  
  29. #define FAR \
  30.     25
  31.    
  32. new bool: MakeClass[MAX_PLAYERS],
  33.     MulValue[MAX_PLAYERS],
  34.     Float: SavePos[4][MAX_PLAYERS]
  35. ;
  36.    
  37. public OnFilterScriptInit()
  38. {
  39.     print(">> OnPlayerRequestClass Maker filterscript by  » RyDeR «  has been loaded!");
  40.     return 1;
  41. }
  42.  
  43. public OnFilterScriptExit()
  44. {
  45.     print(">> OnPlayerRequestClass Maker filterscript by  » RyDeR «  has been unloaded!");
  46.     return 1;
  47. }
  48.  
  49. public OnPlayerCommandText(playerid, cmdtext[])
  50. {
  51.     if(!strcmp(cmdtext, "/classmaker", true))
  52.     {
  53.         if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, RED, "Error: You are in a vehicle! Please get out.");
  54.         SendClientMessage(playerid, GREEN, ">> You have enabled 'OnPlayerRequestClass Maker', follow the intructions of the dialogs!");
  55.         ShowDialog(playerid, 1000);
  56.         TogglePlayerControllable(playerid, false);
  57.         return 1;
  58.     }
  59.     return 0;
  60. }
  61. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  62. {
  63.     switch(dialogid)
  64.     {
  65.         case 1000:
  66.         {
  67.             if(!response) return SendClientMessage(playerid, RED, ">> You have stopped making class! Type /classmaker to start a new wizard!"), TogglePlayerControllable(playerid, true), MakeClass[playerid] = false;
  68.             TogglePlayerControllable(playerid, true), MakeClass[playerid] = true;
  69.         }
  70.         case 1001:
  71.         {
  72.             if(!response) return TogglePlayerControllable(playerid, true), MakeClass[playerid] = true;
  73.             GetPlayerPos(playerid, SavePos[0][playerid], SavePos[1][playerid], SavePos[2][playerid]);
  74.             GetPlayerFacingAngle(playerid, SavePos[3][playerid]);
  75.             ShowDialog(playerid, 1002);
  76.         }
  77.         case 1002:
  78.         {
  79.             if(!response) return SendClientMessage(playerid, RED, ">> You have stopped making class! Type /classmaker to start a new wizard!"), TogglePlayerControllable(playerid, true), MakeClass[playerid] = false;
  80.             if(!strlen(inputtext)) return ShowDialog(playerid, 1003);
  81.             if(isNumeric(inputtext))
  82.             {
  83.                 if(strval(inputtext) < 5 || strval(inputtext) > 30) return ShowDialog(playerid, 1003);
  84.                     else return MulValue[playerid] = strval(inputtext), ShowDialog(playerid, 1004);
  85.             }
  86.             else if(!isNumeric(inputtext))
  87.             {
  88.                 if(!strcmp(inputtext, "SHORT", true)) return MulValue[playerid] = SHORT, ShowDialog(playerid, 1004);
  89.                     else ShowDialog(playerid, 1003);
  90.                 if(!strcmp(inputtext, "MEDIUM", true)) return MulValue[playerid] = MEDIUM, ShowDialog(playerid, 1004);
  91.                     else ShowDialog(playerid, 1003);
  92.                 if(!strcmp(inputtext, "FAR", true)) return MulValue[playerid] = FAR, ShowDialog(playerid, 1004);
  93.                     else ShowDialog(playerid, 1003);
  94.             }
  95.         }
  96.         case 1003:
  97.         {
  98.             if(!response) return SendClientMessage(playerid, RED, ">> You have stopped making class! Type /classmaker to start a new wizard!"), TogglePlayerControllable(playerid, true), MakeClass[playerid] = false;
  99.             if(!strlen(inputtext)) return ShowDialog(playerid, 1003);
  100.             if(isNumeric(inputtext))
  101.             {
  102.                 if(strval(inputtext) < 5 || strval(inputtext) > 30) return ShowDialog(playerid, 1003);
  103.                     else return MulValue[playerid] = strval(inputtext), ShowDialog(playerid, 1004);
  104.             }
  105.             else if(!isNumeric(inputtext))
  106.             {
  107.                 if(!strcmp(inputtext, "SHORT", true)) return MulValue[playerid] = SHORT, ShowDialog(playerid, 1004);
  108.                     else ShowDialog(playerid, 1003);
  109.                 if(!strcmp(inputtext, "MEDIUM", true)) return MulValue[playerid] = MEDIUM, ShowDialog(playerid, 1004);
  110.                     else ShowDialog(playerid, 1003);
  111.                 if(!strcmp(inputtext, "FAR", true)) return MulValue[playerid] = FAR, ShowDialog(playerid, 1004);
  112.                     else ShowDialog(playerid, 1003);
  113.             }
  114.         }
  115.         case 1004:
  116.         {
  117.             if(!strlen(inputtext)) return ShowDialog(playerid, 1006);
  118.             new
  119.                 File: cFile,
  120.                 string[256]
  121.             ;
  122.             cFile = fopen("/Classes.txt", io_append);
  123.             format(string, sizeof(string), "\r\n\r\n/* Saved under name: %s - Add under OnPlayerRequestClass.. */\r\n\r\n", inputtext), fwrite(cFile, string);
  124.             format(string, sizeof(string), "SetPlayerPos(playerid, %f, %f, %f);\r\n", SavePos[0][playerid], SavePos[1][playerid], SavePos[2][playerid]), fwrite(cFile, string);
  125.             format(string, sizeof(string), "SetPlayerFacingAngle(playerid, %f);\r\n", SavePos[3][playerid]), fwrite(cFile, string);
  126.             format(string, sizeof(string), "SetPlayerCameraLookAt(playerid, %f, %f, %f);\r\n", SavePos[0][playerid], SavePos[1][playerid], SavePos[2][playerid]), fwrite(cFile, string);
  127.             format(string, sizeof(string), "SetPlayerCameraPos(playerid, %f + (%d * floatsin(-%f, degrees)), %f + (%d * floatcos(-%f, degrees)), %f);", SavePos[0][playerid], MulValue[playerid], SavePos[3][playerid], SavePos[1][playerid], MulValue[playerid], SavePos[3][playerid], SavePos[2][playerid]), fwrite(cFile, string);
  128.             fclose(cFile);
  129.             ShowDialog(playerid, 1005);
  130.         }
  131.         case 1005:
  132.         {
  133.             if(!response) return TogglePlayerControllable(playerid, true), MakeClass[playerid] = false;
  134.             ShowDialog(playerid, 1000);
  135.         }
  136.         case 1006:
  137.         {
  138.             if(!strlen(inputtext)) return ShowDialog(playerid, 1006);
  139.         }
  140.     }
  141.     return 1;
  142. }
  143.  
  144. ShowDialog(playerid, dialogid)
  145. {
  146.     switch(dialogid)
  147.     {
  148.         case 1000:
  149.         {
  150.             ShowPlayerDialog(playerid, 1000, DIALOG_STYLE_MSGBOX, "Step 1", "\
  151.             Welcome to 'OnPlayerRequestClass Maker'.\n\
  152.             From now on, it's much easier to create a class instead of gambling the correct camera position etc.\n\n\
  153.             Step 1: \n\
  154.             *********\n\
  155.             Go to a place where the player should stand while he is choosing his skin and while is watching the camera.\n\
  156.             >> Press 'OK' to continue. 'Exit' to cancel the current wizard!\n\n\
  157.             Note: Press Enter when you have the location to continue the wizard!", "OK", "Exit");
  158.         }
  159.         case 1001:
  160.         {
  161.             ShowPlayerDialog(playerid, 1001, DIALOG_STYLE_MSGBOX, "Are you sure ..", "\
  162.             Are you sure with the player coordinate?\n\n\
  163.             Answer 'Yes' to continue. 'No' to take the player coordinates again.\n\n\
  164.             NOTE: If you answer 'No' you're able to get new coordinates. Press 'Enter' when you found other position!", "Yes", "No");
  165.         }
  166.         case 1002:
  167.         {
  168.             ShowPlayerDialog(playerid, 1002, DIALOG_STYLE_INPUT, "Step 2", "\
  169.             Step 2:\n\
  170.             *********\n\
  171.             Welcome again. In this step you have to choose the distance between the player and the camera.\n\
  172.             You can also write input as SHORT, MEDIUM, FAR (e.g. SHORT) or just give the correct value between 5-30 (e.g. 25)\n\n\
  173.             >> Write the value below and press 'OK' to continue. 'Exit' to end the process", "OK", "Exit");
  174.         }
  175.         case 1003:
  176.         {
  177.             ShowPlayerDialog(playerid, 1003, DIALOG_STYLE_INPUT, "ERROR: Step 2", "\
  178.             ERROR: The value is incorrect(5-30) also check if the value is numeric or is aviable. (SHORT, MEDIUM, FAR)\n\n\n\
  179.             Welcome again. In this step you have to choose the distance between the player and the camera.\n\
  180.             You can also write input as SHORT, MEDIUM, FAR (e.g. SHORT) or just give the correct value between 5-30. (e.g. 25)\n\n\
  181.             >> Write the value below and press 'OK' to continue. 'Exit' to end the process", "OK", "Exit");
  182.         }
  183.         case 1004:
  184.         {
  185.             ShowPlayerDialog(playerid, 1004, DIALOG_STYLE_INPUT, "Step 3", "\
  186.             This was actually the last step. This filterscript uses goniometric values to find out where the camera position is.\n\
  187.             Easy? ;)\n\
  188.             Step 3:\n\
  189.             *********\n\
  190.             You are done if you give the name to save the file under!", "OK", "Exit");
  191.         }
  192.         case 1005:
  193.         {
  194.             ShowPlayerDialog(playerid, 1005, DIALOG_STYLE_MSGBOX, "Ending wizard..", "\
  195.             The files has been saved in the scriptfiles directory under name Classes.txt.\n\
  196.             If you open it you will see your created class with the given name in the previous step.", "Another", "Finish");
  197.         }
  198.         case 1006:
  199.         {
  200.             ShowPlayerDialog(playerid, 1004, DIALOG_STYLE_INPUT, "ERROR: Step 3", "\
  201.             ERROR: You have to give a valid name to save it under!\n\n\n\
  202.             This was actually the last step. This filterscript uses goniometric values to find out where the camera position is.\n\
  203.             Easy? ;)\n\n\
  204.             You are done if you give the name to save the file under!", "OK", "Exit");
  205.         }
  206.     }
  207.     return 1;
  208. }
  209.  
  210. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  211. {
  212.     if(MakeClass[playerid] == true)
  213.     {
  214.         if(newkeys == KEY_SECONDARY_ATTACK)
  215.         {
  216.             ShowDialog(playerid, 1001);
  217.             MakeClass[playerid] = false;
  218.         }
  219.     }
  220.     return 1;
  221. }
  222. public OnPlayerConnect(playerid)
  223. {
  224.     MakeClass[playerid] = (MakeClass[playerid] == true) ? (false) : (false);
  225.     return 1;
  226. }
  227.  
  228. public OnPlayerDisconnect(playerid)
  229. {
  230.     MakeClass[playerid] = (MakeClass[playerid] == true) ? (false) : (false);
  231.     return 1;
  232. }
  233. stock isNumeric(const string[])
  234. {
  235.   new length=strlen(string);
  236.   if (length==0) return false;
  237.   for (new i = 0; i < length; i++)
  238.     {
  239.       if (
  240.             (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+')
  241.              || (string[i]=='-' && i!=0)                                            
  242.              || (string[i]=='+' && i!=0)                                            
  243.          ) return false;
  244.     }
  245.   if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
  246.   return true;
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement