Guest User

Contract-System by inCrecdible

a guest
Apr 9th, 2012
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.74 KB | None | 0 0
  1. #include <a_samp>
  2. #include <ocmd>
  3.  
  4. #define DIALOG_LAPTOP (1)
  5.  
  6. new Contracted[MAX_PLAYERS];
  7. new ContractMoney[MAX_PLAYERS];
  8. new stringz[128];
  9.  
  10. public OnFilterScriptInit()
  11. {
  12.     print("\n--------------------------------------");
  13.     print("[LITTLE]Contract-System by inCrecdible geladen.");
  14.     print("--------------------------------------\n");
  15.     return 1;
  16. }
  17.  
  18. public OnFilterScriptExit()
  19. {
  20.     print("\n--------------------------------------");
  21.     print("[LITTLE]Contract-System by inCrecdible entladen.");
  22.     print("--------------------------------------\n");
  23.     return 1;
  24. }
  25.  
  26.  
  27. public OnPlayerDisconnect(playerid, reason)
  28. {
  29.     if(Contracted[playerid] == 1)
  30.     {
  31.         new name[MAX_PLAYER_NAME];
  32.         GetPlayerName(playerid, name, sizeof(name));
  33.         format(stringz, sizeof(stringz), "[ANTI-OFFLINE-FLUCHT]%s ist contracted offline gegangen!", name);
  34.         SendClientMessageToAll( 0xFFFF00FF,stringz );
  35.     }
  36.     return 1;
  37. }
  38.  
  39. public OnPlayerDeath(playerid, killerid, reason)
  40. {
  41.     if(Contracted[playerid] == 1)
  42.     {
  43.         GivePlayerMoney(killerid, ContractMoney[playerid]);
  44.         SendClientMessage(playerid,  0xFFFF00FF, "Du wurdest von einem Auftragskiller ermordet!");
  45.         Contracted[playerid] = 0;
  46.     }
  47.     return 1;
  48. }
  49.  
  50. ocmd:contract(playerid,params[])
  51. {
  52.     new TargetID, Money;
  53.     if(sscanf(params,"si",TargetID, Money))return SendClientMessage(playerid,0xFF1400FF, "Error: /contract [Username/ID] [Geld]");
  54.     if(GetPlayerMoney(playerid) < Money)return SendClientMessage(playerid, 0xFF1400FF, "Error: Du hast nicht genügend Geld!");
  55.     Contracted[TargetID] = 1;
  56.     ContractMoney[TargetID] = Money;
  57.     return 1;
  58. }
  59.  
  60. public OnPlayerCommandText(playerid, cmdtext[])
  61. {
  62.     if(strcmp("/laptop", cmdtext, true, 10) == 0)
  63.     {
  64.         new name[MAX_PLAYER_NAME];
  65.         for(new i=0; i<GetMaxPlayers(); i++)
  66.         {
  67.             if(Contracted[i] == 1)
  68.             {
  69.                 GetPlayerName(i, name, sizeof(name));
  70.                 format(stringz,sizeof(stringz), "Auftrag: %s (%i$)", name, ContractMoney[i]);
  71.             }
  72.         }
  73.         ShowPlayerDialog(playerid, DIALOG_LAPTOP, DIALOG_STYLE_MSGBOX, "Folgende Aufträge sind vorhanden:", stringz, "Ok", "");
  74.         return 1;
  75.     }
  76.                
  77.            
  78.     return 1;
  79. }
  80.  
  81. stock sscanf(string[], format[], {Float,_}:...)
  82. {
  83.     #if defined isnull
  84.         if (isnull(string))
  85.     #else
  86.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  87.     #endif
  88.         {
  89.             return format[0];
  90.         }
  91.     #pragma tabsize 4
  92.     new
  93.         formatPos = 0,
  94.         stringPos = 0,
  95.         paramPos = 2,
  96.         paramCount = numargs(),
  97.         delim = ' ';
  98.     while (string[stringPos] && string[stringPos] <= ' ')
  99.     {
  100.         stringPos++;
  101.     }
  102.     while (paramPos < paramCount && string[stringPos])
  103.     {
  104.         switch (format[formatPos++])
  105.         {
  106.             case '\0':
  107.             {
  108.                 return 0;
  109.             }
  110.             case 'i', 'd':
  111.             {
  112.                 new
  113.                     neg = 1,
  114.                     num = 0,
  115.                     ch = string[stringPos];
  116.                 if (ch == '-')
  117.                 {
  118.                     neg = -1;
  119.                     ch = string[++stringPos];
  120.                 }
  121.                 do
  122.                 {
  123.                     stringPos++;
  124.                     if ('0' <= ch <= '9')
  125.                     {
  126.                         num = (num * 10) + (ch - '0');
  127.                     }
  128.                     else
  129.                     {
  130.                         return -1;
  131.                     }
  132.                 }
  133.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  134.                 setarg(paramPos, 0, num * neg);
  135.             }
  136.             case 'h', 'x':
  137.             {
  138.                 new
  139.                     num = 0,
  140.                     ch = string[stringPos];
  141.                 do
  142.                 {
  143.                     stringPos++;
  144.                     switch (ch)
  145.                     {
  146.                         case 'x', 'X':
  147.                         {
  148.                             num = 0;
  149.                             continue;
  150.                         }
  151.                         case '0' .. '9':
  152.                         {
  153.                             num = (num << 4) | (ch - '0');
  154.                         }
  155.                         case 'a' .. 'f':
  156.                         {
  157.                             num = (num << 4) | (ch - ('a' - 10));
  158.                         }
  159.                         case 'A' .. 'F':
  160.                         {
  161.                             num = (num << 4) | (ch - ('A' - 10));
  162.                         }
  163.                         default:
  164.                         {
  165.                             return -1;
  166.                         }
  167.                     }
  168.                 }
  169.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  170.                 setarg(paramPos, 0, num);
  171.             }
  172.             case 'c':
  173.             {
  174.                 setarg(paramPos, 0, string[stringPos++]);
  175.             }
  176.             case 'f':
  177.             {
  178.  
  179.                 new changestr[16], changepos = 0, strpos = stringPos;
  180.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  181.                 {
  182.                     changestr[changepos++] = string[strpos++];
  183.                     }
  184.                 changestr[changepos] = '\0';
  185.                 setarg(paramPos,0,_:floatstr(changestr));
  186.             }
  187.             case 'p':
  188.             {
  189.                 delim = format[formatPos++];
  190.                 continue;
  191.             }
  192.             case '\'':
  193.             {
  194.                 new
  195.                     end = formatPos - 1,
  196.                     ch;
  197.                 while ((ch = format[++end]) && ch != '\'') {}
  198.                 if (!ch)
  199.                 {
  200.                     return -1;
  201.                 }
  202.                 format[end] = '\0';
  203.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  204.                 {
  205.                     if (format[end + 1])
  206.                     {
  207.                         return -1;
  208.                     }
  209.                     return 0;
  210.                 }
  211.                 format[end] = '\'';
  212.                 stringPos = ch + (end - formatPos);
  213.                 formatPos = end + 1;
  214.             }
  215.             case 'u':
  216.             {
  217.                 new
  218.                     end = stringPos - 1,
  219.                     id = 0,
  220.                     bool:num = true,
  221.                     ch;
  222.                 while ((ch = string[++end]) && ch != delim)
  223.                 {
  224.                     if (num)
  225.                     {
  226.                         if ('0' <= ch <= '9')
  227.                         {
  228.                             id = (id * 10) + (ch - '0');
  229.                         }
  230.                         else
  231.                         {
  232.                             num = false;
  233.                         }
  234.                     }
  235.                 }
  236.                 if (num && IsPlayerConnected(id))
  237.                 {
  238.                     setarg(paramPos, 0, id);
  239.                 }
  240.                 else
  241.                 {
  242.                     #if !defined foreach
  243.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  244.                         #define __SSCANF_FOREACH__
  245.                     #endif
  246.                     string[end] = '\0';
  247.                     num = false;
  248.                     new
  249.                         name[MAX_PLAYER_NAME];
  250.                     id = end - stringPos;
  251.                     foreach (Player, playerid)
  252.                     {
  253.                         GetPlayerName(playerid, name, sizeof (name));
  254.                         if (!strcmp(name, string[stringPos], true, id))
  255.                         {
  256.                             setarg(paramPos, 0, playerid);
  257.                             num = true;
  258.                             break;
  259.                         }
  260.                     }
  261.                     if (!num)
  262.                     {
  263.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  264.                     }
  265.                     string[end] = ch;
  266.                     #if defined __SSCANF_FOREACH__
  267.                         #undef foreach
  268.                         #undef __SSCANF_FOREACH__
  269.                     #endif
  270.                 }
  271.                 stringPos = end;
  272.             }
  273.             case 's', 'z':
  274.             {
  275.                 new
  276.                     i = 0,
  277.                     ch;
  278.                 if (format[formatPos])
  279.                 {
  280.                     while ((ch = string[stringPos++]) && ch != delim)
  281.                     {
  282.                         setarg(paramPos, i++, ch);
  283.                     }
  284.                     if (!i)
  285.                     {
  286.                         return -1;
  287.                     }
  288.                 }
  289.                 else
  290.                 {
  291.                     while ((ch = string[stringPos++]))
  292.                     {
  293.                         setarg(paramPos, i++, ch);
  294.                     }
  295.                 }
  296.                 stringPos--;
  297.                 setarg(paramPos, i, '\0');
  298.             }
  299.             default:
  300.             {
  301.                 continue;
  302.             }
  303.         }
  304.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  305.         {
  306.             stringPos++;
  307.         }
  308.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  309.         {
  310.             stringPos++;
  311.         }
  312.         paramPos++;
  313.     }
  314.     do
  315.     {
  316.         if ((delim = format[formatPos++]) > ' ')
  317.         {
  318.             if (delim == '\'')
  319.             {
  320.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  321.             }
  322.             else if (delim != 'z')
  323.             {
  324.                 return delim;
  325.             }
  326.         }
  327.     }
  328.     while (delim > ' ');
  329.     return 0;
  330. }
Advertisement
Add Comment
Please, Sign In to add comment