SA-MP Forums Archive
Array manipulation - 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: Array manipulation (/showthread.php?tid=246239)



Array manipulation ( Fixed thank you to all for the help) - Hornet600 - 03.04.2011

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.


Re: Array manipulation - iggy1 - 03.04.2011

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?


Re: Array manipulation - Hornet600 - 03.04.2011

yes it stores the name i used strmid


Re: Array manipulation - iggy1 - 03.04.2011

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


Re: Array manipulation - Hornet600 - 03.04.2011

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


Re: Array manipulation - iggy1 - 03.04.2011

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;
}



Re: Array manipulation - Hornet600 - 03.04.2011

fail it returned the id 0 again


Re: Array manipulation - iggy1 - 03.04.2011

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.


Re: Array manipulation - Hornet600 - 03.04.2011

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...


Re: Array manipulation - Miguel - 03.04.2011

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