Advertisement
Guest User

Untitled

a guest
Jul 16th, 2015
1,653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.84 KB | None | 0 0
  1. /*
  2.     Daily Cash - Script
  3.       by XStormiest
  4.  
  5. using dini for save
  6. What we save:
  7. Player last day, last month, last year.
  8. */
  9.  
  10. //includes
  11. #include <a_samp>
  12. #include <dini>
  13. #include <zcmd>
  14. //config
  15. #define USE_MONEY_AS_REWARD true // set true if you want to set moneys as reward!
  16. #define USE_SCORE_AS_REWARD false // set true if you want score to be set as reward!
  17. // Don't forget to set one to false if you're using another.
  18.  
  19.  
  20. #define MONEY_REWARD_EVERYDAY 1000 // change this to whatever you want
  21. #define SCORE_REWARD_EVERYDAY 1 // change this to whatever you want
  22.  
  23. //some colors
  24. #define RED 0xFF000089
  25. #define YELLOW 0xFFCA50FF
  26. //functions
  27. stock Receive_Reward(playerid , bool: money=true, bool: score=false, cash = MONEY_REWARD_EVERYDAY, sc = SCORE_REWARD_EVERYDAY)
  28. {
  29.    if(score)
  30.    {
  31.       new string[256];
  32.       format(string, sizeof(string), "[LOGIN]You received ( %d score ) because you connected on this da for the first time!", sc);
  33.       SendClientMessage(playerid, YELLOW, string);
  34.    }
  35.    else if(money)
  36.    {
  37.       new string[256];
  38.       format(string, sizeof(string), "[LOGIN]You received ( %d $ ) because you connected on this da for the first time!", cash);
  39.       SendClientMessage(playerid, YELLOW, string);
  40.    }
  41.    return 1;
  42. }
  43.  
  44. GetDate_V(&day, &month, &year)
  45. {
  46.    getdate(year, month, day);
  47. }
  48. #define U_DACC "Daily/Users/%s.ini"
  49. //variables
  50. enum pD
  51. {
  52.    Login_Streak,
  53.    pLastDay,
  54.    pLastMonth,
  55.    pLastYear
  56. }
  57. new P_Daily[MAX_PLAYERS][pD];
  58. new OnlinePlayers = 0;
  59.  
  60. public OnFilterScriptInit()
  61. {
  62.    if(fexist("Daily") )
  63.      print("Folder Daily: Succesfully loaded!");
  64.    else
  65.      print("WARNING: File missing - Daily");
  66.      
  67.    if(fexist("Daily/Users"))
  68.      print("Folder Users found inside Daily: succesfully loaded!");
  69.    else
  70.      print("WARNING: File missing - Users (inside Daily)");
  71.      
  72.    print("===================");
  73.    print("Daily Cash script|by XStormiest | loaded!");
  74.    print("===================");
  75.    return 1;
  76. }
  77.  
  78. public OnFilterScriptExit()
  79. {
  80.    print("===================");
  81.    print("Daily Cash script|by XStormiest | unloaded!");
  82.    print("===================");
  83.    return 1;
  84. }
  85.  
  86. public OnPlayerConnect(playerid)
  87. {
  88.    new username[MAX_PLAYER_NAME];
  89.    GetPlayerName(playerid, username, sizeof(username));
  90.    new File[MAX_PLAYER_NAME+19];
  91.    format(File, sizeof(File), U_DACC, username);
  92.    if(!dini_Exists(File))
  93.    {
  94.       dini_Create(File);
  95.       dini_IntSet(File, "LastDay", P_Daily[playerid][pLastDay]);
  96.       dini_IntSet(File, "LastMonth", P_Daily[playerid][pLastMonth]);
  97.       dini_IntSet(File, "LastYear", P_Daily[playerid][pLastYear]);
  98.       dini_IntSet(File, "LoginStreak", P_Daily[playerid][Login_Streak]);
  99.       P_Daily[playerid][Login_Streak] = -1;
  100.       new d, m, y;
  101.       GetDate_V(d, m, y);
  102.  
  103.       P_Daily[playerid][pLastDay] = d-1;
  104.       P_Daily[playerid][pLastMonth] = m;
  105.       P_Daily[playerid][pLastYear] = y;
  106.    }
  107.    else
  108.    {
  109.       P_Daily[playerid][pLastDay] = dini_Int(File, "LastDay");
  110.       P_Daily[playerid][pLastMonth] = dini_Int(File, "LastMonth");
  111.       P_Daily[playerid][pLastYear] = dini_Int(File, "LastYear");
  112.       P_Daily[playerid][Login_Streak] = dini_Int(File, "LoginStreak");
  113.    }
  114.    new d, m, y;
  115.    GetDate_V(d, m, y);
  116.    
  117.    if(P_Daily[playerid][pLastDay] + 1 == d && dini_Exists(File)) // It means if players enters the next day
  118.    {
  119.       if(P_Daily[playerid][Login_Streak] == -1)
  120.       {
  121.          P_Daily[playerid][Login_Streak] = 0;
  122.          GetDate_V(P_Daily[playerid][pLastDay], P_Daily[playerid][pLastMonth], P_Daily[playerid][pLastYear]);
  123.       }
  124.       P_Daily[playerid][Login_Streak]++;
  125.       SendClientMessage(playerid, YELLOW, "Congratiolations, you are on a daily streak");
  126.       #if USE_MONEY_AS_REWARD == true
  127.         GivePlayerMoney(playerid, MONEY_REWARD_EVERYDAY);
  128.         Receive_Reward(playerid, true, false);
  129.       #endif
  130.      
  131.       #if USE_SCORE_AS_REWARD == true
  132.         SetPlayerScore(playerid, GetPlayerScore(playerid)+SCORE_REWARD_EVERYDAY);
  133.         Receive_Reward(playerid, false, true);
  134.       #endif
  135.    }
  136.    else if(P_Daily[playerid][pLastDay] + 1 < d && dini_Exists(File)) // if play didn't entered everyday
  137.    {
  138.       if(P_Daily[playerid][Login_Streak] == -1)
  139.       {
  140.          P_Daily[playerid][Login_Streak] = 0;
  141.          GetDate_V(P_Daily[playerid][pLastDay], P_Daily[playerid][pLastMonth], P_Daily[playerid][pLastYear]);
  142.       }
  143.       P_Daily[playerid][Login_Streak] = 0;
  144.       SendClientMessage(playerid, YELLOW, "You losed your daily login streak, but don't worry you can get it back xD");
  145.       #if USE_MONEY_AS_REWARD == true
  146.         GivePlayerMoney(playerid, MONEY_REWARD_EVERYDAY);
  147.         Receive_Reward(playerid, true, false);
  148.       #endif
  149.  
  150.       #if USE_SCORE_AS_REWARD == true
  151.         SetPlayerScore(playerid, GetPlayerScore(playerid)+SCORE_REWARD_EVERYDAY);
  152.         Receive_Reward(playerid, false, true);
  153.       #endif
  154.    }
  155.    else
  156.    {
  157.       if(P_Daily[playerid][pLastDay] == d && dini_Exists(File))
  158.          SendClientMessage(playerid, YELLOW, "You can take your pay for login only once a day, not more!");
  159.    }
  160.    
  161.    new string[256];
  162.    if(m > 10 && d > 10 && (d - P_Daily[playerid][pLastDay] > 1) ) { format(string, sizeof(string), "[LOGIN] You connected last time on [%d:%d:%d]", P_Daily[playerid][pLastDay],  P_Daily[playerid][pLastMonth],  P_Daily[playerid][pLastYear]); SendClientMessage(playerid, YELLOW, string);}
  163.    else if(m > 10 && d < 10  && (d - P_Daily[playerid][pLastDay] > 1) ) { format(string, sizeof(string), "[LOGIN] You connected last time on [0%d:%d:%d]",  P_Daily[playerid][pLastDay],  P_Daily[playerid][pLastMonth],  P_Daily[playerid][pLastYear]); SendClientMessage(playerid, YELLOW, string);}
  164.    else if(m < 10 && d > 10  && (d - P_Daily[playerid][pLastDay] > 1) ) { format(string, sizeof(string), "[LOGIN] You connected last time on [%d:0%d:%d]",  P_Daily[playerid][pLastDay],  P_Daily[playerid][pLastMonth],  P_Daily[playerid][pLastYear]); SendClientMessage(playerid, YELLOW, string);}
  165.    else if(d - P_Daily[playerid][pLastDay] == 1) SendClientMessage(playerid, YELLOW, "[LOGIN] You connected last time Yesterday");
  166.    else if(d - P_Daily[playerid][pLastDay] == 0) SendClientMessage(playerid, YELLOW, "[LOGIN] You connected last time on this day!");
  167.    
  168.    OnlinePlayers++;
  169.    return 1;
  170. }
  171.  
  172. public OnPlayerDisconnect(playerid, reason)
  173. {
  174.    new username[MAX_PLAYER_NAME];
  175.    GetPlayerName(playerid, username, sizeof(username));
  176.    new File[MAX_PLAYER_NAME+19];
  177.    format(File, sizeof(File), U_DACC, username);
  178.    
  179.    
  180.    new d, m, y;
  181.    GetDate_V(d, m, y);
  182.    
  183.    if(dini_Exists(File))
  184.    {
  185.       P_Daily[playerid][pLastDay] = d;
  186.       P_Daily[playerid][pLastMonth] = m;
  187.       P_Daily[playerid][pLastYear] = y;
  188.    
  189.       dini_IntSet(File, "LastDay", P_Daily[playerid][pLastDay]);
  190.       dini_IntSet(File, "LastMonth", P_Daily[playerid][pLastMonth]);
  191.       dini_IntSet(File, "LastYear", P_Daily[playerid][pLastYear]);
  192.       dini_IntSet(File, "LoginStreak", P_Daily[playerid][Login_Streak]);
  193.    }
  194.    OnlinePlayers--;
  195.    return 1;
  196. }
  197.  
  198. // Command
  199. CMD:top5login(playerid, params[])
  200. {
  201.    if(OnlinePlayers < 5) return SendClientMessage(playerid, RED, "Not Enough Players! Min 5!");
  202.    new username[MAX_PLAYER_NAME];
  203.    new str[512], string[256];
  204.    strcat(str, "Username\tLogin Streak\n");
  205.    for(new i = 0; i < MAX_PLAYERS - 1; i++)
  206.    {
  207.       if(P_Daily[i][Login_Streak] > P_Daily[i+1][Login_Streak] && IsPlayerConnected(i) && IsPlayerConnected(i+1))
  208.       {
  209.          GetPlayerName(i, username, sizeof(username));
  210.          format(string, sizeof(string), "%s\t%d\n", username, P_Daily[i][Login_Streak]);
  211.          strcat(str, string);
  212.       }
  213.       else if(P_Daily[i][Login_Streak] < P_Daily[i+1][Login_Streak] && IsPlayerConnected(i) && IsPlayerConnected(i+1))
  214.       {
  215.          GetPlayerName(i+1, username, sizeof(username));
  216.          format(string, sizeof(string), "%s\t%d\n", username, P_Daily[i+1][Login_Streak]);
  217.          strcat(str, string);
  218.       }
  219.    }
  220.    ShowPlayerDialog(playerid, 100, DIALOG_STYLE_TABLIST_HEADERS, "Top 5 Login Streak", str, "Ok", "");
  221.    return 1;
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement