SA-MP Forums Archive
HELP.. "Friend" system.. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: HELP.. "Friend" system.. (/showthread.php?tid=150845)



HELP.. "Friend" system.. - Faith - 28.05.2010


I'm thinking of some kind of friend system, where you can /addfriend, /remove friend, and then it shows nametag.

I have an idea to do it something like this:

dini_IntSet ("[playername].txt", [friendsname], 1); (1 = friend, 0 = no friend).
So the file will look like this.
John_O.txt
Dave_L=1 ( FRIEND)
Kurt=0 (NO FRIEND).

Then on player connect, it finds everyone that is friends and will Show nametag within range.
(ofcourse for both parts).

Is there some way to do this?
- Or do you have an even better idea?


Re: HELP.. "Friend" system.. - (SF)Noobanatior - 28.05.2010

why not if your mode already uses dini and your wanting so save friends


Re: HELP.. "Friend" system.. - Faith - 28.05.2010

I'm not quite sure how to save the friends into dini files, and then make it show nametag in-game.

But if there is a better way, then i'd like to use that instead



Re: HELP.. "Friend" system.. - Jay_ - 28.05.2010

There is a better way... don't use dini


Re: HELP.. "Friend" system.. - Faith - 28.05.2010

Really?

Do you have any idea how that could be?

Much appreciated, thanks.


Re: HELP.. "Friend" system.. - Faith - 28.05.2010

I managed to create a file for every player on connect.

John_O.txt

In that file, it now says:
Dave_Sandman=1
Kurt=0
Don_O=1

How can i do, so that it will show nametag for everyone that has the value 1, in that file?.


Thanks in advance.


It looks like this btw:
Код:
public OnPlayerconnect(playerid)
{

// FRIENDS
  new NAME[MAX_PLAYER_NAME];
  GetPlayerName(playerid, NAME, sizeof(NAME));

  format(Friend, sizeof(Friend), "/FRIENDS/%s.txt", NAME);
		if(!dini_Exists(Friend)) { dini_Create(Friend); }


 		dini_IntSet(Friend, NAME, 1); // Just checking the file.

return 1;
}



Re: HELP.. "Friend" system.. - (SF)Noobanatior - 29.05.2010

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[256],Friend[256];
    new idx;
  cmd = strtok(cmdtext, idx);
 
    if (strcmp("/addfriend", cmd, true, 10) == 0)
    {
   
    if(!strlen(tmp)) {
            SendClientMessage(playerid,0xAFAFAFFF,"Usage: /AddFriend (id)");
            return 1;
        }
        new id = strval(tmp);
        if(!IsPlayerConnected(id)) {
            SendClientMessage(playerid,0xAFAFAFFF,"/AddFriend : Bad player ID");
            return 1;
        }
        if(playerid == id) {
          SendClientMessage(playerid,0xAFAFAFFF,"You Cant be friends with yourself");
            return 1;
        }
        if(!dini_Exists(Friend)) {
            SendClientMessage(playerid,0xAFAFAFFF,"You Dont have a save file");
            return 1;
        }
        new NAME[MAX_PLAYER_NAME],FriendName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, NAME, sizeof(NAME));
        format(Friend, sizeof(Friend), "/FRIENDS/%s.txt", NAME);
      GetPlayerName(id, FriendName, sizeof(FriendName));
        dini_Set(Friend, "Friend1",     FriendName);
        return 1;
        }
    }
    return 0;
}
that should add a name to the file i think not tested though


Re: HELP.. "Friend" system.. - (SF)Noobanatior - 29.05.2010

and some thing like this to set the friends for a player again not tested but both compile

pawn Код:
public GetPlayersFriends(playerid) {
    new playername[MAX_PLAYER_NAME],friendname[256];
    new fstr[128];
    GetPlayerName(playerid, playername, sizeof(playername));
    format(fstr,sizeof(fstr),"/FRIENDS/%s.txt",playername);
    if (dini_Exists(fstr))  {
        if(dini_Isset(fstr,"Friend1")){
            friendname = dini_Get(fstr, "Friend1");
            for(new i=0;i<MAX_PLAYERS;i++) {
              if(!IsPlayerConnected(i))continue;
              new tmpname[MAX_PLAYER_NAME];
              GetPlayerName(i, tmpname, sizeof(tmpname));
              if (strcmp(friendname, tmpname, true, sizeof(friendname) == 0){
                //found friend on server
                ShowPlayerNameTagForPlayer(playerid,i,true);
              }
            }
             
        }
    }
    return 1;
}



Re: HELP.. "Friend" system.. - Faith - 29.05.2010

Damn!

I appreciate your time making this.

I'll look into it right away. Thanks alot!


Re: HELP.. "Friend" system.. - (SF)Noobanatior - 29.05.2010

winning?


Re: HELP.. "Friend" system.. - Faith - 30.05.2010

Not quite, no.
I've tried modifying it a bit aswell.

No work.
I've tried with timers changing the code a little, but still no change.

The nametag won't show up.

I'm thinking to change it to another way, so that nametags won't show up at all, but in the chat it will change the name: Stranger, to his current name - if he's a friend.

That should be possible somehow, and i will attempt to use this code you've given me to help me to get started with.


Re: HELP.. "Friend" system.. - RedShirt - 30.05.2010

I think you need more practice with this script,
also try to make some other stuff.


Re: HELP.. "Friend" system.. - azzerking - 30.05.2010

Yes try learning more about scripting to continue with this script


Re: HELP.. "Friend" system.. - iLinx - 30.05.2010

This is better done with MySQL (its easier and faster in the longrun aswell).
You could create a users table and a friends table, which would contain symbolic links to the friends ID.

IE:

table users
username | userID | money

table friends
userID | targetID

Example implementation

table users
joe | 0 | 1000
bob | 1 | 2000
sky | 2 | 500

table friends
0 | 2
2 | 1

Therefore, Joe is friends with sky, bob is friends with sky, sky has two friends, likewise the other two only have one. This is much easier done than said in MySQL, it could be made in under an hour if you know what your doing.


Re: HELP.. "Friend" system.. - azzerking - 30.05.2010

Hmmmm Nice Ilinx

Good Work

I Suggest U Use Ilinx Idea Its Better And Easier


Re: HELP.. "Friend" system.. - Calgon - 30.05.2010

Quote:
Originally Posted by iLinx
This is better done with MySQL (its easier and faster in the longrun aswell).
You could create a users table and a friends table, which would contain symbolic links to the friends ID.

IE:

table users
username | userID | money

table friends
userID | targetID

Example implementation

table users
joe | 0 | 1000
bob | 1 | 2000
sky | 2 | 500

table friends
0 | 2
2 | 1

Therefore, Joe is friends with sky, bob is friends with sky, sky has two friends, likewise the other two only have one. This is much easier done than said in MySQL, it could be made in under an hour if you know what your doing.
This would be the best thing to do, simply because it's a) more efficient and b) more easy to handle, it'll be understandably more difficult to create for a newbie, but I suppose it is pretty much a learning curve.


Re: HELP.. "Friend" system.. - Faith - 30.05.2010

Sounds pretty cool.

Any ideas of how i could get to start with such thing?
I've never tried mySQL before though.


About scripting, then i can't really attempt to learn more as it is now.
I'm about to be at the end part of my script. Just finishing up some stuff, and this is one of them.

I appreciate your answers, everyone.


Re: HELP.. "Friend" system.. - david_silva_111 - 06.08.2010

..........