Friend system issues
#1

Trying to solve it , thank you.
Reply
#2

someone please help me
Reply
#3

First of all, never ever query the database in a loop. Build the query earlier, call it once. Second of all, code looks ok at the first glance - to debug it, dump printf everywhere, then look at server console to see which steps were called and which weren't.
Reply
#4

i removed the loop and printed out all strings ,
once the player logins it only shows the querys selecting the players name but once it runs the function it returns "null" can u help pls ?
Reply
#5

Show me your new printf enhanced code and console results. Or tell me if FriendsOnline is called at all. If not, show your mysql logs.
Reply
#6

Trying to fix it.
Reply
#7

anyone please ?
Reply
#8

Well, maybe simply you don't have any friends (in database)
Reply
#9

the database is created and when i add a friend the names are saved ...
Reply
#10

Where is the null coming from? You only showed result, not where you put it. Please do it
Reply
#11

something like this you have to write
PHP Code:
table
-friend1,friend2

#define ci     cache_get_field_content_int
#define cs     cache_get_field_content
#define scm    SendClientMessage

enum UserEnum{
    
sid
};
new 
User[MAX_PLAYERS][UserEnum];

public 
OnPlayerConnect(playerid){
    new 
s[80],pid=playerid;
    
format(s,sizeof(s),"select friend1,friend2 where friend1=\'%d\' or friend2=\'%d\'",User[pid][sid],User[pid][sid]);
    new 
Cache:cq=mysql_query(sqlcon,s),f1,f2,uid=User[pid][sid];
    
format(s,sizeof(s),"[FRIEND] Your friend %s has Connected to the server.",RPName(pid));
    for(new 
i,i2=cache_num_rows(); i2i++){
        
f1=ci(i,"friend1"),f2=(i,"friend2");
        if(
f1==uid)MsgToSid(f2,COLOR_ADMIN_PM,s);
        else if(
f2==uid)MsgToSid(f1,COLOR_ADMIN_PM,s);
    }
    
cache_delete(cq);
    return 
1;
}

MsgToSid(sid,clr,msg[]){
    foreach(
Player,i){
        if(
User[i][sid]==sid)return scm(i,clr,msg);
    }
    return 
0;
}
 
NameFromSql(sid){
    new 
s[80];
    
format(s,sizeof(s),"select name from users where sid=\'%d\'",sid);
    new 
Cache:cq=mysql_query(sqlcon,s);
    if(
cache_num_rows())cs(0,s);
    else 
s="(Unknown)";
    
cache_delete(cq);
    return 
s;
}
 
cmd:friends(pid){
    new 
s[100],f1,f2,uid=User[pid][sid];
    
format(s,sizeof(s),"select friend1,friend2 where friend1=\'%d\' or friend2=\'%d\'",User[pid][sid],User[pid][sid]);
    new 
Cache:cq=mysql_query(s);
for(new 
i,i2=c_rowsi2i++){
        
f1=ci(i,"friend1"),f2=(i,"friend2");
        if(
f1==uid)format(s,sizeof(s),"Name: %s",NameFromSql(f2));
        else if(
f2==uid)format(s,sizeof(s),"Name: %s",NameFromSql(f1));
cache_set_active(cq);
        
scm(pid,-1,s);
    }
    
cache_delete(cq);
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)