Offline Check
#1

Hello! I am trying to make an offline check command, however I can not get it to work, and I have no idea why.

This is my code:

pawn Код:
forward OnPlayerOfflineLogin(playername[]);
public OnPlayerOfflineLogin(playername[])
{
    new string2[64];
    format(string2, sizeof(string2), "Users/%s.ini", playername);
    new File: UserFile = fopen(string2, io_read);
    if(UserFile)
    {
        new key[ 256 ] , val[ 256 ];
        new Data[ 256 ];
        while (fread(UserFile , Data , sizeof(Data)))
        {
                    key = ini_GetKey(Data);
                    if(strcmp(key , "AdminLevel" , true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pAdmin] = strval(val); }
                    if(strcmp(key ,"Cash", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pCash] = strval(val); }
                    if(strcmp(key ,"Admin", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pAdmin] = strval(val); }
                    if(strcmp(key ,"Kills", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pKills] = strval(val); }
                    if(strcmp(key ,"Deaths", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pDeaths]= strval(val); }
                    if(strcmp(key ,"Faction", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pFaction]= strval(val); }
                    if(strcmp(key ,"FactionRank", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pFacRank]= strval(val); }
                    if(strcmp(key ,"FactionDivision", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pFacDiv]= strval(val); }
                    if(strcmp(key ,"Skin", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pSkin]= strval(val); }
                    if(strcmp(key ,"PosX", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pX]= strval(val); }
                    if(strcmp(key ,"PosY", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pY]= strval(val); }
                    if(strcmp(key ,"PosZ", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pZ]= strval(val); }
                    if(strcmp(key ,"Level", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pLevel]= strval(val); }
                    if(strcmp(key ,"Bank", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pBank]= strval(val); }
                    if(strcmp(key ,"Job", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pJob]= strval(val); }
                    if(strcmp(key ,"TruckerSkill", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pTruckerSkill]= strval(val); }
                    if(strcmp(key ,"WeaponDealerSkill", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pWDealerSkill]= strval(val); }
                    if(strcmp(key ,"Banned", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pBanned]= strval(val); }
                    if(strcmp(key ,"PlayingHours", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pHours]= strval(val); }
                    if(strcmp(key ,"Interior", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pInt]= strval(val); }
                    if(strcmp(key ,"VirtualWorld", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pVW]= strval(val); }
                    if(strcmp(key , "IP" , true) == 0) { val = Ini_Value(Data); strmid(PlayerInfo[MAX_PLAYERS][pIp], val, 0, strlen(val)-1, 255); }
                    if(strcmp(key ,"Health", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pHealth]= strval(val); }
                    if(strcmp(key ,"Armor", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pArmor]= strval(val); }
                    if(strcmp(key ,"Gun1", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pGuns][0]= strval(val); }
                    if(strcmp(key ,"Gun2", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pGuns][1]= strval(val); }
                    if(strcmp(key ,"Gun3", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pGuns][2]= strval(val); }
                    if(strcmp(key ,"Gun4", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pGuns][3]= strval(val); }
                    if(strcmp(key ,"Gun5", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pGuns][4]= strval(val); }
                    if(strcmp(key ,"Gun6", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pGuns][5]= strval(val); }
                    if(strcmp(key ,"Gun7", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pGuns][6]= strval(val); }
                    if(strcmp(key ,"Gun8", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pGuns][7]= strval(val); }
                    if(strcmp(key ,"Gun9", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pGuns][8]= strval(val); }
                    if(strcmp(key ,"Gun10", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pGuns][9]= strval(val); }
                    if(strcmp(key ,"Gun11", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pGuns][10]= strval(val); }
                    if(strcmp(key ,"Gun12", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pGuns][11]= strval(val); }
                    if(strcmp(key ,"Materials", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pMaterials]= strval(val); }
                    if(strcmp(key ,"Wanted", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pWanted]= strval(val); }
                    if(strcmp(key ,"TotalWanted", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pTotWanted]= strval(val); }
                    if(strcmp(key ,"Jail", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pJail]= strval(val); }
                    if(strcmp(key ,"Bail", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pBail]= strval(val); }
                    if(strcmp(key ,"TotalDeliveries", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pTotDel]= strval(val); }
                    if(strcmp(key ,"Helper", true) == 0) { val = Ini_Value(Data); PlayerInfo[MAX_PLAYERS][pHelper]= strval(val); }
                   
        }
        fclose(UserFile);
    }
}
Offline check command:

pawn Код:
CMD:ocheck(playerid, params[]) {
        if(PlayerInfo[playerid][pAdmin] < 3)
        return SendClientMessage(playerid, COLOR_GRAD1, "You're not authorized to use that command!");

        if(AdminDuty[playerid] != 1 && PlayerInfo[playerid][pAdmin] < 6)
        return SendClientMessage(playerid,COLOR_WHITE, "You are not on admin duty, /aduty to go on duty as an admin.");

        if(isnull(params))
        return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /ocheck [name]");

        if(!doesAccountExist(params)) return SCM(playerid, -1, "Account does not exist.");
   
        OnPlayerOfflineLogin(params);

        new level = PlayerInfo[MAX_PLAYERS][pLevel];
        new jtext[56];
       
        switch(PlayerInfo[MAX_PLAYERS][pJob])
        {
            case 1: jtext = "Trucker";
            case 2: jtext = "Bodyguard";
            case 3: jtext = "Weapon Dealer";
            default: jtext = "None";
        }

        new cash =  PlayerInfo[MAX_PLAYERS][pCash];
        new bank = PlayerInfo[MAX_PLAYERS][pBank];
        new totalwealth = cash + bank;
        new phours = PlayerInfo[MAX_PLAYERS][pHours]/1000/60;
        new crimes = PlayerInfo[MAX_PLAYERS][pTotWanted];
        new wanted = PlayerInfo[MAX_PLAYERS][pWanted];
        new faction = PlayerInfo[MAX_PLAYERS][pFaction];
        new division = PlayerInfo[MAX_PLAYERS][pFacDiv];
        new jtime = PlayerInfo[MAX_PLAYERS][pJail];
        new interior = PlayerInfo[MAX_PLAYERS][pInt];
        new adminlevel = PlayerInfo[MAX_PLAYERS][pAdmin];
        new banned = PlayerInfo[MAX_PLAYERS][pBanned];
        new vw = PlayerInfo[MAX_PLAYERS][pVW];
        new Float:health, Float:armor;
        health = PlayerInfo[MAX_PLAYERS][pHealth];
        armor = PlayerInfo[MAX_PLAYERS][pArmor];
        new mats = PlayerInfo[MAX_PLAYERS][pMaterials];


        SendClientMessage(playerid, COLOR_GREEN,"___________________________________________________________________________________________________");
        new coordsstring[128];
        format(coordsstring, sizeof(coordsstring),"%s - Level: %d - Playing hours: %d", params, level, phours);
        SendClientMessage(playerid, COLOR_GREEN, coordsstring);
        format(coordsstring, sizeof(coordsstring),"Faction: %s - Rank: %d - Division: %s - Job: %s", faction, PlayerInfo[MAX_PLAYERS][pFacRank], division, jtext);
        SendClientMessage(playerid, COLOR_GREEN, coordsstring);
        format(coordsstring, sizeof(coordsstring),"Total wealth: $%d - Cash: $%d - Bank balance: $%d", totalwealth, cash, bank);
        SendClientMessage(playerid, COLOR_GREEN, coordsstring);
        format(coordsstring, sizeof(coordsstring),"Health: %.1f - Armor: %.1f",health, armor);
        SendClientMessage(playerid, COLOR_GREEN, coordsstring);
        format(coordsstring, sizeof(coordsstring),"Wanted Level: %d - Total Wanted: %d - Materials: %d ", wanted, mats, crimes);
        SendClientMessage(playerid, COLOR_GREEN, coordsstring);
        format(coordsstring, sizeof(coordsstring), "Admin Level: %d - Banned: %d", adminlevel, banned);
        SendClientMessage(playerid, COLOR_GREEN,coordsstring);
        format(coordsstring, sizeof(coordsstring), "Interior: %d - Virtual World: %d - Jail: %d secs", interior, vw, jtime);
        SendClientMessage(playerid, COLOR_GREEN,coordsstring);
        SendClientMessage(playerid, COLOR_GREEN,"___________________________________________________________________________________________________");
        return 1;
}


Playerfile
Код:
[data]
Password = *******************
PosX = 1864.891845
PosY = -1726.326293
PosZ = 31.804687
Job = 0
TruckerSkill = 0
Faction = 1
FactionRank = 6
FactionDivision = 0
Banned = 1
PlayingHours = 7387
Interior = 0
VirtualWorld = 0
Admin = 6
Helper = 0
Cash = 300
Kills = 0
Deaths = 0
Skin = 1
Level = 1
Bank = 300
WeaponDealerSkill = 0
Gun1 = 0
Gun2 = 0
Gun3 = 0
Gun4 = 0
Gun5 = 0
Gun6 = 0
Gun7 = 0
Gun8 = 0
Gun9 = 0
Gun10 = 0
Gun11 = 0
Gun12 = 0
Materials = 0
Wanted = 0
WantedReason1 = 
WantedReason2 = 
WantedReason3 = 
WantedReason4 = 
WantedReason5 = 
WantedReason6 = 
TotalWanted = 0
Jail = 0
Bail = 0
AdminName = Test
Name = Test_Account
Health = 100.000000
TotalDeliveries = 0
Armor = 0.000000
IP = 127.0.0.1
Reply
#2

It's best to get the function results into the same command instead of calling it, don't save them into a player variable but normal ones e.g new level.

Then level = strval(data);
Reply
#3

pawn Код:
forward OnPlayerOfflineLogin(playername[]);
public OnPlayerOfflineLogin(playername[])
{
    new string2[64];
    format(string2, sizeof(string2), "Users/%s.ini", playername);
    new File: UserFile = fopen(string2, io_read);
    if(UserFile)
    {
        new key[ 256 ] , val[ 256 ];
        new Data[ 256 ];
        while (fread(UserFile , Data , sizeof(Data)))
        {
                    key = ini_GetKey(Data);
                    if(strcmp(key , "AdminLevel" , true) == 0) { val = Ini_Value(Data); AdminLevel = strval(val); }
                    if(strcmp(key ,"Cash", true) == 0) { val = Ini_Value(Data); Cash = strval(val); }
                    if(strcmp(key ,"Kills", true) == 0) { val = Ini_Value(Data); Kills = strval(val); }
                    if(strcmp(key ,"Deaths", true) == 0) { val = Ini_Value(Data); Deaths = strval(val); }
                    if(strcmp(key ,"Faction", true) == 0) { val = Ini_Value(Data); Faction = strval(val); }
                    if(strcmp(key ,"FactionRank", true) == 0) { val = Ini_Value(Data); FactionRank = strval(val); }
                    if(strcmp(key ,"FactionDivision", true) == 0) { val = Ini_Value(Data); FactionDivision = strval(val); }
                    if(strcmp(key ,"Skin", true) == 0) { val = Ini_Value(Data); Skin = strval(val); }
                    if(strcmp(key ,"PosX", true) == 0) { val = Ini_Value(Data); PosX = strval(val); }
                    if(strcmp(key ,"PosY", true) == 0) { val = Ini_Value(Data); PosY = strval(val); }
                    if(strcmp(key ,"PosZ", true) == 0) { val = Ini_Value(Data); PosZ = strval(val); }
                    if(strcmp(key ,"Level", true) == 0) { val = Ini_Value(Data); Level = strval(val); }
                    if(strcmp(key ,"Bank", true) == 0) { val = Ini_Value(Data); Bank = strval(val); }
                    if(strcmp(key ,"Job", true) == 0) { val = Ini_Value(Data); Job = strval(val); }
                    if(strcmp(key ,"TruckerSkill", true) == 0) { val = Ini_Value(Data); TruckerSkill = strval(val); }
                    if(strcmp(key ,"WeaponDealerSkill", true) == 0) { val = Ini_Value(Data); WeaponDealerSkill = strval(val); }
                    if(strcmp(key ,"Banned", true) == 0) { val = Ini_Value(Data); Banned = strval(val); }
                    if(strcmp(key ,"PlayingHours", true) == 0) { val = Ini_Value(Data); PlayingHours = strval(val); }
                    if(strcmp(key ,"Interior", true) == 0) { val = Ini_Value(Data); Interior = strval(val); }
                    if(strcmp(key ,"VirtualWorld", true) == 0) { val = Ini_Value(Data); VirtualWorld = strval(val); }
                    //if(strcmp(key , "IP" , true) == 0) { val = Ini_Value(Data); IP, val, 0, strlen(val)-1, 255); }
                    if(strcmp(key ,"Health", true) == 0) { val = Ini_Value(Data); Health = strval(val); }
                    if(strcmp(key ,"Armor", true) == 0) { val = Ini_Value(Data); Armor = strval(val); }
                    if(strcmp(key ,"Gun1", true) == 0) { val = Ini_Value(Data); Gun1 = strval(val); }
                    if(strcmp(key ,"Gun2", true) == 0) { val = Ini_Value(Data); Gun2 = strval(val); }
                    if(strcmp(key ,"Gun3", true) == 0) { val = Ini_Value(Data); Gun3 = strval(val); }
                    if(strcmp(key ,"Gun4", true) == 0) { val = Ini_Value(Data); Gun4 = strval(val); }
                    if(strcmp(key ,"Gun5", true) == 0) { val = Ini_Value(Data); Gun5 = strval(val); }
                    if(strcmp(key ,"Gun6", true) == 0) { val = Ini_Value(Data); Gun6 = strval(val); }
                    if(strcmp(key ,"Gun7", true) == 0) { val = Ini_Value(Data); Gun7 = strval(val); }
                    if(strcmp(key ,"Gun8", true) == 0) { val = Ini_Value(Data); Gun8 = strval(val); }
                    if(strcmp(key ,"Gun9", true) == 0) { val = Ini_Value(Data); Gun9 = strval(val); }
                    if(strcmp(key ,"Gun10", true) == 0) { val = Ini_Value(Data); Gun10 = strval(val); }
                    if(strcmp(key ,"Gun11", true) == 0) { val = Ini_Value(Data); Gun11 = strval(val); }
                    if(strcmp(key ,"Gun12", true) == 0) { val = Ini_Value(Data); Gun12 = strval(val); }
                    if(strcmp(key ,"Materials", true) == 0) { val = Ini_Value(Data); Materials = strval(val); }
                    if(strcmp(key ,"Wanted", true) == 0) { val = Ini_Value(Data); Wanted = strval(val); }
                    if(strcmp(key ,"TotalWanted", true) == 0) { val = Ini_Value(Data); TotalWanted = strval(val); }
                    if(strcmp(key ,"Jail", true) == 0) { val = Ini_Value(Data); Jail = strval(val); }
                    if(strcmp(key ,"Bail", true) == 0) { val = Ini_Value(Data); Bail = strval(val); }
                    if(strcmp(key ,"TotalDeliveries", true) == 0) { val = Ini_Value(Data); TotalDeliveries = strval(val); }
                    if(strcmp(key ,"Helper", true) == 0) { val = Ini_Value(Data); Helper = strval(val); }
                   
        }
        fclose(UserFile);
    }
}
pawn Код:
CMD:ocheck(playerid, params[]) {
        if(PlayerInfo[playerid][pAdmin] < 3)
        return SendClientMessage(playerid, COLOR_GRAD1, "You're not authorized to use that command!");

        if(AdminDuty[playerid] != 1 && PlayerInfo[playerid][pAdmin] < 6)
        return SendClientMessage(playerid,COLOR_WHITE, "You are not on admin duty, /aduty to go on duty as an admin.");

        if(isnull(params))
        return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /ocheck [name]");

        if(!doesAccountExist(params)) return SCM(playerid, -1, "Account does not exist.");
   
        OnPlayerOfflineLogin(params);
        new jtext[56];
       
        switch(PlayerInfo[MAX_PLAYERS][pJob])
        {
            case 1: jtext = "Trucker";
            case 2: jtext = "Bodyguard";
            case 3: jtext = "Weapon Dealer";
            default: jtext = "None";
        }

        SendClientMessage(playerid, COLOR_GREEN,"___________________________________________________________________________________________________");
        new coordsstring[128];
        format(coordsstring, sizeof(coordsstring),"%s - Level: %d - Playing hours: %d", params, Level, PlayingHours/1000/60);
        SendClientMessage(playerid, COLOR_GREEN, coordsstring);
        format(coordsstring, sizeof(coordsstring),"Faction: %s - Rank: %d - Division: %s - Job: %s", Faction, FactionRank, FactionDivision, jtext);
        SendClientMessage(playerid, COLOR_GREEN, coordsstring);
        format(coordsstring, sizeof(coordsstring),"Total wealth: $%d - Cash: $%d - Bank: $%d", Cash+Bank, Cash, Bank);
        SendClientMessage(playerid, COLOR_GREEN, coordsstring);
        format(coordsstring, sizeof(coordsstring),"Health: %.1f - Armor: %.1f",Health, Armor);
        SendClientMessage(playerid, COLOR_GREEN, coordsstring);
        format(coordsstring, sizeof(coordsstring),"Wanted Level: %d - Total Wanted: %d - Materials: %d ", Wanted, TotalWanted, Materials);
        SendClientMessage(playerid, COLOR_GREEN, coordsstring);
        format(coordsstring, sizeof(coordsstring), "Admin Level: %d - Banned: %d", AdminLevel, Banned);
        SendClientMessage(playerid, COLOR_GREEN,coordsstring);
        format(coordsstring, sizeof(coordsstring), "Interior: %d - Virtual World: %d - Jail: %d secs", Interior, VirtualWorld, Jail);
        SendClientMessage(playerid, COLOR_GREEN,coordsstring);
        SendClientMessage(playerid, COLOR_GREEN,"___________________________________________________________________________________________________");
        return 1;
}
Everything still returns 0
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)