dini in mysql
#1

Hello all. How to convert to save in mysql from dini ?

i have here i script:
pawn Код:
/*
        Daily Cash - Script
          by XStormiest
 
using dini for save
What we save:
Player last day, last month, last year.
*/

 
//includes
#include <a_samp>
#include <dini>
#include <zcmd>
//config
#define USE_MONEY_AS_REWARD true // set true if you want to set moneys as reward!
#define USE_SCORE_AS_REWARD false // set true if you want score to be set as reward!
// Don't forget to set one to false if you're using another.
 
 
#define MONEY_REWARD_EVERYDAY 1000 // change this to whatever you want
#define SCORE_REWARD_EVERYDAY 1 // change this to whatever you want
 
//some colors
#define RED 0xFF000089
#define YELLOW 0xFFCA50FF
//functions
stock Receive_Reward(playerid , bool: money=true, bool: score=false, cash = MONEY_REWARD_EVERYDAY, sc = SCORE_REWARD_EVERYDAY)
{
   if(score)
   {
          new string[256];
          format(string, sizeof(string), "[LOGIN]You received ( %d score ) because you connected on this da for the first time!", sc);
          SendClientMessage(playerid, YELLOW, string);
   }
   else if(money)
   {
          new string[256];
          format(string, sizeof(string), "[LOGIN]You received ( %d $ ) because you connected on this da for the first time!", cash);
          SendClientMessage(playerid, YELLOW, string);
   }
   return 1;
}
 
GetDate_V(&day, &month, &year)
{
   getdate(year, month, day);
}
#define U_DACC "Daily/Users/%s.ini"
//variables
enum pD
{
   Login_Streak,
   pLastDay,
   pLastMonth,
   pLastYear
}
new P_Daily[MAX_PLAYERS][pD];
new OnlinePlayers = 0;
 
public OnFilterScriptInit()
{
   if(fexist("Daily") )
         print("Folder Daily: Succesfully loaded!");
   else
         print("WARNING: File missing - Daily");
         
   if(fexist("Daily/Users"))
         print("Folder Users found inside Daily: succesfully loaded!");
   else
         print("WARNING: File missing - Users (inside Daily)");
         
   print("===================");
   print("Daily Cash script|by XStormiest | loaded!");
   print("===================");
   return 1;
}
 
public OnFilterScriptExit()
{
   print("===================");
   print("Daily Cash script|by XStormiest | unloaded!");
   print("===================");
   return 1;
}
 
public OnPlayerConnect(playerid)
{
   new username[MAX_PLAYER_NAME];
   GetPlayerName(playerid, username, sizeof(username));
   new File[MAX_PLAYER_NAME+19];
   format(File, sizeof(File), U_DACC, username);
   if(!dini_Exists(File))
   {
          dini_Create(File);
          dini_IntSet(File, "LastDay", P_Daily[playerid][pLastDay]);
          dini_IntSet(File, "LastMonth", P_Daily[playerid][pLastMonth]);
          dini_IntSet(File, "LastYear", P_Daily[playerid][pLastYear]);
          dini_IntSet(File, "LoginStreak", P_Daily[playerid][Login_Streak]);
          P_Daily[playerid][Login_Streak] = -1;
      new d, m, y;
      GetDate_V(d, m, y);
 
      P_Daily[playerid][pLastDay] = d-1;
      P_Daily[playerid][pLastMonth] = m;
      P_Daily[playerid][pLastYear] = y;
   }
   else
   {
          P_Daily[playerid][pLastDay] = dini_Int(File, "LastDay");
          P_Daily[playerid][pLastMonth] = dini_Int(File, "LastMonth");
          P_Daily[playerid][pLastYear] = dini_Int(File, "LastYear");
          P_Daily[playerid][Login_Streak] = dini_Int(File, "LoginStreak");
   }
   new d, m, y;
   GetDate_V(d, m, y);
   
   if(P_Daily[playerid][pLastDay] + 1 == d && dini_Exists(File)) // It means if players enters the next day
   {
          if(P_Daily[playerid][Login_Streak] == -1)
          {
                 P_Daily[playerid][Login_Streak] = 0;
                 GetDate_V(P_Daily[playerid][pLastDay], P_Daily[playerid][pLastMonth], P_Daily[playerid][pLastYear]);
          }
          P_Daily[playerid][Login_Streak]++;
          SendClientMessage(playerid, YELLOW, "Congratiolations, you are on a daily streak");
          #if USE_MONEY_AS_REWARD == true
        GivePlayerMoney(playerid, MONEY_REWARD_EVERYDAY);
        Receive_Reward(playerid, true, false);
      #endif
     
      #if USE_SCORE_AS_REWARD == true
        SetPlayerScore(playerid, GetPlayerScore(playerid)+SCORE_REWARD_EVERYDAY);
        Receive_Reward(playerid, false, true);
      #endif
   }
   else if(P_Daily[playerid][pLastDay] + 1 < d && dini_Exists(File)) // if play didn't entered everyday
   {
          if(P_Daily[playerid][Login_Streak] == -1)
          {
                 P_Daily[playerid][Login_Streak] = 0;
                 GetDate_V(P_Daily[playerid][pLastDay], P_Daily[playerid][pLastMonth], P_Daily[playerid][pLastYear]);
          }
          P_Daily[playerid][Login_Streak] = 0;
          SendClientMessage(playerid, YELLOW, "You losed your daily login streak, but don't worry you can get it back xD");
          #if USE_MONEY_AS_REWARD == true
        GivePlayerMoney(playerid, MONEY_REWARD_EVERYDAY);
        Receive_Reward(playerid, true, false);
      #endif
 
      #if USE_SCORE_AS_REWARD == true
        SetPlayerScore(playerid, GetPlayerScore(playerid)+SCORE_REWARD_EVERYDAY);
        Receive_Reward(playerid, false, true);
      #endif
   }
   else
   {
          if(P_Daily[playerid][pLastDay] == d && dini_Exists(File))
             SendClientMessage(playerid, YELLOW, "You can take your pay for login only once a day, not more!");
   }
   
   new string[256];
   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);}
   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);}
   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);}
   else if(d - P_Daily[playerid][pLastDay] == 1) SendClientMessage(playerid, YELLOW, "[LOGIN] You connected last time Yesterday");
   else if(d - P_Daily[playerid][pLastDay] == 0) SendClientMessage(playerid, YELLOW, "[LOGIN] You connected last time on this day!");
   
   OnlinePlayers++;
   return 1;
}
 
