Friend system issues -
LazzyBoy - 07.08.2017
Trying to solve it , thank you.
Re: Friend system issues -
LazzyBoy - 08.08.2017
someone please help me
Re: Friend system issues -
Misiur - 08.08.2017
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.
Re: Friend system issues -
LazzyBoy - 08.08.2017
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 ?
Re: Friend system issues -
Misiur - 08.08.2017
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.
Re: Friend system issues -
LazzyBoy - 08.08.2017
Trying to fix it.
Re: Friend system issues -
LazzyBoy - 09.08.2017
anyone please ?
Re: Friend system issues -
Misiur - 09.08.2017
Well, maybe simply you don't have any friends (in database)
Re: Friend system issues -
LazzyBoy - 09.08.2017
the database is created and when i add a friend the names are saved ...
Re: Friend system issues -
Misiur - 09.08.2017
Where is the null coming from? You only showed result, not where you put it. Please do it
Re: Friend system issues -
CodeStyle175 - 09.08.2017
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(); i < i2; i++){
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_rows; i < i2; i++){
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;
}