Little help -
Cowboy - 28.10.2011
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
Re: Little help -
Pinguinn - 28.10.2011
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;
}
}
}
Re: Little help -
admantis - 28.10.2011
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
|
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..
Re: Little help -
[MG]Dimi - 28.10.2011
This was told a thousands of times. Use isnull function incuded in ZCMD so it will be
PHP код:
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");
if(!isnull(params)) return SendClientMessage(playerid,-1,"Usage: /g [message]");
new string[128],pName[MAX_PLAYER_NAME];
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, params[0]);
SendClientMessage(i, Purple, string);
}
}
}
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);
|
Re: Little help -
FUNExtreme - 28.10.2011
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
Re: Little help -
Cowboy - 28.10.2011
@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
Re: Little help -
admantis - 28.10.2011
Try using the fix I told you: change the line to this
pawn Код:
if(PlayerInfo[i][Gang] == PlayerInfo[playerid][Gang])
Re: Little help -
Cowboy - 28.10.2011
That did it, thank you.
rep to all of you.