Array manipulation
#1

Im having problems with enum arrays this is bugs some values of my script.
Ok lets start with enums:

pawn Код:
enum users
{
    Name[MAX_PLAYER_NAME],
}
new playerinfo[MAX_PLAYERS][users];


enum vInfo
{
    Owner[MAX_PLAYER_NAME],
}
new vehicleinfo[MAX_VEHICLES][vInfo];
Ok looks all alright but there is a big problem with advanced structures.

One exemple I want to get a player name from the vehicleinfo Owner

so I do:
pawn Код:
new pid = GetPlayerID(vehicleinfo[vehicleid][Owner]);
pid will be the playerid but it bugs because it returns always the id number 0

so if there are two players it will return always to id 0 and not
the correct vehicle owner.

I hope someone knows how to manages arrays well to help me sort this bug out please.
Reply
#2

Could be something to do with the "GetPlayerID" function. And are you sure you have actually stored a name in the array before using it?
Reply
#3

yes it stores the name i used strmid
Reply
#4

But have you printed the string to make sure it holds a name?
Reply
#5

the GetPlayerId stock
pawn Код:
stock GetPlayerID(const PName[])
{
    for(new i; i<MAX_PLAYERS; i++)
    {
      if(IsPlayerConnected(i))
      {
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(i, pName, sizeof(pName));
        if(strcmp(PName, pName, true)==0)
        {
          return i;
        }
      }
    }
    return -1;
}

EDIT: Yes i printed look here [15:31:34] Owner = James_Cullen
Reply
#6

It might be the strcmp function try this one.
pawn Код:
stock GetPlayerID(const PName[])
{
    for(new i; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            new pName[MAX_PLAYER_NAME];
            GetPlayerName(i, pName, sizeof(pName));
            if(!strcmp(PName, pName))
            {
                return i;
            }
        }
    }
    return -1;
}
Reply
#7

fail it returned the id 0 again
Reply
#8

Well if the array holds the name and you compare them with strcmp it should work. The name in the array isn't the same as the one passed to the function "GetPlayerID" else it would return the id the loop stops on. Or -1 if no name was matched. It should never return zero unless the name of id 0 is matched.
Reply
#9

i get your point but if the variables holds the player name why it isnt returning the right it? maybe a bug with enum? I don't really know...
Reply
#10

Try this:
pawn Код:
if(strcmp(PName, pName, true, strlen(pName)) == 0)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)