Advertisement
FanHamMer

[FS] Calculator SA:MP [by FanHamMer]

Feb 27th, 2013
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.85 KB | None | 0 0
  1. #include            "a_samp.inc"
  2.  
  3. #file                           "Calc by FanHamMer"
  4.  
  5. #define d_calc                  (0x83)
  6.  
  7. public OnFilterScriptInit()
  8. {
  9.     printf("Calc_"#by"_FanHamMer");
  10.     return true;
  11. }
  12.  
  13. public OnFilterScriptExit() return true;
  14.  
  15. public OnPlayerCommandText(playerid, cmdtext[])
  16. {
  17.     if (strcmp("/calc", cmdtext, true, 10) == 0)
  18.     {
  19.         ShowPlayerDialog(playerid, d_calc, DIALOG_STYLE_INPUT, \
  20.         "Calculator", "Enter a value 'a'", "Enter", "Cancel");
  21.         return true;
  22.     }
  23.     return false;
  24. }
  25.  
  26. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  27. {
  28.     static a, b, c;
  29.     switch(dialogid)
  30.     {
  31.         case d_calc:
  32.         {
  33.             if !response *then return true;
  34.             if !strlen(inputtext) *then return true;
  35.             a = strval(inputtext), \
  36.             ShowPlayerDialog(playerid, d_calc+0b1, DIALOG_STYLE_INPUT,  \
  37.             "Calculator", "Enter a value 'b'", "Enter", "Cancel");
  38.         }
  39.         case d_calc+0x1:
  40.         {
  41.             if !response *then return true;
  42.             if !strlen(inputtext) *then return true;
  43.             b = strval(inputtext), \
  44.             ShowPlayerDialog(playerid, d_calc+0b10, DIALOG_STYLE_INPUT,\
  45.             "Calculator", "Enter the operator (*, /, -, +)", "Enter", "Cancel");
  46.         }
  47.         case d_calc+0b10:
  48.         {
  49.             if !response *then return true;
  50.             if !strlen(inputtext) *then return true;
  51.             static str[21];
  52.             if strfind(inputtext, "+", true) != -1 *then
  53.             c=a+b, format(str,21,"%i+%i = %d",a,b,c);
  54.            
  55.             if strfind(inputtext, "-", true) != -1 *then
  56.             c=a-b, format(str,21,"%i-%i = %d",a,b,c);
  57.            
  58.             if strfind(inputtext, "*", true) != -1 *then
  59.             c=a*b, format(str,21,"%i*%i = %d",a,b,c);
  60.            
  61.             if strfind(inputtext, "/", true) != -1 *then
  62.             c=a/b, format(str,21,"%i/%i = %d",a,b,c);
  63.  
  64.             SendClientMessage(playerid,-1,str);
  65.         }
  66.     }
  67.     return true;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement