SA-MP Forums Archive
Not able to get a player's ID by his name. - 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)
+--- Thread: Not able to get a player's ID by his name. (/showthread.php?tid=423037)



Not able to get a player's ID by his name. - Denying - 16.03.2013

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.


Re: Not able to get a player's ID by his name. - Jstylezzz - 16.03.2013

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.


Re: Not able to get a player's ID by his name. - Denying - 16.03.2013

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.


Re: Not able to get a player's ID by his name. - park4bmx - 16.03.2013

Then u never have updated the owners name!


Re: Not able to get a player's ID by his name. - Denying - 16.03.2013

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!