public OnPlayerDisconnect(playerid, reason)
{
   new username[MAX_PLAYER_NAME];
   GetPlayerName(playerid, username, sizeof(username));
   new File[MAX_PLAYER_NAME+19];
   format(File, sizeof(File), U_DACC, username);
   
   
   new d, m, y;
   GetDate_V(d, m, y);
   
   if(dini_Exists(File))
   {
          P_Daily[playerid][pLastDay] = d;
          P_Daily[playerid][pLastMonth] = m;
          P_Daily[playerid][pLastYear] = y;
   
          dini_IntSet(File, "LastDay", P_Daily[playerid][pLastDay]);
          dini_IntSet(File, "LastMonth", P_Daily[playerid][pLastMonth]);
          dini_IntSet(File, "LastYear", P_Daily[playerid][pLastYear]);
          dini_IntSet(File, "LoginStreak", P_Daily[playerid][Login_Streak]);
   }
   OnlinePlayers--;
   return 1;
}
 
// Command
CMD:top5login(playerid, params[])
{
   if(OnlinePlayers < 5) return SendClientMessage(playerid, RED, "Not Enough Players! Min 5!");
   new username[MAX_PLAYER_NAME];
   new str[512], string[256];
   strcat(str, "Username\tLogin Streak\n");
   for(new i = 0; i < MAX_PLAYERS - 1; i++)
   {
          if(P_Daily[i][Login_Streak] > P_Daily[i+1][Login_Streak] && IsPlayerConnected(i) && IsPlayerConnected(i+1))
          {
                 GetPlayerName(i, username, sizeof(username));
                 format(string, sizeof(string), "%s\t%d\n", username, P_Daily[i][Login_Streak]);
                 strcat(str, string);
          }
          else if(P_Daily[i][Login_Streak] < P_Daily[i+1][Login_Streak] && IsPlayerConnected(i) && IsPlayerConnected(i+1))
          {
                 GetPlayerName(i+1, username, sizeof(username));
                 format(string, sizeof(string), "%s\t%d\n", username, P_Daily[i+1][Login_Streak]);
                 strcat(str, string);
          }
   }
   ShowPlayerDialog(playerid, 100, DIALOG_STYLE_TABLIST_HEADERS, "Top 5 Login Streak", str, "Ok", "");
   return 1;
}
Thanks!
Reply
#2

Learn MySQL.
Reply
#3

Give me a link pls
Reply
#4

https://sampforum.blast.hk/showthread.php?tid=574714
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)