Y_Ini help
#1

I'm trying to add an admin line to my ini and kills/deaths. How would I do this? I've tried but I just don't know as I haven;t used Y_Ini.
Here's all my code:
Код:
    #pragma unused ret_memcpy

    enum iDetails {
            Pass,
            Cash,
            Score,
	    AdminLevel
	};
    new pInfo[MAX_PLAYERS][iDetails];

    #if defined AUTOLOGIN
            new pIP[MAX_PLAYERS][16];
    #endif

    new pLogged[MAX_PLAYERS];

    stock PlayerPath(playerid) {
            new iStr[256],name[MAX_PLAYER_NAME];
            GetPlayerName(playerid,name,sizeof(name));
            format(iStr,sizeof(iStr),PATH,name);
            return iStr;
    }
    public OnFilterScriptInit()
    {
            print("\n--------------------------------------");
            print("Login & Register system by NoahF");
            print("--------------------------------------\n");
            return 1;
    }

    public OnFilterScriptExit()
    {
			print("*******************************************");
			print("NoahF's Login and Register system has unloaded.");
			print("*******************************************");
			return 1;
    }

    public OnGameModeExit()
    {
            return 1;
    }

    forward UserDataLoad_data(playerid,name[],value[]);

    public UserDataLoad_data(playerid,name[],value[]) {
            INI_Int("Pass",pInfo[playerid][Pass]);
            #if defined AUTOLOGIN
                    INI_String("IP",pIP[playerid],16);
            #endif
            INI_Int("Cash",pInfo[playerid][Cash]);
            INI_Int("Score",pInfo[playerid][Score]);
			INI_Int("AdminLevel",pInfo[playerid][Level]);
			return 1;
    }

    public OnPlayerConnect(playerid)
    {
            pLogged[playerid] = 0;
            #if defined AUTOLOGIN
                    new tmpIP[16];
                    GetPlayerIp(playerid,tmpIP,sizeof(tmpIP));
            #endif
            if(fexist(PlayerPath(playerid))) {
                INI_ParseFile(PlayerPath(playerid), "UserDataLoad_%s", .bExtra = true, .extra = playerid);
                    #if defined AUTOLOGIN
                    if(strcmp(tmpIP,pIP[playerid],true) == 0) {
                        pLogged[playerid] = 1;
                        SetPlayerScore(playerid,pInfo[playerid][Score]);
                        GivePlayerMoney(playerid,pInfo[playerid][Cash]);
                        SendClientMessage(playerid,lime,"You've been auto-logged in. [IP match]");
                        return 1;
                            }
                    #endif
                    ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login","Please enter your password below.","Login","Leave");
            } else {
                ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Register","Please register by entering a password below.","Register","Leave");
            }
            return 1;
    }

    public OnPlayerDisconnect(playerid, reason)
    {
            if(pLogged[playerid] == 1) {
                    new INI:iFile = INI_Open(PlayerPath(playerid));
                    INI_SetTag(iFile,"data");
                    INI_WriteInt(iFile,"Cash",GetPlayerMoney(playerid));
                    INI_WriteInt(iFile,"Score",GetPlayerScore(playerid));
                    INI_Close(iFile);
            }
            pLogged[playerid] = 0;
            return 1;
    }

    public OnPlayerRequestSpawn(playerid)
    {
            if(pLogged[playerid] == 0) return SendClientMessage(playerid,yellow,"You must register or login before spawning.");
            return 1;
    }

    public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
    {
            if(dialogid == DIALOG_REGISTER) {
                GetPlayerIp(playerid,pIP[playerid],16);
                if(!response) Kick(playerid);
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Register","Please enter a password.","Register","Leave");
                new INI:iFile = INI_Open(PlayerPath(playerid));
                    INI_SetTag(iFile,"data");
                    INI_WriteInt(iFile,"Pass",udb_hash(inputtext));
                    #if defined AUTOLOGIN
                            INI_WriteString(iFile,"IP",pIP[playerid]);
                    #endif
                    INI_WriteInt(iFile,"Cash",REGISTERED_MONEY);
                    INI_WriteInt(iFile,"Score",0);
                    INI_Close(iFile);
                    pLogged[playerid] = 1;
                    new iStr[128];
                    format(iStr,sizeof(iStr),"You have successfully registered with the password \"%s\".",inputtext);
                    SendClientMessage(playerid,yellow,iStr);
                    return 1;
            }
            if(dialogid == DIALOG_LOGIN) {
                if(!response) Kick(playerid);
                    new iStr[128],gTries;
                    if(gTries == 0) gTries = 1;
                    if(gTries == 3) {
                        new pName[30];
                        GetPlayerName(playerid,pName,sizeof(pName));
                        format(iStr,sizeof(iStr),"%s has been kicked for exceeding login tries.",pName);
                            SendClientMessageToAll(red,iStr);
                            return Kick(playerid);
                    }
                    if(!strlen(inputtext)) {
                        format(iStr,sizeof(iStr),"Please enter your password. ATTEMPTS: %i/3",gTries);
                            return ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login",iStr,"Login","Leave");
                    }
                    if(udb_hash(inputtext) == pInfo[playerid][Pass]) {
                        pLogged[playerid] = 1;
                        SendClientMessage(playerid,lime,"You have successfully logged in.");
                        SetPlayerScore(playerid,pInfo[playerid][Score]);
                        GivePlayerMoney(playerid,pInfo[playerid][Cash]);
                    } else {
                        format(iStr,sizeof(iStr),"Incorrect password. Tries: %i/3",gTries);
                            ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Register",iStr,"Login","Leave");
                            gTries++;
                            return 1;
                    }
                    return 1;
            }
            return 1;
    }
In the enum I have put "AdminLevel" But what do I do next?
Reply
#2

AH ok, nvm, but what would the variable look like when making admin commands, and how would I make it so the player gets no admin level on connect?
Reply
#3

You will need to add
pawn Код:
if(pInfo[playerid][AdminLevel] > 1) return SendClientMessage(playerid, COLOR_RED, "ERROR: You are not a admin!");
1 = The admin level the player needs to be.

Also recommend to reset the stats BEFORE loading the userdata.
Reply
#4

Quote:
Originally Posted by NoahF
Посмотреть сообщение
AH ok, nvm, but what would the variable look like when making admin commands, and how would I make it so the player gets no admin level on connect?
Like how would I make a /setlevel command?
Reply
#5

In the register part add "INI_WriteInt(iFile, "AdminLevel", 0);" 0 is for the value.

Now in the loading part add: "INI_LoadInt(iFile, "AdminLevel", Where to Store it in);".

And finally the disconnecting part, I guess you know what to do next.
Reply
#6

pawn Код:
CMD:makeadmin(playerid, params[])
{
    new targetid, admin, string[128];
    if(pInfo[playerid][AdminLevel] < 1337) return SendClientMessage(playerid, COLOR_RED, "ERROR: You are not authorized to use this command.");
    if(sscanf(params, "ud", targetid, admin)) return SendClientMessage(playerid, COLOR_WHITE,"Usage: /makeadmin [PlayerID][AdminLevel]");
    if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_WHITE, "ERROR: That player is not in the server");
    if(pInfo[playerid][AdminLevel] < PlayerInfo[targetid][pAdmin]) return SendClientMessage(playerid, COLOR_WHITE, "ERROR: You cant demote/promote a higher level admin.");
    if(pInfo[playerid][AdminLevel] < admin) return SendClientMessage(playerid, COLOR_WHITE,"ERROR: You can't promote yourself");
    pInfo[targetid][AdminLevel] = admin;

    SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have made someone admin!");
    SendClientMessage(targetid, COLOR_LIGHTBLUE, "You have been made admin!");
    return 1;
}
But with this im using ZCMD and sscanf, also you need to be admin level 1337 to use this command.Wich you can edit by changing the number 1337 at the top
Reply
#7

What should I do for the disconnecting part? Thank you for the makeadmin command, face.
Reply
#8

Np, You will neede to create a SaveAcountStats(playerid) function wich you can execute everytime you want to save someones stats.

EDIT: But i see your script already saves it. Just add
pawn Код:
INI_WriteInt(iFile, "AdminLevel", pInfo[playerid][AdminLevel]);
Reply
#9

You save the admin level on disconnect. Use the INI_WriteInt function.
Reply
#10

Alright, I get these errors:
Quote:

C:\Users\Noah\Desktop\[sK] Deathmatch\filterscripts\loginreg.pwn(185) : error 017: undefined symbol "PlayerInfo"
C:\Users\Noah\Desktop\[sK] Deathmatch\filterscripts\loginreg.pwn(185) : warning 215: expression has no effect
C:\Users\Noah\Desktop\[sK] Deathmatch\filterscripts\loginreg.pwn(185) : error 001: expected token: ";", but found "]"
C:\Users\Noah\Desktop\[sK] Deathmatch\filterscripts\loginreg.pwn(185) : error 029: invalid expression, assumed zero
C:\Users\Noah\Desktop\[sK] Deathmatch\filterscripts\loginreg.pwn(185) : fatal error 107: too many error messages on one line

Line 185:
Quote:

if(pInfo[playerid][AdminLevel] < PlayerInfo[targetid][pAdmin]) return SendClientMessage(playerid, white, "ERROR: You cant demote/promote a higher level admin.");

And could someone just do the WriteInt part.. like I said I have no experience with Y_Ini.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)