Little help
#1

Hello all.

I've got this:

pawn Код:
COMMAND:g(playerid, params[])
{
    if(!PlayerInfo[playerid][Gang]) return SendClientMessage(playerid, Red, "You have to be a member of a gang to use this command");
    new string[128], pName[MAX_PLAYER_NAME];
    if(sscanf(params, "s[128]", string)) return SendClientMessage(playerid, Yellow, "Usage: /g <message>");
    GetPlayerName(playerid, pName, sizeof(pName));
    for(new i; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][Gang])
            {
                format(string, sizeof(string), "( %s ) %s: %s", GetGangName(PlayerInfo[i][Gang]), pName, string);
                SendClientMessage(i, Purple, string);
            }
        }
    }
    return 1;
}


stock GetGangName(GangID)
{
    new Query[150]; format(Query, sizeof(Query), "SELECT name FROM gangs WHERE id = %d;", GangID);
    mysql_query(Query);
    mysql_store_result();
    mysql_fetch_field_row(Query, "name");
    return Query;
}
So the problem is, when player 1 sends a message, it will work fine. But when player 2 sees player 1 message it will be double. example: "( gangname ) Player1: ( gangname ) Cowboy: test.

Why does it do that? please help
Reply
#2

Try this

pawn Код:
for(new i; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][Gang])
            {
                format(string, sizeof(string), "( %s ) %s: %s", GetGangName(PlayerInfo[i][Gang]), pName, string);
                SendClientMessage(i, Purple, string);
                return 1;
            }
        }
    }
Reply
#3

Quote:
Originally Posted by Cowboy
Посмотреть сообщение
Hello all.

I've got this:

pawn Код:
COMMAND:g(playerid, params[])
{
    if(!PlayerInfo[playerid][Gang]) return SendClientMessage(playerid, Red, "You have to be a member of a gang to use this command");
    new string[128], pName[MAX_PLAYER_NAME];
    if(sscanf(params, "s[128]", string)) return SendClientMessage(playerid, Yellow, "Usage: /g <message>");
    GetPlayerName(playerid, pName, sizeof(pName));
    for(new i; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][Gang])
            {
                format(string, sizeof(string), "( %s ) %s: %s", GetGangName(PlayerInfo[i][Gang]), pName, string);
                SendClientMessage(i, Purple, string);
            }
        }
    }
    return 1;
}


stock GetGangName(GangID)
{
    new Query[150]; format(Query, sizeof(Query), "SELECT name FROM gangs WHERE id = %d;", GangID);
    mysql_query(Query);
    mysql_store_result();
    mysql_fetch_field_row(Query, "name");
    return Query;
}
So the problem is, when player 1 sends a message, it will work fine. But when player 2 sees player 1 message it will be double. example: "( gangname ) Player1: ( gangname ) Cowboy: test.

Why does it do that? please help
pawn Код:
if(PlayerInfo[i][Gang])
That will only check if that value is positive (or above 0..). You can use this, instead:
pawn Код:
if(PlayerInfo[i][Gang] == PlayerInfo[playerid][Gang])
to comprove the gang of "i" is equal to "playerid".

I doubt this is the fix to your problem but it's also important or it will be buggy..
Reply
#4

This was told a thousands of times. Use isnull function incuded in ZCMD so it will be

PHP код:
COMMAND:g(playeridparams[])
{
    if(!
PlayerInfo[playerid][Gang]) return SendClientMessage(playeridRed"You have to be a member of a gang to use this command");
    if(!
isnull(params)) return SendClientMessage(playerid,-1,"Usage: /g [message]");    
    new 
string[128],pName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpNamesizeof(pName));
    for(new 
iMAX_PLAYERS++)
    {
        if(
IsPlayerConnected(i))
        {
            if(
PlayerInfo[i][Gang])
            {
                
format(stringsizeof(string), "( %s ) %s: %s"GetGangName(PlayerInfo[i][Gang]), pNameparams[0]);
                
SendClientMessage(iPurplestring);
            }
        }
    }
    return 
1;

Also problem in your function is that you are inserting string that you are formating into same string.

Quote:

format(string, sizeof(string), "( %s ) %s: %s", GetGangName(PlayerInfo[i][Gang]), pName, string);

Reply
#5

Quote:
Originally Posted by [MG]Dimi
Посмотреть сообщение
Also problem in your function is that you are inserting string that you are formating into same string.
You can do that, try it
Reply
#6

@Pinguinn: That stopped the code working.

@admantis: Should I only change that line? Or also the one in the string line

@[MG]Dimi: Changed it like that worked.

But there is one problem now. Let's say player 1 creates a gang and player 2 creates a gang. Player 1 writes a message and it will show it's gang name but it will also show to player 2, but with player 2's gang name. And vice versa
Reply
#7

Try using the fix I told you: change the line to this
pawn Код:
if(PlayerInfo[i][Gang] == PlayerInfo[playerid][Gang])
Reply
#8

That did it, thank you.

rep to all of you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)