Not able to get a player's ID by his name.
#1

First of all thank you for reading this.

Alright, so I got the following code:
pawn Код:
stock ConvertOwnerName(playerid)
{
    for(new i = 0; i <= MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            GetPlayerName(i, pname, sizeof(pname));
            GetHouseID(playerid);
            format(file, sizeof(file), "Houses/House_%d.ini", HouseID);
            format(OwnerName, sizeof(OwnerName), "%s", dini_Get(file, "Owner"));
            if(strcmp(pname, OwnerName) == 0) return OwnerID = i;
        }
    }
    return 1;
}
which is used to convert a house owner's name into his ID if he's online. If not the money will just go to his 'bank account' but that's in a different code.

Anyway, the problem is that I can not convert the name into the player's ID.. it just does nothing.
Reply
#2

Is the loop working?
I'm not sure if this would solve anything, but change the loop to for(new i = 0; i < MAX_PLAYERS; i++), remove the '='.
That's all I see.
You might want to debug the code if you're not sure, just place 'print("So far 1");', 'print("So far 2");' troughout the function, and when you call it, look in your console to see whether it's called or not.
Reply
#3

I will debug it, remove the ' = ' even though I also don't think it will effect anything, but it's worth to try.
I will edit this post with the result when I'm done.

I debugged it, it prints the ID of the player who bought the house, not the one who owns it, I will check the code out, I will reply here if I can not find any way to get it working.
Reply
#4

Then u never have updated the owners name!
Reply
#5

Quote:
Originally Posted by park4bmx
Посмотреть сообщение
Then u never have updated the owners name!
I did, I checked the house's file, it is saved the way it should.
OH......... Now I understand my problem, I used this line AFTER I changed the owner's name in the file. Thank you!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)