ID 0 bug
#1

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:channelDCC_User:author, const message[])
{
    new 
channel_name[100 1];
    if(!
DCC_GetChannelName(channelchannel_name))
        return 
0;
    new 
user_name[32 1];
    if (!
DCC_GetUserName(authoruser_name))
        return 
0;
        
    new 
str[145];
    
format(strsizeof str"{667aca}[Discord/%s] %s:{ffffff} %s"channel_nameuser_namemessage);
    for(new 
0MAX_PLAYERSi++){
    if (
DiscordStats[i]==0) return 0;
    
SendClientMessage(i, -1str); }
    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.
Reply
#2

return stops the loop, instead use, continue
PHP код:
for(new 0MAX_PLAYERSi++){ 
    if (
DiscordStats[i]==0) continue; 
    
SendClientMessage(i, -1str); } 
Reply
#3

Quote:
Originally Posted by jlalt
Посмотреть сообщение
return stope the loop, instead use, continue
PHP код:
for(new 0MAX_PLAYERSi++){ 
    if (
DiscordStats[i]==0) continue; 
    
SendClientMessage(i, -1str); } 
Thanks but I just fixed it with

PHP код:
for(new iMAX_PLAYERSi++){
    if (
DiscordStats[i]==0) return 0;
    
SendClientMessage(i, -1str); } 
Reply
#4

Quote:
Originally Posted by Exhibit
Посмотреть сообщение
Thanks but I just fixed it with

PHP код:
for(new iMAX_PLAYERSi++){
    if (
DiscordStats[i]==0) return 0;
    
SendClientMessage(i, -1str); } 
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.
Reply
#5

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)