Will strval convert a player's name to the player's ID?
#1

As the title says, will "strval" convert a player's name to his ID?
Reply
#2

no. its meant to convert a numerical expressed by a string, into an integer number which contains 4 bytes only:
pawn Код:
new a=strval("12345");
when you know the players name, you had to retrieve it by using GetPlayerName(playerid,..);, therefore i think the playerid is already known?
Reply
#3

Not at all. This is how I am using it:

pawn Код:
if (strcmp("/buyhouse", cmdtext, true, 10) == 0)
    {
        GetHouseID(playerid);
        format(file, sizeof(file), "House_%d.ini", HouseID);
        forSale = dini_Get(file, "ForSale");
        houseOwned = dini_Get(file, "Owned");
        hValue = dini_Get(file, "Price");
        if(strval(forSale) == 1)
        {
            if(strval(houseOwned) == 1)
            {
                OwnerName = dini_Get(file, "Owner");
                GetPlayerName(playerid, name, sizeof(name));
                if(strcmp(name, OwnerName) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: You may not buy your own houses");
                if(GetPlayerMoney(playerid) >= strval(hValue))
                {
                    GivePlayerMoney(playerid, GetPlayerMoney(playerid)-strval(hValue));
                    GivePlayerMoney("OwnerName", strval(hValue)/100*75);
                    dini_Set(file, "Owner", name);
                    dini_IntSet(file, "Price", INVALID_HOUSE_PRICE);
                    dini_IntSet(file, "ForSale", 0);
                    dini_IntSet(file, "Pickupid", 1273);
                    dini_IntSet(file, "Owned", 1);
                }
            }
        }
        return 1;
    }
On a house creation, the "Owner" is defined as "None". Although when a player buys the house, his name will replace the "None", notice that "houseOwned".

So, I do have the player's name.. but what now?
Reply
#4

Why are you not using dini_GetInt, which should internally do the very same - get the string and then strval() it?

Also you do know the player's ID and name in the code above.
Reply
#5

For the dini_GetInt I never heard about that command, thank you for mentioning it.

And for the rest, no, I only know the player's name. How may I convert it into the player's ID?
Reply
#6

You can get the playerid from the player name, just compare it:
pawn Код:
foreach ( new i: Player)
{
  if(strcmp(playername, GetPlayerName(..i), true) != -1)
  return i;
}
Reply
#7

I was thinking about making a stock which would do the same action with a few more lines. But with foreach as I see now, I can make it using 5 lines. Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)