If PlayerName exist
#1

Hello,
I have changename it saves fine but

if i put an exist name it will be replaced i want to avoid this issue by checking if playername exist
How do i check if playername exist?

I use dini for saving system.

Note: ok ok i know dini is slow. I will move Y_INI soon.
Reply
#2

Add this check in your command.

pawn Код:
new string[MAX_PLAYER_NAME];
GetPlayerName(playerid, string, sizeof(string));
format(string, sizeof(string), "%s.ini", PlayerName(playerid));
if(dini_Exists(string)) // This will check if the dini exists. returns true if exists.
{
//
// Your code here
}
else
{
//Use your code here if no dini exists.
}
Reply
#3

Thanks but in order to test it i need to fix one more bug in my /changename

Can you help me?

pawn Код:
CMD:changename(playerid, params[])
{
    new string[128],
        newname[24],
        oldname[24],
        location[254],
        id;
    if(pData[playerid][Login] == 0) return SendClientMessage(playerid, COLOR_RED, "*** Please login first! ***");
    if(pData[playerid][Admin] < 3) return SendClientMessage(playerid, COLOR_RED, "*** You are not Junior Administrator ***");
    if(sscanf(params, "us[24]", id, newname)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /changename [playerid] [newname]");
    format(location, 254, pPath, newname);
    format(oldname,  24, "%s", dini_Get(DataPath(id), "Name"));
//i always get bug in this part >>>// if(strval(newname) == strval(oldname)) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change the old name to new name! ***");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "*** Player not connected ***");
    if(pData[playerid][Admin] < pData[id][Admin]) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change name higher administrator! ***");
    if(!dini_Exists(DataPath(playerid)))
    {
        format(string, sizeof(string), "Administrator %s(%d) has change %s name to %s(%d)", GetpName(playerid), playerid, GetpName(id), newname, id);
        SendClientMessageToAll(COLOR_GREEN, string);
        format(string, sizeof(string), "*** You change %s name to %s(%d)", GetpName(id), newname, id);
        SendClientMessage(playerid, COLOR_GREEN, string);
        format(string, sizeof(string), "*** Administrator %s(%d) has change your name to %s", GetpName(playerid), playerid, newname);
        SendClientMessage(id, COLOR_GREEN, string);
        pData[id][Pass] = dini_Int(DataPath(id), "Password");
        pData[id][NoPM] = dini_Int(DataPath(id), "NoPM");
        pData[id][Banned] = dini_Int(DataPath(id), "Ban");
        new banreason[92];
        format(banreason, 92, "%s", dini_Get(DataPath(id), "Reason"));
        new banby[24];
        format(banby, 24, "%s", dini_Get(DataPath(id), "BanBy"));
        pData[id][Admin] = dini_Int(DataPath(id), "Admin");
        pData[id][VIP] = dini_Int(DataPath(id), "VIP");
        pData[id][Score] = dini_Int(DataPath(id), "Score");
        pData[id][Cash] = dini_Int(DataPath(id), "Cash");
        pData[id][Freeze] = dini_Int(DataPath(id), "Freeze");
        pData[id][Deaths] = dini_Int(DataPath(id), "Deaths");
        pData[id][Kills] = dini_Int(DataPath(id), "Kills");
        dini_Remove(DataPath(id));
        dini_Create(location);
        dini_Set(location, "Name", newname);
        dini_Set(location, "IP", IP);
        dini_IntSet(location, "Password", pData[id][Pass]);
        dini_IntSet(location, "Ban", pData[id][Banned]);
        dini_Set(location, "Reason", banreason);
        dini_Set(location, "BanBy", banby);
        dini_IntSet(location, "Admin", pData[id][Admin]);
        dini_IntSet(location, "VIP", pData[id][VIP]);
        dini_IntSet(location, "Score", pData[id][Score]);
        dini_IntSet(location, "Cash", pData[id][Cash]);
        dini_IntSet(location, "Freeze", pData[id][Freeze]);
        dini_IntSet(location, "Deaths", pData[id][Deaths]);
        dini_IntSet(location, "Kills", pData[id][Kills]);
        SetPlayerName(id, newname);
    }
    else if(dini_Exists(DataPath(playerid)))
    {
        SendClientMessage(playerid, COLOR_RED, "*** That player name exists! ***");
    }
    return 1;
}
Reply
#4

What is the bug now?

Secondly the above code will be like this:

pawn Код:
CMD:changename(playerid, params[])
{
    new string[128],
        newname[MAX_PLAYER_NAME],
        oldname[MAX_PLAYER_NAME],
        location[254],
        id;
    if(pData[playerid][Login] == 0) return SendClientMessage(playerid, COLOR_RED, "*** Please login first! ***");
    if(pData[playerid][Admin] < 3) return SendClientMessage(playerid, COLOR_RED, "*** You are not Junior Administrator ***");
    if(sscanf(params, "us[24]", id, newname)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /changename [playerid] [newname]");
    format(location, 254, pPath, newname);
    format(oldname,  24, "%s", dini_Get(DataPath(id), "Name"));
 if(newname, oldname, true, 34) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change the old name to new name! ***");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "*** Player not connected ***");
    if(pData[playerid][Admin] < pData[id][Admin]) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change name higher administrator! ***");
         if(dini_Exists(DataPath(playerid))) return SendClientMessage(playerid, COLOR_RED, "*** That player name exists! ***");

    if(!dini_Exists(DataPath(playerid)))
    {
        format(string, sizeof(string), "Administrator %s(%d) has change %s name to %s(%d)", GetpName(playerid), playerid, GetpName(id), newname, id);
        SendClientMessageToAll(COLOR_GREEN, string);
        format(string, sizeof(string), "*** You change %s name to %s(%d)", GetpName(id), newname, id);
        SendClientMessage(playerid, COLOR_GREEN, string);
        format(string, sizeof(string), "*** Administrator %s(%d) has change your name to %s", GetpName(playerid), playerid, newname);
        SendClientMessage(id, COLOR_GREEN, string);
        pData[id][Pass] = dini_Int(DataPath(id), "Password");
        pData[id][NoPM] = dini_Int(DataPath(id), "NoPM");
        pData[id][Banned] = dini_Int(DataPath(id), "Ban");
        new banreason[92];
        format(banreason, 92, "%s", dini_Get(DataPath(id), "Reason"));
        new banby[24];
        format(banby, 24, "%s", dini_Get(DataPath(id), "BanBy"));
        pData[id][Admin] = dini_Int(DataPath(id), "Admin");
        pData[id][VIP] = dini_Int(DataPath(id), "VIP");
        pData[id][Score] = dini_Int(DataPath(id), "Score");
        pData[id][Cash] = dini_Int(DataPath(id), "Cash");
        pData[id][Freeze] = dini_Int(DataPath(id), "Freeze");
        pData[id][Deaths] = dini_Int(DataPath(id), "Deaths");
        pData[id][Kills] = dini_Int(DataPath(id), "Kills");
        dini_Remove(DataPath(id));
        dini_Create(location);
        dini_Set(location, "Name", newname);
        dini_Set(location, "IP", IP);
        dini_IntSet(location, "Password", pData[id][Pass]);
        dini_IntSet(location, "Ban", pData[id][Banned]);
        dini_Set(location, "Reason", banreason);
        dini_Set(location, "BanBy", banby);
        dini_IntSet(location, "Admin", pData[id][Admin]);
        dini_IntSet(location, "VIP", pData[id][VIP]);
        dini_IntSet(location, "Score", pData[id][Score]);
        dini_IntSet(location, "Cash", pData[id][Cash]);
        dini_IntSet(location, "Freeze", pData[id][Freeze]);
        dini_IntSet(location, "Deaths", pData[id][Deaths]);
        dini_IntSet(location, "Kills", pData[id][Kills]);
        SetPlayerName(id, newname);
    }
   
    return 1;
}
Reply
#5

I always get bug

like

Код:
You cannot change the old name to new name!
i already put arrow on it you didn't see it?

let me put it again

pawn Код:
>>>>>>>>>>>>>>>>>>> if(strval(newname) == strval(oldname)) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change the old name to new name! ***");
Reply
#6

Quote:
Originally Posted by Romel
Посмотреть сообщение
I always get bug

like

Код:
You cannot change the old name to new name!
i already put arrow on it you didn't see it?

let me put it again

pawn Код:
>>>>>>>>>>>>>>>>>>> if(strval(newname) == strval(oldname)) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change the old name to new name! ***");
I fixed it. Test the code above now.Tell me it works fine or not?
Reply
#7

Thanks for fixing my code but now i get this

Код:
*** That player name exists! ***
here is my code

pawn Код:
CMD:changename(playerid, params[])
{
    new string[128],
        newname[MAX_PLAYER_NAME],
        oldname[MAX_PLAYER_NAME],
        location[254],
        id;
    if(pData[playerid][Login] == 0) return SendClientMessage(playerid, COLOR_RED, "*** Please login first! ***");
    if(pData[playerid][Admin] < 3) return SendClientMessage(playerid, COLOR_RED, "*** You are not Junior Administrator ***");
    if(sscanf(params, "us[24]", id, newname)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /changename [playerid] [newname]");
    format(location, 254, pPath, newname);
    format(oldname,  24, "%s", dini_Get(DataPath(id), "Name"));
    if(!strcmp(newname, oldname, true)) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change the old name to new name! ***");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "*** Player not connected ***");
    if(pData[playerid][Admin] < pData[id][Admin]) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change name higher administrator! ***");
    if(dini_Exists(DataPath(playerid))) return SendClientMessage(playerid, COLOR_RED, "*** That player name exists! ***");
    else if(!dini_Exists(DataPath(playerid)))
    {
        format(string, sizeof(string), "Administrator %s(%d) has change %s name to %s(%d)", GetpName(playerid), playerid, GetpName(id), newname, id);
        SendClientMessageToAll(COLOR_GREEN, string);
        format(string, sizeof(string), "*** You change %s name to %s(%d)", GetpName(id), newname, id);
        SendClientMessage(playerid, COLOR_GREEN, string);
        format(string, sizeof(string), "*** Administrator %s(%d) has change your name to %s", GetpName(playerid), playerid, newname);
        SendClientMessage(id, COLOR_GREEN, string);
        pData[id][Pass] = dini_Int(DataPath(id), "Password");
        pData[id][NoPM] = dini_Int(DataPath(id), "NoPM");
        pData[id][Banned] = dini_Int(DataPath(id), "Ban");
        new banreason[92];
        format(banreason, 92, "%s", dini_Get(DataPath(id), "Reason"));
        new banby[24];
        format(banby, 24, "%s", dini_Get(DataPath(id), "BanBy"));
        pData[id][Admin] = dini_Int(DataPath(id), "Admin");
        pData[id][VIP] = dini_Int(DataPath(id), "VIP");
        pData[id][Score] = dini_Int(DataPath(id), "Score");
        pData[id][Cash] = dini_Int(DataPath(id), "Cash");
        pData[id][Freeze] = dini_Int(DataPath(id), "Freeze");
        pData[id][Deaths] = dini_Int(DataPath(id), "Deaths");
        pData[id][Kills] = dini_Int(DataPath(id), "Kills");
        dini_Remove(DataPath(id));
        dini_Create(location);
        dini_Set(location, "Name", newname);
        dini_Set(location, "IP", IP);
        dini_IntSet(location, "Password", pData[id][Pass]);
        dini_IntSet(location, "Ban", pData[id][Banned]);
        dini_Set(location, "Reason", banreason);
        dini_Set(location, "BanBy", banby);
        dini_IntSet(location, "Admin", pData[id][Admin]);
        dini_IntSet(location, "VIP", pData[id][VIP]);
        dini_IntSet(location, "Score", pData[id][Score]);
        dini_IntSet(location, "Cash", pData[id][Cash]);
        dini_IntSet(location, "Freeze", pData[id][Freeze]);
        dini_IntSet(location, "Deaths", pData[id][Deaths]);
        dini_IntSet(location, "Kills", pData[id][Kills]);
        SetPlayerName(id, newname);
    }
    return 1;
}
Reply
#8

Oww sorry.

pawn Код:
CMD:changename(playerid, params[])
{
    new string[128],
        newname[MAX_PLAYER_NAME],
        oldname[MAX_PLAYER_NAME],
        location[254],
        id;
    if(pData[playerid][Login] == 0) return SendClientMessage(playerid, COLOR_RED, "*** Please login first! ***");
    if(pData[playerid][Admin] < 3) return SendClientMessage(playerid, COLOR_RED, "*** You are not Junior Administrator ***");
    if(sscanf(params, "us[24]", id, newname)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /changename [playerid] [newname]");
    format(location, 254, pPath, newname);
    format(oldname,  24, "%s", dini_Get(DataPath(id), "Name"));
    if(strcmp(newname, oldname, true)) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change the old name to new name! ***");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "*** Player not connected ***");
    if(pData[playerid][Admin] < pData[id][Admin]) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change name higher administrator! ***");
    if(dini_Exists(DataPath(playerid))) return SendClientMessage(playerid, COLOR_RED, "*** That player name exists! ***");
    else if(!dini_Exists(DataPath(playerid)))
    {
        format(string, sizeof(string), "Administrator %s(%d) has change %s name to %s(%d)", GetpName(playerid), playerid, GetpName(id), newname, id);
        SendClientMessageToAll(COLOR_GREEN, string);
        format(string, sizeof(string), "*** You change %s name to %s(%d)", GetpName(id), newname, id);
        SendClientMessage(playerid, COLOR_GREEN, string);
        format(string, sizeof(string), "*** Administrator %s(%d) has change your name to %s", GetpName(playerid), playerid, newname);
        SendClientMessage(id, COLOR_GREEN, string);
        pData[id][Pass] = dini_Int(DataPath(id), "Password");
        pData[id][NoPM] = dini_Int(DataPath(id), "NoPM");
        pData[id][Banned] = dini_Int(DataPath(id), "Ban");
        new banreason[92];
        format(banreason, 92, "%s", dini_Get(DataPath(id), "Reason"));
        new banby[24];
        format(banby, 24, "%s", dini_Get(DataPath(id), "BanBy"));
        pData[id][Admin] = dini_Int(DataPath(id), "Admin");
        pData[id][VIP] = dini_Int(DataPath(id), "VIP");
        pData[id][Score] = dini_Int(DataPath(id), "Score");
        pData[id][Cash] = dini_Int(DataPath(id), "Cash");
        pData[id][Freeze] = dini_Int(DataPath(id), "Freeze");
        pData[id][Deaths] = dini_Int(DataPath(id), "Deaths");
        pData[id][Kills] = dini_Int(DataPath(id), "Kills");
        dini_Remove(DataPath(id));
        dini_Create(location);
        dini_Set(location, "Name", newname);
        dini_Set(location, "IP", IP);
        dini_IntSet(location, "Password", pData[id][Pass]);
        dini_IntSet(location, "Ban", pData[id][Banned]);
        dini_Set(location, "Reason", banreason);
        dini_Set(location, "BanBy", banby);
        dini_IntSet(location, "Admin", pData[id][Admin]);
        dini_IntSet(location, "VIP", pData[id][VIP]);
        dini_IntSet(location, "Score", pData[id][Score]);
        dini_IntSet(location, "Cash", pData[id][Cash]);
        dini_IntSet(location, "Freeze", pData[id][Freeze]);
        dini_IntSet(location, "Deaths", pData[id][Deaths]);
        dini_IntSet(location, "Kills", pData[id][Kills]);
        SetPlayerName(id, newname);
    }
    return 1;
}
Reply
#9

I don't quite understand you bring back the old bug

when you edit my strcmp and made this

pawn Код:
if(strcmp(newname, oldname, true)) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change the old name to new name! ***");
now i get

Код:
*** You cannot change old name to new name ***
but if i do this

pawn Код:
if(!strcmp(newname, oldname, true)) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change the old name to new name! ***");
i get a bug

Код:
*** That player name exists ***
anyway i will rep you for now i will find where the bug comes from
Reply
#10

Quote:
Originally Posted by Romel
Посмотреть сообщение
I don't quite understand you bring back the old bug

when you edit my strcmp and made this

pawn Код:
if(strcmp(newname, oldname, true)) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change the old name to new name! ***");
now i get

Код:
*** You cannot change old name to new name ***
but if i do this

pawn Код:
if(!strcmp(newname, oldname, true)) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change the old name to new name! ***");
i get a bug

Код:
*** That player name exists ***
anyway i will rep you for now i will find where the bug comes from
pawn Код:
CMD:changename(playerid, params[])
{
    new string[128],
        newname[MAX_PLAYER_NAME],
        oldname[MAX_PLAYER_NAME],
        location[254],
        id;
    if(pData[playerid][Login] == 0) return SendClientMessage(playerid, COLOR_RED, "*** Please login first! ***");
    if(pData[playerid][Admin] < 3) return SendClientMessage(playerid, COLOR_RED, "*** You are not Junior Administrator ***");
    if(sscanf(params, "us[24]", id, newname)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /changename [playerid] [newname]");
    format(location, 254, pPath, newname);
    format(oldname,  24, "%s", dini_Get(DataPath(id), "Name"));
        if(dini_Exists(DataPath(playerid))) return SendClientMessage(playerid, COLOR_RED, "*** That player name exists! or you're changing the newname to a oldname. ***");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "*** Player not connected ***");
    if(pData[playerid][Admin] < pData[id][Admin]) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change name higher administrator! ***");
    else if(!dini_Exists(DataPath(playerid)))
    {
        format(string, sizeof(string), "Administrator %s(%d) has change %s name to %s(%d)", GetpName(playerid), playerid, GetpName(id), newname, id);
        SendClientMessageToAll(COLOR_GREEN, string);
        format(string, sizeof(string), "*** You change %s name to %s(%d)", GetpName(id), newname, id);
        SendClientMessage(playerid, COLOR_GREEN, string);
        format(string, sizeof(string), "*** Administrator %s(%d) has change your name to %s", GetpName(playerid), playerid, newname);
        SendClientMessage(id, COLOR_GREEN, string);
        pData[id][Pass] = dini_Int(DataPath(id), "Password");
        pData[id][NoPM] = dini_Int(DataPath(id), "NoPM");
        pData[id][Banned] = dini_Int(DataPath(id), "Ban");
        new banreason[92];
        format(banreason, 92, "%s", dini_Get(DataPath(id), "Reason"));
        new banby[24];
        format(banby, 24, "%s", dini_Get(DataPath(id), "BanBy"));
        pData[id][Admin] = dini_Int(DataPath(id), "Admin");
        pData[id][VIP] = dini_Int(DataPath(id), "VIP");
        pData[id][Score] = dini_Int(DataPath(id), "Score");
        pData[id][Cash] = dini_Int(DataPath(id), "Cash");
        pData[id][Freeze] = dini_Int(DataPath(id), "Freeze");
        pData[id][Deaths] = dini_Int(DataPath(id), "Deaths");
        pData[id][Kills] = dini_Int(DataPath(id), "Kills");
        dini_Remove(DataPath(id));
        dini_Create(location);
        dini_Set(location, "Name", newname);
        dini_Set(location, "IP", IP);
        dini_IntSet(location, "Password", pData[id][Pass]);
        dini_IntSet(location, "Ban", pData[id][Banned]);
        dini_Set(location, "Reason", banreason);
        dini_Set(location, "BanBy", banby);
        dini_IntSet(location, "Admin", pData[id][Admin]);
        dini_IntSet(location, "VIP", pData[id][VIP]);
        dini_IntSet(location, "Score", pData[id][Score]);
        dini_IntSet(location, "Cash", pData[id][Cash]);
        dini_IntSet(location, "Freeze", pData[id][Freeze]);
        dini_IntSet(location, "Deaths", pData[id][Deaths]);
        dini_IntSet(location, "Kills", pData[id][Kills]);
        SetPlayerName(id, newname);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)