DINI and STRINGS
#1

Код:
YCMD:login(playerid, params[], help)
{
    new pFile[100], pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    format(pFile, sizeof(pFile), "Accounts/%s.ini", pName);
    new string[256],string2[256];
    format(string,sizeof(string),"%s",dini_Get(pFile,"Password"));
    format(string2,sizeof(string),"%s",params);
    
    if(!dini_Exists(pFile)) return SendClientMessage(playerid,0x00FF00AA,"You are not registered! Please /register");
	if(string = string2) return  SendClientMessage(playerid,0x00FF00AA,"WORKS YEAAAAAAA");
	if(!string = string2) return  SendClientMessage(playerid,0x00FF00AA,"wrong!");
	}
What's wrong here ( i get the "WORKS YEAAAAAAA" message even if the password is wrong )
Reply
#2

Tried it like this :


Код:
YCMD:login(playerid, params[], help)
{
    new pFile[100], pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    format(pFile, sizeof(pFile), "Accounts/%s.ini", pName);
    new string[256],string2[256];
    format(string,sizeof(string),"%s",dini_Get(pFile,"Password"));
    format(string2,sizeof(string),"%s",params);
    
    if(!dini_Exists(pFile)) return SendClientMessage(playerid,0x00FF00AA,"You are not registered! Please /register");
    if(!string = string2) return  SendClientMessage(playerid,0x00FF00AA,"wrong!");
	if(string = string2) return SendClientMessage(playerid,0x00FF00AA,"WORKS YEAAAAAAA");
	else return 1;
	}
but now, when i type the password correctly i get the Wrong! message and when i try again ( wrong or correct ) it shows me UNKNOWN COMMAND
Reply
#3

pawn Код:
YCMD:login(playerid, params[], help)
{
    new pFile[100], pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    format(pFile, sizeof(pFile), "Accounts/%s.ini", pName);
    new string[256],string2[256];
    format(string,sizeof(string),"%s",dini_Get(pFile,"Password"));
    format(string2,sizeof(string),"%s",params);
   
    if(!dini_Exists(pFile)) return SendClientMessage(playerid,0x00FF00AA,"You are not registered! Please /register");
    if(strcmp(string,string2) != 0) return  SendClientMessage(playerid,0x00FF00AA,"wrong!");
    if(strcmp(string,string2) == 0)
        {
        SendClientMessage(playerid,0x00FF00AA,"WORKS YEAAAAAAA");
        }
        return 1;
}
When you want to check if one string (text) is the same as an other
Always use Strcmp (string compare) not ==
https://sampwiki.blast.hk/wiki/Strcmp
Reply
#4

Quote:
Originally Posted by FireCat
Посмотреть сообщение
pawn Код:
YCMD:login(playerid, params[], help)
{
    new pFile[100], pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    format(pFile, sizeof(pFile), "Accounts/%s.ini", pName);
    new string[256],string2[256];
    format(string,sizeof(string),"%s",dini_Get(pFile,"Password"));
    format(string2,sizeof(string),"%s",params);
   
    if(!dini_Exists(pFile)) return SendClientMessage(playerid,0x00FF00AA,"You are not registered! Please /register");
    if(strcmp(string,string2) != 0) return  SendClientMessage(playerid,0x00FF00AA,"wrong!");
    if(strcmp(string,string2) == 0)
        {
        SendClientMessage(playerid,0x00FF00AA,"WORKS YEAAAAAAA");
        }
        return 1;
}
When you want to check if one string (text) is the same as an other
Always use Strcmp (string compare) not ==
https://sampwiki.blast.hk/wiki/Strcmp
Works like a charm! mind giving me tip on how to +rep you ?
Reply
#5

Quote:
Originally Posted by [JnA]DukeNukem
Посмотреть сообщение
Works like a charm! mind giving me tip on how to +rep you ?
Click on Under my name
Glad I helped you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)