Need some help
#1

Hello,

I am trying to make when a player creates a gang, and the player's gangname is already choosen by someone else, it should send a message, but it ain't working.
Here's the code

pawn Код:
for(new i; i < TotalGangs; i++)
    {
        format(CheckName, sizeof(CheckName), Gang_File, i);
        if(DOF_FileExists(CheckName))
        {
            new gname[128];
            strcat(gname, DOF_GetString(CheckName, "Name"), 128);
            if(strcmp(GangName, gname, true) == 0)
            {
                SendClientMessage(playerid, Red, "A gang with this name already exists");
                return 1;
            }
        }
    }
It just keeps on making the gang, please help, thanks.
Rep will be given.
Reply
#2

Bump.
Reply
#3

Ignore me...

Give me a second.
Reply
#4

Quote:
Originally Posted by funky1234
Посмотреть сообщение
Ignore me...

Give me a second.
Hey, could you figure it out?
Reply
#5

Are you sure the original file exists. (The 'CheckName' file?)
Reply
#6

Yes, it does exists

pawn Код:
// This is my define for Gang_File

#define Gang_File "Gangs/%d.ini"

new TotalGangs;

public OnGameModeInit()
{
    if(!DOF_FileExists(CFG_File))
    {
        DOF_CreateFile(CFG_File);
        DOF_SetInt(CFG_File, "Gangs", 0);
        print("CFG File created");
    }
    else
    {
        TotalGangs = DOF_GetInt(CFG_File, "Gangs");
        for(new i = 0; i <= TotalGangs; i++)
        {
            GangInfo[i][Gangs] = i;
        }
        printf("CFG File loaded. %d gangs loaded", TotalGangs);
    }
    DOF_SaveFile();
    return 1;
}
There's the TotalGangs variable which also works, so yeah, maybe something wrong with the code I provided in the first post?
Reply
#7

I had another attempt but failed, I don't know what I have done wrong. Maybe with the strcmp or strcat line?
Reply
#8

Код:
for(new i; i < TotalGangs; i++)
    {
        format(CheckName, sizeof(CheckName), Gang_File, i);
        if(DOF_FileExists(CheckName))
        {
            new gname[128];
            strcat(gname, DOF_GetString(CheckName, "Name"), 128);
            if(!strcmp(GangName, gname, true) == 0)
            {
                SendClientMessage(playerid, Red, "A gang with this name already exists");
                return 1;
            }
        }
    }
Reply
#9

It gave me a tag mismatch warning, how can I fix it?
Reply
#10

Quote:
Originally Posted by Cowboy
Посмотреть сообщение
It gave me a tag mismatch warning, how can I fix it?
The user that posted above you, has placed an exclamation mark infront of the strcmp function. This has actually broken your code.

Doing !strcmp(...) is the same as doing strcmp(...) == 0, hence there is no difference.

The reason you are getting the warning is because you're doing two checks (checking with an exclamation mark and the == 0 method.

I'm unsure on your issue, though.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)