Advertisement
Guest User

Untitled

a guest
Jun 8th, 2010
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 25.57 KB | None | 0 0
  1. // * ViruZZzZ_ChiLLLs Cookie System :) * //
  2. // |
  3. // * Some notes :
  4. // --- First : I added a little bit killing spree system ;) you can define their cookie award below.
  5. // --- Second : You can define how many money can they buy a cookie right below.
  6. // --- Third : Change the things that has the sign (CHANGE ME) on them.
  7. // --- Fourth : Enjoy your Cookie System ;)
  8. // |
  9. // * Updates :
  10. // --- First Release (June 07, 2010)
  11.  
  12.  
  13.  
  14. #include <a_samp>
  15. #include <Dini>
  16.  
  17. #define PlayerFile                  "Cookie System/%s.ini"
  18. #pragma unused strtok
  19.  
  20.  
  21. #define cookieD 187
  22.  
  23. // (CHANGE THIS) Buy cookies worth :
  24. #define C1_COOKIES 100 // 1 cookies is worth $100
  25. #define C3_COOKIES 300
  26. #define C5_COOKIES 500
  27. #define C10_COOKIES 1000
  28. #define C15_COOKIES 1500
  29. #define C20_COOKIES 2000
  30.  
  31. // (CHANGE THIS) Sell cookies worth :
  32. #define S1_COOKIES 50
  33. #define S3_COOKIES 150
  34. #define S5_COOKIES 250
  35. #define S10_COOKIES 500
  36. #define S15_COOKIES 750
  37. #define S20_COOKIES 1000
  38.  
  39. // (CHANGE THIS) Cookie Reward for killingsprees
  40. #define KillingSpree3 5 // for 3 killing spree the player gets 3 cookies
  41. #define KillingSpree5 8
  42. #define KillingSpree10 15
  43. #define KillingSpree15 20
  44. #define KillingSpree20 30
  45. #define KillingSpree35 50
  46. #define KillingSpree50 100
  47.  
  48. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  49.  
  50.  
  51. #define Red 0xFF0000FF
  52. #define Grey 0xAFAFAFAA
  53. #define Green 0x33AA33AA
  54. #define Yellow 0xFFFF00AA
  55. #define White 0xFFFFFFAA
  56. #define Blue 0x0000BBAA
  57. #define Lightblue 0x33CCFFAA
  58. #define Orange 0xFF9900AA
  59. #define Lime 0x10F441AA
  60. #define Magenta 0xFF00FFFFT
  61. #define Navy 0x000080AA
  62. #define Aqua 0xF0F8FFAA
  63. #define Crimson 0xDC143CAA
  64. #define Black 0x000000AA
  65. #define Brown 0XA52A2AAA
  66. #define Gold 0xB8860BAA
  67. #define Limegreen 0x32CD32AA
  68.  
  69.  
  70.  
  71. new KillingSpree[MAX_PLAYERS];
  72.  
  73.  
  74. enum PLAYER_MAIN
  75. {
  76.    Cookies
  77. }
  78.  
  79.  
  80. new giveplayerid, amount;
  81. new pInfo[MAX_PLAYERS][PLAYER_MAIN];
  82. public OnPlayerConnect(playerid)
  83. {
  84.     new file[100],Name[MAX_PLAYER_NAME],Ip[16]; GetPlayerName(playerid,Name,sizeof(Name)); GetPlayerIp(playerid,Ip,sizeof(Ip)); format(file,sizeof(file),PlayerFile,Name);
  85.     if(!dini_Exists(file)) {
  86.         dini_Create(file);
  87.         dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  88.     }
  89.         else if(dini_Exists(file))
  90.         {
  91.     pInfo[playerid][Cookies] = dini_Int(file,"Cookies");
  92.         }
  93.     return 1;
  94. }
  95.  
  96. public OnPlayerDisconnect(playerid, reason)
  97. {
  98.     new file[100],Name[MAX_PLAYER_NAME],Ip[16]; GetPlayerName(playerid,Name,sizeof(Name)); GetPlayerIp(playerid,Ip,sizeof(Ip)); format(file,sizeof(file),PlayerFile,Name);
  99.     dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  100.     return 1;
  101. }
  102.  
  103. public OnPlayerCommandText(playerid, cmdtext[])
  104. {
  105.     dcmd(givecookies, 11, cmdtext);
  106.     dcmd(setcookies, 10, cmdtext);
  107.     dcmd(mycookies, 9, cmdtext);
  108.     dcmd(cookiesof, 9, cmdtext);
  109.     dcmd(buycookies, 10, cmdtext);
  110.     dcmd(eatcookies, 10, cmdtext);
  111.     dcmd(cookiehelp, 10, cmdtext);
  112.     dcmd(sellcookies, 10, cmdtext);
  113.     return 0;
  114. }
  115.  
  116. dcmd_cookiehelp(playerid, params[])
  117. {
  118. #pragma unused params
  119. if(IsPlayerAdmin(playerid) == 1) return ShowPlayerDialog(playerid, cookieD+1, DIALOG_STYLE_MSGBOX, "Cookie Help", "/setcookies [playerid] [amount]\n/givecookies [playerid] [amount]\n/cookiesof [playerid]\n/eatcookies - You will gain 10HP\n/mycookies - Will display your total cookies.\n/buycookies - You will buy cookies.\n/sellcookies - You can sell your cookies.", "Done", "Exit");
  120. ShowPlayerDialog(playerid, cookieD+2, DIALOG_STYLE_MSGBOX, "Cookie Help", "/givecookies [playerid] [amount]\n/cookiesof [playerid]\n/eatcookies - You will gain 10HP\n/mycookies - Will display your total cookies.\n/buycookies - You will buy cookies.\n/sellcookies - You can sell your cookies.", "Done", "Exit");
  121. return 1;
  122. }
  123. public OnPlayerDeath(playerid, killerid, reason)
  124. {
  125.     SendDeathMessage(playerid, killerid, reason);
  126.     KillingSpree[playerid] = 0;
  127.     KillingSpree[killerid]++;
  128.     new file[100],Name[MAX_PLAYER_NAME],Ip[16],name[MAX_PLAYER_NAME]; GetPlayerName(giveplayerid, name, sizeof(name));GetPlayerName(playerid,Name,sizeof(Name)); GetPlayerIp(playerid,Ip,sizeof(Ip)); format(file,sizeof(file),PlayerFile,Name);
  129.     if(KillingSpree[killerid] == 50)
  130.      {
  131.       new pName[MAX_PLAYER_NAME]; GetPlayerName(killerid,pName,MAX_PLAYER_NAME);
  132.       new string[128]; format(string,sizeof(string),"%s is on a killing spree! (Kills : 50) (Reward : $60000 + %d Cookies)",pName, KillingSpree50);
  133.       SendClientMessageToAll(Red, string);
  134.       pInfo[playerid][Cookies] += KillingSpree50;
  135.       dini_IntSet(file,"Cookies", pInfo[killerid][Cookies]);
  136.      }
  137.  
  138.     if(KillingSpree[killerid] == 35)
  139.      {
  140.       new pName[MAX_PLAYER_NAME]; GetPlayerName(killerid,pName,MAX_PLAYER_NAME);
  141.       new string[128]; format(string,sizeof(string),"%s is on a killing spree! (Kills : 35) (Reward : $25000 + %d Cookies)",pName, KillingSpree35);
  142.       SendClientMessageToAll(Red, string);
  143.       pInfo[playerid][Cookies] += KillingSpree35;
  144.       dini_IntSet(file,"Cookies", pInfo[killerid][Cookies]);
  145.      }
  146.      
  147.     if(KillingSpree[killerid] == 20)
  148.      {
  149.       new pName[MAX_PLAYER_NAME]; GetPlayerName(killerid,pName,MAX_PLAYER_NAME);
  150.       new string[128]; format(string,sizeof(string),"%s is on a killing spree! (Kills : 20) (Reward : $25000 + %d Cookies)",pName, KillingSpree20);
  151.       SendClientMessageToAll(Red, string);
  152.       pInfo[playerid][Cookies] += KillingSpree20;
  153.       dini_IntSet(file,"Cookies", pInfo[killerid][Cookies]);
  154.      }
  155.  
  156.     if(KillingSpree[killerid] == 15)
  157.      {
  158.       new pName[MAX_PLAYER_NAME]; GetPlayerName(killerid,pName,MAX_PLAYER_NAME);
  159.       new string[128]; format(string,sizeof(string),"%s is on a killing spree! (Kills : 15) (Reward : $15000 + %d cookies)",pName, KillingSpree15);
  160.       SendClientMessageToAll(Red, string);
  161.       pInfo[playerid][Cookies] += KillingSpree15;
  162.       dini_IntSet(file,"Cookies", pInfo[killerid][Cookies]);
  163.      }
  164.  
  165.     if(KillingSpree[killerid] == 10)
  166.      {
  167.       new pName[MAX_PLAYER_NAME]; GetPlayerName(killerid,pName,MAX_PLAYER_NAME);
  168.       new string[128]; format(string,sizeof(string),"%s is on a killing spree! (Kills : 10) (Reward : $10000 + %d cookies)",pName, KillingSpree10);
  169.       SendClientMessageToAll(Red, string);
  170.       pInfo[playerid][Cookies] += KillingSpree10;
  171.       dini_IntSet(file,"Cookies", pInfo[killerid][Cookies]);
  172.      }
  173.  
  174.     if(KillingSpree[killerid] == 5)
  175.      {
  176.       new pName[MAX_PLAYER_NAME]; GetPlayerName(killerid,pName,MAX_PLAYER_NAME);
  177.       new string[128]; format(string,sizeof(string),"%s is on a killing spree! (Kills : 5) (Reward : $5000 + %d cookies)",pName, KillingSpree5);
  178.       SendClientMessageToAll(Red, string);
  179.       pInfo[playerid][Cookies] += KillingSpree5;
  180.       dini_IntSet(file,"Cookies", pInfo[killerid][Cookies]);
  181.      }
  182.  
  183.  
  184.     if(KillingSpree[killerid] == 3)
  185.      {
  186.       new pName[MAX_PLAYER_NAME]; GetPlayerName(killerid,pName,MAX_PLAYER_NAME);
  187.       new string[128]; format(string,sizeof(string),"%s is on a killing spree! (Kills : 3) (Reward : $1500 + %d cookies)",pName, KillingSpree3);
  188.       SendClientMessageToAll(Red, string);
  189.       pInfo[playerid][Cookies] += KillingSpree3;
  190.       dini_IntSet(file,"Cookies", pInfo[killerid][Cookies]);
  191.      }
  192.     return 1;
  193. }
  194. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  195. {
  196.   new string[156],file[100],Name[MAX_PLAYER_NAME],Ip[16],name[MAX_PLAYER_NAME]; GetPlayerName(giveplayerid, name, sizeof(name));GetPlayerName(playerid,Name,sizeof(Name)); GetPlayerIp(playerid,Ip,sizeof(Ip)); format(file,sizeof(file),PlayerFile,Name);
  197.   if(dialogid == cookieD && response)
  198.   {
  199.    switch(listitem)
  200.    {
  201.    case 0:
  202.    {
  203.    if( GetPlayerMoney(playerid)  <  C1_COOKIES) return SendClientMessage(playerid, Red, "ERROR : You dont have enough money to buy a cookie!");
  204.    pInfo[playerid][Cookies] += 1;
  205.    GivePlayerMoney(playerid, -C1_COOKIES);
  206.    dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  207.    SendClientMessage(playerid, Limegreen, "You have succesfully bought 1 cookie!");
  208.    format(string, sizeof(string), "1 Cookie        [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", C1_COOKIES, C3_COOKIES, C5_COOKIES, C10_COOKIES, C15_COOKIES, C20_COOKIES);
  209.    ShowPlayerDialog(playerid, cookieD, DIALOG_STYLE_LIST, "Buy Cookies", string, "Buy", "Exit");
  210.    }
  211.    case 1:
  212.    {
  213.    if( GetPlayerMoney(playerid)  <  C3_COOKIES) return SendClientMessage(playerid, Red, "ERROR : You dont have enough money to buy a cookie!");
  214.    pInfo[playerid][Cookies] += 3;
  215.    GivePlayerMoney(playerid, -C3_COOKIES);
  216.    dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  217.    SendClientMessage(playerid, Limegreen, "You have succesfully bought 3 cookies!");
  218.    format(string, sizeof(string), "1 Cookie        [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", C1_COOKIES, C3_COOKIES, C5_COOKIES, C10_COOKIES, C15_COOKIES, C20_COOKIES);
  219.    ShowPlayerDialog(playerid, cookieD, DIALOG_STYLE_LIST, "Buy Cookies", string, "Buy", "Exit");
  220.    }
  221.    case 2:
  222.    {
  223.    if( GetPlayerMoney(playerid)  <  C5_COOKIES) return SendClientMessage(playerid, Red, "ERROR : You dont have enough money to buy a cookie!");
  224.    pInfo[playerid][Cookies] += 5;
  225.    GivePlayerMoney(playerid, -C5_COOKIES);
  226.    dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  227.    SendClientMessage(playerid, Limegreen, "You have succesfully bought 5 cookies!");
  228.    format(string, sizeof(string), "1 Cookie        [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", C1_COOKIES, C3_COOKIES, C5_COOKIES, C10_COOKIES, C15_COOKIES, C20_COOKIES);
  229.    ShowPlayerDialog(playerid, cookieD, DIALOG_STYLE_LIST, "Buy Cookies", string, "Buy", "Exit");
  230.    }
  231.    case 3:
  232.    {
  233.    if( GetPlayerMoney(playerid)  <  C10_COOKIES) return SendClientMessage(playerid, Red, "ERROR : You dont have enough money to buy a cookie!");
  234.    pInfo[playerid][Cookies] += 10;
  235.    GivePlayerMoney(playerid, -C10_COOKIES);
  236.    dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  237.    SendClientMessage(playerid, Limegreen, "You have succesfully bought 10 cookies!");
  238.    format(string, sizeof(string), "1 Cookie        [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", C1_COOKIES, C3_COOKIES, C5_COOKIES, C10_COOKIES, C15_COOKIES, C20_COOKIES);
  239.    ShowPlayerDialog(playerid, cookieD, DIALOG_STYLE_LIST, "Buy Cookies", string, "Buy", "Exit");
  240.    }
  241.    case 4:
  242.    {
  243.    if( GetPlayerMoney(playerid)  <  C15_COOKIES) return SendClientMessage(playerid, Red, "ERROR : You dont have enough money to buy a cookie!");
  244.    pInfo[playerid][Cookies] += 15;
  245.    GivePlayerMoney(playerid, -C15_COOKIES);
  246.    dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  247.    SendClientMessage(playerid, Limegreen, "You have succesfully bought 15 cookies!");
  248.    format(string, sizeof(string), "1 Cookie        [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", C1_COOKIES, C3_COOKIES, C5_COOKIES, C10_COOKIES, C15_COOKIES, C20_COOKIES);
  249.    ShowPlayerDialog(playerid, cookieD, DIALOG_STYLE_LIST, "Buy Cookies", string, "Buy", "Exit");
  250.    }
  251.    case 5:
  252.    {
  253.    if( GetPlayerMoney(playerid)  <  C20_COOKIES) return SendClientMessage(playerid, Red, "ERROR : You dont have enough money to buy a cookie!");
  254.    pInfo[playerid][Cookies] += 20;
  255.    GivePlayerMoney(playerid, -C20_COOKIES);
  256.    dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  257.    SendClientMessage(playerid, Limegreen, "You have succesfully bought 20 cookies!");
  258.    format(string, sizeof(string), "1 Cookie        [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", C1_COOKIES, C3_COOKIES, C5_COOKIES, C10_COOKIES, C15_COOKIES, C20_COOKIES);
  259.    ShowPlayerDialog(playerid, cookieD, DIALOG_STYLE_LIST, "Buy Cookies", string, "Buy", "Exit");
  260.    }
  261.    }
  262.    }
  263.    
  264.   if(dialogid == cookieD+10 && response)
  265.   {
  266.    switch(listitem)
  267.    {
  268.    case 0:
  269.    {
  270.    if(pInfo[playerid][Cookies] < 1) return SendClientMessage(playerid, Red, "ERROR : You dont have enough cookies to sell!");
  271.    pInfo[playerid][Cookies] -= 1;
  272.    GivePlayerMoney(playerid, S1_COOKIES);
  273.    dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  274.    SendClientMessage(playerid, Limegreen, "You have succesfully sold 1 cookie!");
  275.    format(string, sizeof(string), "1 Cookie        [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", S1_COOKIES, S3_COOKIES, S5_COOKIES, S10_COOKIES, S15_COOKIES, S20_COOKIES);
  276.    ShowPlayerDialog(playerid, cookieD+10, DIALOG_STYLE_LIST, "Sell Cookies", string, "Sell", "Exit");
  277.    }
  278.    case 1:
  279.    {
  280.    if(pInfo[playerid][Cookies] < 3) return SendClientMessage(playerid, Red, "ERROR : You dont have enough cookies to sell!");
  281.    pInfo[playerid][Cookies] -= 3;
  282.    GivePlayerMoney(playerid, S3_COOKIES);
  283.    dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  284.    SendClientMessage(playerid, Limegreen, "You have succesfully sold 3 cookies!");
  285.    format(string, sizeof(string), "1 Cookie        [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", S1_COOKIES, S3_COOKIES, S5_COOKIES, S10_COOKIES, S15_COOKIES, S20_COOKIES);
  286.    ShowPlayerDialog(playerid, cookieD+10, DIALOG_STYLE_LIST, "Sell Cookies", string, "Sell", "Exit");
  287.    }
  288.    case 2:
  289.    {
  290.    if(pInfo[playerid][Cookies] < 5) return SendClientMessage(playerid, Red, "ERROR : You dont have enough cookies to sell!");
  291.    pInfo[playerid][Cookies] -= 5;
  292.    GivePlayerMoney(playerid, S5_COOKIES);
  293.    dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  294.    SendClientMessage(playerid, Limegreen, "You have succesfully sold 5 cookies!");
  295.    format(string, sizeof(string), "1 Cookie        [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", S1_COOKIES, S3_COOKIES, S5_COOKIES, S10_COOKIES, S15_COOKIES, S20_COOKIES);
  296.    ShowPlayerDialog(playerid, cookieD+10, DIALOG_STYLE_LIST, "Sell Cookies", string, "Sell", "Exit");
  297.    }
  298.    case 3:
  299.    {
  300.    if(pInfo[playerid][Cookies] < 10) return SendClientMessage(playerid, Red, "ERROR : You dont have enough cookies to sell!");
  301.    pInfo[playerid][Cookies] -= 10;
  302.    GivePlayerMoney(playerid, S10_COOKIES);
  303.    dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  304.    SendClientMessage(playerid, Limegreen, "You have succesfully sold 10 cookies!");
  305.    format(string, sizeof(string), "1 Cookie        [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", S1_COOKIES, S3_COOKIES, S5_COOKIES, S10_COOKIES, S15_COOKIES, S20_COOKIES);
  306.    ShowPlayerDialog(playerid, cookieD+10, DIALOG_STYLE_LIST, "Sell Cookies", string, "Sell", "Exit");
  307.    }
  308.    case 4:
  309.    {
  310.    if(pInfo[playerid][Cookies] < 15) return SendClientMessage(playerid, Red, "ERROR : You dont have enough cookies to sell!");
  311.    pInfo[playerid][Cookies] -= 15;
  312.    GivePlayerMoney(playerid, S15_COOKIES);
  313.    dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  314.    SendClientMessage(playerid, Limegreen, "You have succesfully sold 15 cookies!");
  315.    format(string, sizeof(string), "1 Cookie        [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", S1_COOKIES, S3_COOKIES, S5_COOKIES, S10_COOKIES, S15_COOKIES, S20_COOKIES);
  316.    ShowPlayerDialog(playerid, cookieD+10, DIALOG_STYLE_LIST, "Sell Cookies", string, "Sell", "Exit");
  317.    }
  318.    case 5:
  319.    {
  320.    if(pInfo[playerid][Cookies] < 20) return SendClientMessage(playerid, Red, "ERROR : You dont have enough cookies to sell!");
  321.    pInfo[playerid][Cookies] -= 20;
  322.    GivePlayerMoney(playerid, S20_COOKIES);
  323.    dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  324.    SendClientMessage(playerid, Limegreen, "You have succesfully sold 20 cookies!");
  325.    format(string, sizeof(string), "1 Cookie        [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", S1_COOKIES, S3_COOKIES, S5_COOKIES, S10_COOKIES, S15_COOKIES, S20_COOKIES);
  326.    ShowPlayerDialog(playerid, cookieD+10, DIALOG_STYLE_LIST, "Sell Cookies", string, "Sell", "Exit");
  327.    }
  328.    }
  329.    }
  330.   return 1;
  331. }
  332.  
  333. dcmd_sellcookies(playerid, params[])
  334. {
  335. #pragma unused params
  336. new string[156];
  337. format(string, sizeof(string), "1 Cookie       [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", S1_COOKIES, S3_COOKIES, S5_COOKIES, S10_COOKIES, S15_COOKIES, S20_COOKIES);
  338. ShowPlayerDialog(playerid, cookieD+10, DIALOG_STYLE_LIST, "Sell Cookies", string, "Buy", "Exit");
  339. return 1;
  340. }
  341.  
  342. dcmd_buycookies(playerid, params[])
  343. {
  344. #pragma unused params
  345. new string[156];
  346. format(string, sizeof(string), "1 Cookie       [$%d]\n3 Cookies      [$%d]\n5 Cookies      [$%d]\n10 Cookies    [$%d]\n15 Cookies    [$%d]\n20 Cookies    [$%d]", C1_COOKIES, C3_COOKIES, C5_COOKIES, C10_COOKIES, C15_COOKIES, C20_COOKIES);
  347. ShowPlayerDialog(playerid, cookieD, DIALOG_STYLE_LIST, "Buy Cookies", string, "Buy", "Exit");
  348. return 1;
  349. }
  350.  
  351. dcmd_givecookies(playerid, params[])
  352. {
  353. if(sscanf(params, "ud", giveplayerid, amount)) SendClientMessage(playerid, Orange, "USAGE : /givecookie [playerid] [amount]");
  354. else if(giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, Red, "ERROR : That player is not connected!");
  355. else if(giveplayerid == playerid) SendClientMessage(playerid, Red, "ERROR : You cant send yourself a cookie!");
  356. else if(amount > pInfo[playerid][Cookies]) SendClientMessage(playerid, Red, "ERROR : You dont have that amount of cookie!");
  357. else
  358. {
  359. new string[156],file[100],Name[MAX_PLAYER_NAME],Ip[16],name[MAX_PLAYER_NAME]; GetPlayerName(giveplayerid, name, sizeof(name));GetPlayerName(playerid,Name,sizeof(Name)); GetPlayerIp(playerid,Ip,sizeof(Ip)); format(file,sizeof(file),PlayerFile,Name);
  360. format(string, sizeof(string), "SERVER : You have succesfully sent %d cookies to %s!", amount, name);
  361. SendClientMessage(playerid, Limegreen, string);
  362. format(string, sizeof(string), "SERVER : %s has given you %d cookies!", Name, amount);
  363. SendClientMessage(giveplayerid, Limegreen, string);
  364. pInfo[giveplayerid][Cookies] += amount;
  365. pInfo[playerid][Cookies] -= amount;
  366. dini_IntSet(file,"Cookies", pInfo[giveplayerid][Cookies]);
  367. dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  368. }
  369. return 1;
  370. }
  371.  
  372. dcmd_eatcookies(playerid, params[])
  373. {
  374. #pragma unused params
  375. new Float:health;
  376. GetPlayerHealth(playerid, health);
  377. if(health == 100) return SendClientMessage(playerid, Red, "ERROR : You already have a full health!");
  378. if(health >= 100) return SetPlayerHealth(playerid, 100);
  379. SetPlayerHealth(playerid, health+10);
  380. pInfo[playerid][Cookies] -= 1;
  381. new file[100],Name[MAX_PLAYER_NAME],Ip[16]; GetPlayerName(playerid,Name,sizeof(Name)); GetPlayerIp(playerid,Ip,sizeof(Ip)); format(file,sizeof(file),PlayerFile,Name);
  382. dini_IntSet(file,"Cookies", pInfo[playerid][Cookies]);
  383. return 1;
  384. }
  385.  
  386. dcmd_cookiesof(playerid, params[])
  387. {
  388. if(sscanf(params, "u", giveplayerid)) SendClientMessage(playerid, Orange, "USAGE : /cookiesof [playerid]");
  389. else if(giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, Red, "ERROR : That player is not connected!");
  390. else if(giveplayerid == playerid) SendClientMessage(playerid, Red, "ERROR : Use /mycookies to check out how many cookies you have!");
  391. else
  392. {
  393. new string[156], str[MAX_PLAYER_NAME]; GetPlayerName(giveplayerid, str, sizeof(str));
  394. format(string, sizeof(string), "SERVER : Player %s has %d!", str, pInfo[giveplayerid][Cookies]);
  395. SendClientMessage(playerid, Limegreen, string);
  396. }
  397. return 1;
  398. }
  399.  
  400. dcmd_mycookies(playerid, params[])
  401. {
  402. #pragma unused params
  403. new string[126];
  404. format(string, sizeof(string), "SERVER : You have %d cookies!", pInfo[playerid][Cookies]);
  405. SendClientMessage(playerid, Limegreen, string);
  406. return 1;
  407. }
  408.  
  409. dcmd_setcookies(playerid, params[])
  410. {
  411. if(IsPlayerAdmin(playerid) == 0) return SendClientMessage(playerid, Red, "ERROR : Only admins can use that command!");
  412. if(sscanf(params, "ud", giveplayerid, amount)) SendClientMessage(playerid, Orange, "USAGE : /setcookie [playerid] [amount]");
  413. else if(giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, Red, "ERROR : That player is not connected!");
  414. else
  415. {
  416. new string[156],file[100],Name[MAX_PLAYER_NAME],Ip[16],name[MAX_PLAYER_NAME]; GetPlayerName(giveplayerid, name, sizeof(name));GetPlayerName(playerid,Name,sizeof(Name)); GetPlayerIp(playerid,Ip,sizeof(Ip)); format(file,sizeof(file),PlayerFile,Name);
  417. format(string, sizeof(string), "SERVER : You have succesfully setted %s cookies to %d!", name, amount);
  418. SendClientMessage(playerid, Limegreen, string);
  419. format(string, sizeof(string), "SERVER : Admin %s has setted your cookies to %d!", Name, amount);
  420. SendClientMessage(giveplayerid, Limegreen, string);
  421. pInfo[giveplayerid][Cookies] = amount;
  422. dini_IntSet(file,"Cookies", pInfo[giveplayerid][Cookies]);
  423. }
  424. return 1;
  425. }
  426.  
  427. stock sscanf(string[], format[], {Float,_}:...)
  428. {
  429.     #if defined isnull
  430.         if (isnull(string))
  431.     #else
  432.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  433.     #endif
  434.         {
  435.             return format[0];
  436.         }
  437.     #pragma tabsize 4
  438.     new
  439.         formatPos = 0,
  440.         stringPos = 0,
  441.         paramPos = 2,
  442.         paramCount = numargs(),
  443.         delim = ' ';
  444.     while (string[stringPos] && string[stringPos] <= ' ')
  445.     {
  446.         stringPos++;
  447.     }
  448.     while (paramPos < paramCount && string[stringPos])
  449.     {
  450.         switch (format[formatPos++])
  451.         {
  452.             case '\0':
  453.             {
  454.                 return 0;
  455.             }
  456.             case 'i', 'd':
  457.             {
  458.                 new
  459.                     neg = 1,
  460.                     num = 0,
  461.                     ch = string[stringPos];
  462.                 if (ch == '-')
  463.                 {
  464.                     neg = -1;
  465.                     ch = string[++stringPos];
  466.                 }
  467.                 do
  468.                 {
  469.                     stringPos++;
  470.                     if ('0' <= ch <= '9')
  471.                     {
  472.                         num = (num * 10) + (ch - '0');
  473.                     }
  474.                     else
  475.                     {
  476.                         return -1;
  477.                     }
  478.                 }
  479.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  480.                 setarg(paramPos, 0, num * neg);
  481.             }
  482.             case 'h', 'x':
  483.             {
  484.                 new
  485.                     num = 0,
  486.                     ch = string[stringPos];
  487.                 do
  488.                 {
  489.                     stringPos++;
  490.                     switch (ch)
  491.                     {
  492.                         case 'x', 'X':
  493.                         {
  494.                             num = 0;
  495.                             continue;
  496.                         }
  497.                         case '0' .. '9':
  498.                         {
  499.                             num = (num << 4) | (ch - '0');
  500.                         }
  501.                         case 'a' .. 'f':
  502.                         {
  503.                             num = (num << 4) | (ch - ('a' - 10));
  504.                         }
  505.                         case 'A' .. 'F':
  506.                         {
  507.                             num = (num << 4) | (ch - ('A' - 10));
  508.                         }
  509.                         default:
  510.                         {
  511.                             return -1;
  512.                         }
  513.                     }
  514.                 }
  515.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  516.                 setarg(paramPos, 0, num);
  517.             }
  518.             case 'c':
  519.             {
  520.                 setarg(paramPos, 0, string[stringPos++]);
  521.             }
  522.             case 'f':
  523.             {
  524.  
  525.                 new changestr[16], changepos = 0, strpos = stringPos;
  526.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  527.                 {
  528.                     changestr[changepos++] = string[strpos++];
  529.                     }
  530.                 changestr[changepos] = '\0';
  531.                 setarg(paramPos,0,_:floatstr(changestr));
  532.             }
  533.             case 'p':
  534.             {
  535.                 delim = format[formatPos++];
  536.                 continue;
  537.             }
  538.             case '\'':
  539.             {
  540.                 new
  541.                     end = formatPos - 1,
  542.                     ch;
  543.                 while ((ch = format[++end]) && ch != '\'') {}
  544.                 if (!ch)
  545.                 {
  546.                     return -1;
  547.                 }
  548.                 format[end] = '\0';
  549.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  550.                 {
  551.                     if (format[end + 1])
  552.                     {
  553.                         return -1;
  554.                     }
  555.                     return 0;
  556.                 }
  557.                 format[end] = '\'';
  558.                 stringPos = ch + (end - formatPos);
  559.                 formatPos = end + 1;
  560.             }
  561.             case 'u':
  562.             {
  563.                 new
  564.                     end = stringPos - 1,
  565.                     id = 0,
  566.                     bool:num = true,
  567.                     ch;
  568.                 while ((ch = string[++end]) && ch != delim)
  569.                 {
  570.                     if (num)
  571.                     {
  572.                         if ('0' <= ch <= '9')
  573.                         {
  574.                             id = (id * 10) + (ch - '0');
  575.                         }
  576.                         else
  577.                         {
  578.                             num = false;
  579.                         }
  580.                     }
  581.                 }
  582.                 if (num && IsPlayerConnected(id))
  583.                 {
  584.                     setarg(paramPos, 0, id);
  585.                 }
  586.                 else
  587.                 {
  588.                     #if !defined foreach
  589.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  590.                         #define __SSCANF_FOREACH__
  591.                     #endif
  592.                     string[end] = '\0';
  593.                     num = false;
  594.                     new
  595.                         name[MAX_PLAYER_NAME];
  596.                     id = end - stringPos;
  597.                     foreach (Player, playerid)
  598.                     {
  599.                         GetPlayerName(playerid, name, sizeof (name));
  600.                         if (!strcmp(name, string[stringPos], true, id))
  601.                         {
  602.                             setarg(paramPos, 0, playerid);
  603.                             num = true;
  604.                             break;
  605.                         }
  606.                     }
  607.                     if (!num)
  608.                     {
  609.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  610.                     }
  611.                     string[end] = ch;
  612.                     #if defined __SSCANF_FOREACH__
  613.                         #undef foreach
  614.                         #undef __SSCANF_FOREACH__
  615.                     #endif
  616.                 }
  617.                 stringPos = end;
  618.             }
  619.             case 's', 'z':
  620.             {
  621.                 new
  622.                     i = 0,
  623.                     ch;
  624.                 if (format[formatPos])
  625.                 {
  626.                     while ((ch = string[stringPos++]) && ch != delim)
  627.                     {
  628.                         setarg(paramPos, i++, ch);
  629.                     }
  630.                     if (!i)
  631.                     {
  632.                         return -1;
  633.                     }
  634.                 }
  635.                 else
  636.                 {
  637.                     while ((ch = string[stringPos++]))
  638.                     {
  639.                         setarg(paramPos, i++, ch);
  640.                     }
  641.                 }
  642.                 stringPos--;
  643.                 setarg(paramPos, i, '\0');
  644.             }
  645.             default:
  646.             {
  647.                 continue;
  648.             }
  649.         }
  650.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  651.         {
  652.             stringPos++;
  653.         }
  654.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  655.         {
  656.             stringPos++;
  657.         }
  658.         paramPos++;
  659.     }
  660.     do
  661.     {
  662.         if ((delim = format[formatPos++]) > ' ')
  663.         {
  664.             if (delim == '\'')
  665.             {
  666.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  667.             }
  668.             else if (delim != 'z')
  669.             {
  670.                 return delim;
  671.             }
  672.         }
  673.     }
  674.     while (delim > ' ');
  675.     return 0;
  676. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement