Comparing string :( -
Rudy_ - 15.10.2014
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 :/
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))))
Re: Comparing string :( -
Anzipane - 15.10.2014
pawn Код:
if (strcmp(GroupInfo[9][gLeader], sendername(playerid)) == 0) // If they are the same
{
// Code here
}
Re: Comparing string :( -
Rudy_ - 15.10.2014
I tried that, I could still delete a group made by different name...
Re: Comparing string :( -
Anzipane - 15.10.2014
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.
Re: Comparing string :( -
Cell_ - 15.10.2014
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..
Re: Comparing string :( -
Rudy_ - 15.10.2014
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?
Re: Comparing string :( -
Rudy_ - 15.10.2014
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")
Re: Comparing string :( -
Blunt - 15.10.2014
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
Re: Comparing string :( -
Cell_ - 15.10.2014
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
}
}
Re: Comparing string :( -
Rudy_ - 15.10.2014
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