Comparing string :(
#1

Hello everyone, Recently i've tried to do some group/gang system. I got most of the things working, But i can't seem to be comparing two names. I wanted to do that if i create a group, i save the Leader name. If i want to delete the group , My name must match to the group leader name. But not working :/

pawn Код:
#define MAX_GROUPS 10
Tried this
pawn Код:
if(!strcmp(GroupInfo[9][gLeader], sendername(playerid), true))
and this too, But
pawn Код:
if(strcmp(sendername(playerid), GroupInfo[9][gLeader], false, strlen(sendername(playerid))))
Reply
#2

pawn Код:
if (strcmp(GroupInfo[9][gLeader], sendername(playerid)) == 0) // If they are the same
{
    // Code here
}
Reply
#3

I tried that, I could still delete a group made by different name...
Reply
#4

Quote:
Originally Posted by Rudy_
Посмотреть сообщение
I tried that, I could still delete a group made by different name...
Then the problem must be in one of these two strings.
Try checking sendername(playerid) and GroupInfo[9][gLeader] values at run-time.
Reply
#5

Are you sure you are going for faction ID 9 and that both names match? Try printing both strings (leader name, player name) and see if they match.

Edit: Didn't see the above post, he has posted while I was typing..
Reply
#6

i save gLeader to a file, here's what in the file
Owner = [Are]SilenT
then when i use the command, i compare playername with Owner (gLeader) name

/creategroup command
pawn Код:
INI_WriteString(File, "Owner", GroupInfo[gid][gLeader]);
It writes the name correctly, ? what could possibly be wrong?
Reply
#7

Quote:
Originally Posted by Cell_
Посмотреть сообщение
Are you sure you are going for faction ID 9 and that both names match? Try printing both strings (leader name, player name) and see if they match.

Edit: Didn't see the above post, he has posted while I was typing..
Oh, that could be the problem
if (strcmp(GroupInfo[9][gLeader], sendername(playerid)) == 0)

I tried it like this before
pawn Код:
if (strcmp(GroupInfo[MAX_GROUPS][gLeader], sendername(playerid)) == 0)
Which gave errors
Код:
error 032: array index out of bounds (variable "GroupInfo")
Reply
#8

Create this stock

Код:
stock GetName(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}
Код:
if(strcmp(GetName(playerid), GroupInfo[9][gLeader], false) != 0) // Check if the player isn't the leader
Reply
#9

Quote:
Originally Posted by Rudy_
Посмотреть сообщение
Oh, that could be the problem
if (strcmp(GroupInfo[9][gLeader], sendername(playerid)) == 0)

I tried it like this before
pawn Код:
if (strcmp(GroupInfo[MAX_GROUPS][gLeader], sendername(playerid)) == 0)
Which gave errors
Код:
error 032: array index out of bounds (variable "GroupInfo")
NO! MAX_GROUPS will not work! Try:
pawn Код:
if (strcmp(GroupInfo[groupid][gLeader], sendername(playerid)) == 0)
where groupid is the id you want to destroy. For example:
pawn Код:
CMD:destroygroup(playerid, params[])
{
    new groupid;
    if(sscanf("i", groupid))
    {
        ...;
    }

    if(!strcmp(GroupInfo[groupid][GroupInfo], sendername(playerid)))
    {
        Code to destroy here
    }
}
Reply
#10

Quote:
Originally Posted by Cell_
Посмотреть сообщение
NO! MAX_GROUPS will not work! Try:
pawn Код:
if (strcmp(GroupInfo[groupid][gLeader], sendername(playerid)) == 0)
where groupid is the id you want to destroy. For example:
pawn Код:
CMD:destroygroup(playerid, params[])
{
    new groupid;
    if(sscanf("i", groupid))
    {
        ...;
    }

    if(!strcmp(GroupInfo[groupid][GroupInfo], sendername(playerid)))
    {
        Code to destroy here
    }
}
pawn Код:
new groupid;
    new groupid;
    if(sscanf(params,"i", groupid))
This? I'll try
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)