String comparison
#1

I got this code:

Код:
#include <a_samp>
#include <YSI/y_ini>
#include "../include/gl_common.inc"
#include <string>

#define FILTERSCRIPT
#define COLOR_WHITE 0xFFFFFFFF

new PlayerName[MAX_PLAYER_NAME], Password[MAX_PASSWORD];

INI:playerlist[](playerid, name[], value[])
{
    INI_String(PlayerName, Password, sizeof(Password));
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[]){
    new idx;
    new cmd[256];
	cmd = strtok(cmdtext, idx);

    if(strcmp("/ls", cmd, true) == 0){
		GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
	    INI_Load("playerlist.ini", true, playerid);     // if set to true, playerid will be passed over to INI:playerlist[...
	    SendClientMessage(playerid, COLOR_WHITE, Password);
	    if(strcmp(Password, "") == 0){
			ShowPlayerDialog(playerid, 30, 1, "Register", "To register you must first give in the first name of your character.", "OK", "Cancel");
			return 1;
	    }
	    else{
	        ShowPlayerDialog(playerid, 33, 1, "Login", "Please give in your password.", "OK", "Cancel");
	        return 1;
		}
	}
    return 0;
}
So when the string Password is empty you'll get the register dialog, however when Password contains "somepass" or any other text it will still show the register dialog. I've tried to edit Password manually but nothing seems to work. The SendClientMessage will allways show the password in the playerlist.ini so I think the error lies int strcmp?

EDIT: I defined MAX_PASSWORD in <a_samp>
Reply
#2

Comparing to an empty string will always return false, so that snippet of code won't work, instead of strcmp use strlen, for example:

pawn Код:
if(strlen(Password) == 0)
Reply
#3

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Comparing to an empty string will always return false, so that snippet of code won't work, instead of strcmp use strlen, for example:

pawn Код:
if(strlen(Password) == 0)
OH MY F.. god
waarom ben ik daar niet op gekomen !!
maar bedankt
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)