Advertisement
Guest User

Untitled

a guest
Jul 7th, 2012
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 15.13 KB | None | 0 0
  1. /*
  2.     Dieses Coupon-System wurde von CoKeZ geschrieben.
  3.    
  4.     (C)CoKeZ - 2012
  5. */
  6.  
  7. #include <a_samp>
  8. #include <dini>
  9.  
  10. #define BLOCK_INTERVAL 3 // Sperrzeit nach mehrmaliger Falscheingabe des Codes (in Minuten)
  11.  
  12. //COLORS
  13. #define COLOR_RED 0xFF0000FF
  14. #define COLOR_LYELLOW 0xFAF0CEFF
  15. #define COLOR_GREEN 0x33AA33AA
  16.  
  17. //DIALOGE
  18. #define DIALOG_COUPONMENU 8123
  19. #define DIALOG_MONEY 8124
  20. #define DIALOG_SCORE 8125
  21. #define DIALOG_WANTEDS 8126
  22. #define DIALOG_WEAPONTYPE 8127
  23. #define DIALOG_WEAPONAMMO 8128
  24. #define DIALOG_ARMOUR 8129
  25. #define DIALOG_SKIN 8130
  26. #define DIALOG_CREATECOUPON 8131
  27. #define DIALOG_COUPON 8132
  28.  
  29. forward Block(playerid);
  30.  
  31. enum CouponEnum
  32. {
  33.     Money,
  34.     Score,
  35.     Wanteds,
  36.     Weapontype,
  37.     Weaponammo,
  38.     Armour,
  39.     Skin
  40. };
  41.  
  42. new Coupon[MAX_PLAYERS][CouponEnum];
  43. new CouponBlock[MAX_PLAYERS];
  44.  
  45. public OnFilterScriptInit()
  46. {
  47.     print("\n--------------------------------------");
  48.     print(" Coupon-System by CoKeZ");
  49.     print("--------------------------------------\n");
  50.     return 1;
  51. }
  52.  
  53. public OnPlayerDisconnect(playerid)
  54. {
  55.     ResetCouponSettings(playerid);
  56. }
  57.  
  58. public OnPlayerCommandText(playerid, cmdtext[])
  59. {
  60.     if(strcmp("/createcoupon", cmdtext, true) == 0)
  61.     {
  62.         if(IsPlayerAdmin(playerid))
  63.         {
  64.             ShowPlayerDialog(playerid, DIALOG_COUPONMENU, DIALOG_STYLE_LIST, "Coupon erstellen", "Geld hinzufügen\nScore hinzufügen\nWanteds hinzufügen\nWaffe hinzufügen\nRüstung hinzufügen\nSkin hinzufügen\nCoupon erstellen", "Auswählen", "Abbrechen");
  65.         }
  66.         else SendClientMessage(playerid, COLOR_RED, "Du bist kein Admin.");
  67.        
  68.         return 1;
  69.     }
  70.    
  71.     if(strcmp("/coupon", cmdtext, true) == 0)
  72.     {
  73.         if(CouponBlock[playerid] != 2)
  74.         {
  75.             ShowPlayerDialog(playerid, DIALOG_COUPON, DIALOG_STYLE_INPUT, "Coupon einlösen", "Gib den Couponcode ein:", "Einlösen", "Abbrechen");
  76.         }
  77.         else SendClientMessage(playerid, COLOR_RED, "Du hast eine Couponsperre.");
  78.        
  79.         return 1;
  80.     }
  81.    
  82.     return 0;
  83. }
  84.  
  85. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  86. {
  87.     if(dialogid == DIALOG_COUPONMENU)
  88.     {
  89.         if(response)
  90.         {
  91.             switch(listitem)
  92.             {
  93.                 case 0:
  94.                 {
  95.                     ShowPlayerDialog(playerid, DIALOG_MONEY, DIALOG_STYLE_INPUT, "Geld hinzufügen", "Wie viel Geld möchtest du hinzufügen?", "Hinzufügen", "Zurück");
  96.                 }
  97.                 case 1:
  98.                 {
  99.                     ShowPlayerDialog(playerid, DIALOG_SCORE, DIALOG_STYLE_INPUT, "Score hinzufügen", "Wie viel Score möchtest du hinzufügen?", "Hinzufügen", "Zurück");
  100.                 }
  101.                 case 2:
  102.                 {
  103.                     ShowPlayerDialog(playerid, DIALOG_WANTEDS, DIALOG_STYLE_INPUT, "Wanteds hinzufügen", "Wie viele Wanteds sollen hinzugefügt werden?", "Hinzufügen", "Zurück");
  104.                 }
  105.                 case 3:
  106.                 {
  107.                     ShowPlayerDialog(playerid, DIALOG_WEAPONTYPE, DIALOG_STYLE_INPUT, "Waffentype auswählen", "Welche Waffe soll hinzugefügt werden? (ID)", "Weiter", "Zurück");
  108.                 }
  109.                 case 4:
  110.                 {
  111.                     ShowPlayerDialog(playerid, DIALOG_ARMOUR, DIALOG_STYLE_INPUT, "Rüstung hinzufügen", "Wie viel Rüstung soll hinzugefügt werden?", "Hinzufügen", "Zurück");
  112.                 }
  113.                 case 5:
  114.                 {
  115.                     ShowPlayerDialog(playerid, DIALOG_SKIN, DIALOG_STYLE_INPUT, "Skin hinzufügen", "Welcher Skin soll hinzugefügt werden?", "Hinzufügen", "Zurück");
  116.                 }
  117.                 case 6:
  118.                 {
  119.                     ShowPlayerDialog(playerid, DIALOG_CREATECOUPON, DIALOG_STYLE_INPUT, "Couponcode auswählen", "Wie soll der Couponcode lauten? (mind. 4 Zeichen)\n\nHinweis: Sollte kein Couponcode eingetragen werden, so wird ein zufälliger generiert.", "Erstellen", "Zurück");
  120.                 }
  121.  
  122.             }
  123.         }
  124.         else ResetCouponSettings(playerid);
  125.        
  126.         return 1;
  127.     }
  128.    
  129.     if(dialogid == DIALOG_MONEY)
  130.     {
  131.         if(response)
  132.         {
  133.             if(strval(inputtext) == 0) return ShowPlayerDialog(playerid, DIALOG_MONEY, DIALOG_STYLE_INPUT, "Geld hinzufügen", "Wie viel Geld möchtest du hinzufügen?", "Hinzufügen", "Zurück");
  134.        
  135.             new msg[64];
  136.            
  137.             format(msg, sizeof(msg), "Dem Coupon wurden %i$ hinzugefügt.", strval(inputtext));
  138.             SendClientMessage(playerid, COLOR_LYELLOW, msg);
  139.             Coupon[playerid][Money] = strval(inputtext);
  140.         }
  141.         ShowPlayerDialog(playerid, DIALOG_COUPONMENU, DIALOG_STYLE_LIST, "Coupon erstellen", "Geld hinzufügen\nScore hinzufügen\nWanteds hinzufügen\nWaffe hinzufügen\nRüstung hinzufügen\nSkin hinzufügen\nCoupon erstellen", "Auswählen", "Abbrechen");
  142.        
  143.         return 1;
  144.     }
  145.    
  146.     if(dialogid == DIALOG_SCORE)
  147.     {
  148.         if(response)
  149.         {
  150.             if(strval(inputtext) == 0) return ShowPlayerDialog(playerid, DIALOG_SCORE, DIALOG_STYLE_INPUT, "Score hinzufügen", "Wie viel Score möchtest du hinzufügen?", "Hinzufügen", "Zurück");
  151.        
  152.             new msg[64];
  153.  
  154.             format(msg, sizeof(msg), "Dem Coupon wurde %i Score hinzugefügt.", strval(inputtext));
  155.             SendClientMessage(playerid, COLOR_LYELLOW, msg);
  156.             Coupon[playerid][Score] = strval(inputtext);
  157.         }
  158.         ShowPlayerDialog(playerid, DIALOG_COUPONMENU, DIALOG_STYLE_LIST, "Coupon erstellen", "Geld hinzufügen\nScore hinzufügen\nWanteds hinzufügen\nWaffe hinzufügen\nRüstung hinzufügen\nSkin hinzufügen\nCoupon erstellen", "Auswählen", "Abbrechen");
  159.        
  160.         return 1;
  161.     }
  162.    
  163.     if(dialogid == DIALOG_WANTEDS)
  164.     {
  165.         if(response)
  166.         {
  167.             if(strval(inputtext) == 0) return ShowPlayerDialog(playerid, DIALOG_WANTEDS, DIALOG_STYLE_INPUT, "Wanteds hinzufügen", "Wie viele Wanteds sollen hinzugefügt werden?", "Hinzufügen", "Zurück");
  168.  
  169.             new msg[64];
  170.  
  171.             if(strval(inputtext) == 1) format(msg, sizeof(msg), "Dem Coupon wurde 1 Wanted hinzugefügt.");
  172.             else format(msg, sizeof(msg), "Dem Coupon wurden %i Wanteds hinzugefügt.", strval(inputtext));
  173.             SendClientMessage(playerid, COLOR_LYELLOW, msg);
  174.             Coupon[playerid][Wanteds] = strval(inputtext);
  175.  
  176.         }
  177.         ShowPlayerDialog(playerid, DIALOG_COUPONMENU, DIALOG_STYLE_LIST, "Coupon erstellen", "Geld hinzufügen\nScore hinzufügen\nWanteds hinzufügen\nWaffe hinzufügen\nRüstung hinzufügen\nSkin hinzufügen\nCoupon erstellen", "Auswählen", "Abbrechen");
  178.        
  179.         return 1;
  180.     }
  181.    
  182.     if(dialogid == DIALOG_WEAPONTYPE)
  183.     {
  184.         if(response)
  185.         {
  186.             new weaponid = strval(inputtext);
  187.  
  188.             if(weaponid > 0 && weaponid <= 46)
  189.             {
  190.                 Coupon[playerid][Weapontype] = weaponid;
  191.                 ShowPlayerDialog(playerid, DIALOG_WEAPONAMMO, DIALOG_STYLE_INPUT, "Munition auswählen", "Wie viel Munition soll der Waffe hinzugefügt werden?", "Hinzufügen", "Zurück");
  192.             }
  193.             else
  194.             {
  195.                 SendClientMessage(playerid, COLOR_RED, "Ungültige Waffen ID.");
  196.                 ShowPlayerDialog(playerid, DIALOG_WEAPONTYPE, DIALOG_STYLE_INPUT, "Waffentype auswählen", "Welche Waffe soll hinzugefügt werden? (ID)", "Weiter", "Zurück");
  197.             }
  198.         }
  199.         else
  200.         {
  201.             Coupon[playerid][Weapontype] = 0;
  202.             ShowPlayerDialog(playerid, DIALOG_COUPONMENU, DIALOG_STYLE_LIST, "Coupon erstellen", "Geld hinzufügen\nScore hinzufügen\nWanteds hinzufügen\nWaffe hinzufügen\nRüstung hinzufügen\nSkin hinzufügen\nCoupon erstellen", "Auswählen", "Abbrechen");
  203.         }
  204.        
  205.         return 1;
  206.     }
  207.    
  208.     if(dialogid == DIALOG_WEAPONAMMO)
  209.     {
  210.         if(response)
  211.         {
  212.             if(strval(inputtext) == 0) return ShowPlayerDialog(playerid, DIALOG_WEAPONAMMO, DIALOG_STYLE_INPUT, "Munition auswählen", "Wie viel Munition soll der Waffe hinzugefügt werden?", "Hinzufügen", "Zurück");
  213.        
  214.             new msg[64];
  215.             new weaponname[32];
  216.            
  217.             GetWeaponName(Coupon[playerid][Weapontype], weaponname, sizeof(weaponname));
  218.            
  219.             format(msg, sizeof(msg), "Dem Coupon wurde die Waffe %s mit %i Munition hinzugefügt,", weaponname, strval(inputtext));
  220.             SendClientMessage(playerid, COLOR_LYELLOW, msg);
  221.            
  222.             Coupon[playerid][Weaponammo] = strval(inputtext);
  223.             ShowPlayerDialog(playerid, DIALOG_COUPONMENU, DIALOG_STYLE_LIST, "Coupon erstellen", "Geld hinzufügen\nScore hinzufügen\nWanteds hinzufügen\nWaffe hinzufügen\nRüstung hinzufügen\nSkin hinzufügen\nCoupon erstellen", "Auswählen", "Abbrechen");
  224.         }
  225.         else ShowPlayerDialog(playerid, DIALOG_WEAPONTYPE, DIALOG_STYLE_INPUT, "Waffentype auswählen", "Welche Waffe soll hinzugefügt werden? (ID)", "Weiter", "Zurück");
  226.  
  227.         return 1;
  228.     }
  229.    
  230.     if(dialogid == DIALOG_ARMOUR)
  231.     {
  232.         if(response)
  233.         {
  234.             if(strval(inputtext) == 0)
  235.             {
  236.                 ShowPlayerDialog(playerid, DIALOG_ARMOUR, DIALOG_STYLE_INPUT, "Rüstung hinzufügen", "Wie viel Rüstung soll hinzugefügt werden?", "Hinzufügen", "Zurück");
  237.  
  238.                 return 1;
  239.             }
  240.             else
  241.             {
  242.                 new msg[64];
  243.  
  244.                 format(msg, sizeof(msg), "Dem Coupon wurde %i Rüstung hinzugefügt.", strval(inputtext));
  245.                 SendClientMessage(playerid, COLOR_LYELLOW, msg);
  246.                 Coupon[playerid][Armour] = strval(inputtext);
  247.             }
  248.         }
  249.         ShowPlayerDialog(playerid, DIALOG_COUPONMENU, DIALOG_STYLE_LIST, "Coupon erstellen", "Geld hinzufügen\nScore hinzufügen\nWanteds hinzufügen\nWaffe hinzufügen\nRüstung hinzufügen\nSkin hinzufügen\nCoupon erstellen", "Auswählen", "Abbrechen");
  250.  
  251.         return 1;
  252.     }
  253.    
  254.     if(dialogid == DIALOG_SKIN)
  255.     {
  256.         if(response)
  257.         {
  258.             if(strval(inputtext) < 0 || strval(inputtext) > 299)
  259.             {
  260.                 SendClientMessage(playerid, COLOR_RED, "Ungültige ID.");
  261.                 ShowPlayerDialog(playerid, DIALOG_SKIN, DIALOG_STYLE_INPUT, "Skin hinzufügen", "Welcher Skin soll hinzugefügt werden?", "Hinzufügen", "Zurück");
  262.  
  263.                 return 1;
  264.             }
  265.             else
  266.             {
  267.                 new msg[64];
  268.  
  269.                 format(msg, sizeof(msg), "Dem Coupon wurde der Skin %i hinzugefügt.", strval(inputtext));
  270.                 SendClientMessage(playerid, COLOR_LYELLOW, msg);
  271.                 Coupon[playerid][Skin] = strval(inputtext)+1;
  272.             }
  273.         }
  274.         ShowPlayerDialog(playerid, DIALOG_COUPONMENU, DIALOG_STYLE_LIST, "Coupon erstellen", "Geld hinzufügen\nScore hinzufügen\nWanteds hinzufügen\nWaffe hinzufügen\nRüstung hinzufügen\nSkin hinzufügen\nCoupon erstellen", "Auswählen", "Abbrechen");
  275.  
  276.         return 1;
  277.     }
  278.    
  279.     if(dialogid == DIALOG_CREATECOUPON)
  280.     {
  281.         if(response)
  282.         {
  283.             if(strlen(inputtext) != 0 && strlen(inputtext) < 4)
  284.             {
  285.                 SendClientMessage(playerid, COLOR_RED, "Der Code muss mindestens 4 Zeichen lang sein.");
  286.                 ShowPlayerDialog(playerid, DIALOG_CREATECOUPON, DIALOG_STYLE_INPUT, "Couponcode auswählen", "Wie soll der Couponcode lauten? (mind. 4 Zeichen)\n\nHinweis: Sollte kein Couponcode eingetragen werden, so wird ein zufälliger generiert.", "Erstellen", "Zurück");
  287.  
  288.                 return 1;
  289.             }
  290.             else
  291.             {
  292.                 new coupondata[64];
  293.                 new couponname[16];
  294.                 new msg[64];
  295.  
  296.                 if(strlen(inputtext) == 0)
  297.                 {
  298.                     couponname = GenerateCode();
  299.                     format(coupondata, sizeof(couponname), "%s.txt", couponname);
  300.                    
  301.                     while(fexist(coupondata))
  302.                     {
  303.                         couponname = GenerateCode();
  304.                         format(coupondata, sizeof(couponname), "%s.txt", couponname);
  305.                     }
  306.                 }
  307.                 else
  308.                 {
  309.                     format(couponname, sizeof(couponname), inputtext);
  310.                     format(coupondata, sizeof(couponname), "%s.txt", couponname);
  311.                 }
  312.                
  313.  
  314.                 dini_Create(coupondata);
  315.                 dini_IntSet(coupondata, "Geld", Coupon[playerid][Money]);
  316.                 dini_IntSet(coupondata, "Score", Coupon[playerid][Score]);
  317.                 dini_IntSet(coupondata, "Wanteds", Coupon[playerid][Wanteds]);
  318.                 dini_IntSet(coupondata, "Waffe", Coupon[playerid][Weapontype]);
  319.                 dini_IntSet(coupondata, "Munition", Coupon[playerid][Weaponammo]);
  320.                 dini_IntSet(coupondata, "Rüstung", Coupon[playerid][Armour]);
  321.                 dini_IntSet(coupondata, "Skin", Coupon[playerid][Skin]);
  322.  
  323.                 format(msg, sizeof(msg), "Der Coupon %s wurde erfolgreich erstellt.", couponname);
  324.                 SendClientMessage(playerid, COLOR_LYELLOW, msg);
  325.                 ResetCouponSettings(playerid);
  326.             }
  327.         }
  328.         else ShowPlayerDialog(playerid, DIALOG_COUPONMENU, DIALOG_STYLE_LIST, "Coupon erstellen", "Geld hinzufügen\nScore hinzufügen\nWanteds hinzufügen\nWaffe hinzufügen\nRüstung hinzufügen\nSkin hinzufügen\nCoupon erstellen", "Auswählen", "Abbrechen");
  329.        
  330.         return 1;
  331.     }
  332.    
  333.     if(dialogid == DIALOG_COUPON)
  334.     {
  335.         if(response)
  336.         {
  337.             new coupondata[16];
  338.            
  339.             format(coupondata, sizeof(coupondata), "%s.txt", inputtext);
  340.  
  341.             if(fexist(coupondata))
  342.             {
  343.                 new msg[128];
  344.                 new score = dini_Int(coupondata, "Score");
  345.                 new money = dini_Int(coupondata, "Geld");
  346.                 new wanteds = dini_Int(coupondata, "Wanteds");
  347.                 new weapontype = dini_Int(coupondata, "Waffe");
  348.                 new weaponammo = dini_Int(coupondata, "Munition");
  349.                 new Float:armour = dini_Int(coupondata, "Rüstung");
  350.                 new skin = dini_Int(coupondata, "Skin");
  351.                
  352.                 format(msg, sizeof(msg), "-------- Coupon %s wurde eingelöst --------", inputtext);
  353.                 SendClientMessage(playerid, COLOR_GREEN, msg);
  354.                
  355.                 if(score != 0)
  356.                 {
  357.                     SetPlayerScore(playerid, GetPlayerScore(playerid)+score);
  358.                    
  359.                     format(msg, sizeof(msg), "Du hast %i Score erhalten", score);
  360.                     SendClientMessage(playerid, COLOR_LYELLOW, msg);
  361.                 }
  362.  
  363.                 if(money != 0)
  364.                 {
  365.                     GivePlayerMoney(playerid, money);
  366.                    
  367.                     format(msg, sizeof(msg), "Du hast %i$ erhalten.", money);
  368.                     SendClientMessage(playerid, COLOR_LYELLOW, msg);
  369.                 }
  370.                
  371.                 if(wanteds != 0)
  372.                 {
  373.                     SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid)+wanteds);
  374.  
  375.                     if(wanteds == 1) format(msg, sizeof(msg), "Du hast 1 Wanted erhalten.");
  376.                     else format(msg, sizeof(msg), "Du hast %i Wanteds erhalten.", wanteds);
  377.                     SendClientMessage(playerid, COLOR_LYELLOW, msg);
  378.                 }
  379.                
  380.                 if(weapontype != 0)
  381.                 {
  382.                     new weaponname[32];
  383.                
  384.                     GivePlayerWeapon(playerid, weapontype, weaponammo);
  385.                    
  386.                     GetWeaponName(weapontype, weaponname, sizeof(weaponname));
  387.                     format(msg, sizeof(msg), "Du hast die Waffe %s mit %i Munition erhalten.", weaponname, weaponammo);
  388.                     SendClientMessage(playerid, COLOR_LYELLOW, msg);
  389.                 }
  390.                
  391.                 if(armour != 0)
  392.                 {
  393.                     new Float:curArmour;
  394.  
  395.                     GetPlayerArmour(playerid, curArmour);
  396.                     SetPlayerArmour(playerid, curArmour+armour);
  397.                    
  398.                     format(msg, sizeof(msg), "Du hast %i Rüstung erhalten.", floatround(armour));
  399.                     SendClientMessage(playerid, COLOR_LYELLOW, msg);
  400.                 }
  401.                
  402.                 if(skin != 0)
  403.                 {
  404.                     SetPlayerSkin(playerid, skin-1);
  405.                    
  406.                     format(msg, sizeof(msg), "Du hast den Skin %i erhalten.", skin-1);
  407.                     SendClientMessage(playerid, COLOR_LYELLOW, msg);
  408.                 }
  409.                
  410.                 CouponBlock[playerid] = 0;
  411.                 fremove(coupondata);
  412.             }
  413.             else
  414.             {
  415.                 SendClientMessage(playerid, COLOR_RED, "Ungültiger Coupon.");
  416.                 CouponBlock[playerid]++;
  417.  
  418.                 if(CouponBlock[playerid] == 3)
  419.                 {
  420.                     SendClientMessage(playerid, COLOR_RED, "Du hast eine Couponsperre erhalten.");
  421.                     SetTimerEx("Block", 60000*BLOCK_INTERVAL, false, "i", playerid);
  422.                 }
  423.             }
  424.         }
  425.  
  426.         return 1;
  427.     }
  428.  
  429.     return 1;
  430. }
  431.  
  432. stock ResetCouponSettings(playerid)
  433. {
  434.     Coupon[playerid][Money] = 0;
  435.     Coupon[playerid][Score] = 0;
  436.     Coupon[playerid][Wanteds] = 0;
  437.     Coupon[playerid][Weapontype] = 0;
  438.     Coupon[playerid][Weaponammo] = 0;
  439.     Coupon[playerid][Armour] = 0;
  440.     Coupon[playerid][Skin] = 0;
  441. }
  442.  
  443. stock GenerateCode()
  444. {
  445.     new zeichen[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
  446.     new length = random(3) + 5;
  447.     new index;
  448.     new code[10];
  449.    
  450.     for(new i = 0; i < length; i++)
  451.     {
  452.         index = random(sizeof(zeichen)-1);
  453.         code[i] = zeichen[index];
  454.     }
  455.    
  456.     return code;
  457. }
  458.  
  459. public Block(playerid)
  460. {
  461.     CouponBlock[playerid] = 0;
  462. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement