ID 0 bug - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: ID 0 bug (
/showthread.php?tid=652126)
ID 0 bug -
Exhibit - 03.04.2018
Hey. I've added some commands with the discord connector like /dchaton and /dchatoff to toggle between the Discord Chat but only id 0 is able to see the messages that are sent from discord to the samp server.
Code:
PHP код:
public DCC_OnChannelMessage(DCC_Channel:channel, DCC_User:author, const message[])
{
new channel_name[100 + 1];
if(!DCC_GetChannelName(channel, channel_name))
return 0;
new user_name[32 + 1];
if (!DCC_GetUserName(author, user_name))
return 0;
new str[145];
format(str, sizeof str, "{667aca}[Discord/%s] %s:{ffffff} %s", channel_name, user_name, message);
for(new i = 0; i < MAX_PLAYERS; i++){
if (DiscordStats[i]==0) return 0;
SendClientMessage(i, -1, str); }
return 1;
}
I want the it to show the messages to everyone who have Discord chat turned on but not the ones who don't have it on.
Re: ID 0 bug -
jlalt - 03.04.2018
return stops the loop, instead use, continue
PHP код:
for(new i = 0; i < MAX_PLAYERS; i++){
if (DiscordStats[i]==0) continue;
SendClientMessage(i, -1, str); }
Re: ID 0 bug -
Exhibit - 03.04.2018
Quote:
Originally Posted by jlalt
return stope the loop, instead use, continue
PHP код:
for(new i = 0; i < MAX_PLAYERS; i++){
if (DiscordStats[i]==0) continue;
SendClientMessage(i, -1, str); }
|
Thanks but I just fixed it with
PHP код:
for(new i; i < MAX_PLAYERS; i++){
if (DiscordStats[i]==0) return 0;
SendClientMessage(i, -1, str); }
Re: ID 0 bug -
AdamsLT - 03.04.2018
Quote:
Originally Posted by Exhibit
Thanks but I just fixed it with
PHP код:
for(new i; i < MAX_PLAYERS; i++){
if (DiscordStats[i]==0) return 0;
SendClientMessage(i, -1, str); }
|
That may have fixed for the problem for now but you left a flaw in your logic.
Example:
Green - message sent, red - message not sent:
DiscordStats[0] = true
DiscordStats[1] == true
DiscordStats[2] == true
DiscordStats[3] == true
DiscordStats[4] == false // loop stops because you return 0;
DiscordStats[5] == true
DiscordStats[6] == true
People from ID 4 (in this example) and onwards will not receive the message as the loop will have been stopped as ID 4 had their settings set to false and you returned 0.
Use the code jlalt provided to avoid this.
Re: ID 0 bug -
Exhibit - 04.04.2018
Quote:
Originally Posted by AdamsLT
That may have fixed for the problem for now but you left a flaw in your logic.
Example:
Green - message sent, red - message not sent:
DiscordStats[0] = true
DiscordStats[1] == true
DiscordStats[2] == true
DiscordStats[3] == true
DiscordStats[4] == false // loop stops because you return 0;
DiscordStats[5] == true
DiscordStats[6] == true
People from ID 4 (in this example) and onwards will not receive the message as the loop will have been stopped as ID 4 had their settings set to false and you returned 0.
Use the code jlalt provided to avoid this.
|
Thank you.