SA-MP Forums Archive
Can I use such arrays? - 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: Can I use such arrays? (/showthread.php?tid=427614)



Can I use such arrays? - Darth1993 - 02.04.2013

Hello.

I'm currently working on battlefield server (writting from scratch) and after testing I noticed, that console outputs not array values from enum, but weird symbols and smiles.

So, my question is:

Can I use such arrays?
Код:
enum pInfo
{
	// 0 - assault, 1 - engineer, 2 - sniper, 3 - medic
	rank_lvl, // 30 total
	experience, // current experience points
	Float:health, Float:armor,
	credits, kills, deaths, score, timePlayed,
}
new PlayerInfo[MAX_PLAYERS][4][pInfo];
There gonna be 4 classes per player and each class will have different stats and player will need to increase stats and etc individually.

For example: Assault class rank_lvl = PlayerInfo[playerid][0][rank_lvl];


Re: Can I use such arrays? - Konstantinos - 02.04.2013

Sometimes that happens when for example, instead of printing an integer, you're using '%s' which is for strings or the opposite, I don't remember.

Would you mind to show us the part that prints the values?


Re: Can I use such arrays? - faff - 02.04.2013

pawn Код:
enum pInfo
{
    ranklvl,
    experience,
    Float:health,
    Float:armor,
    credits,
    kills,
    deaths,
    score,
    timePlayed,
}
new PlayerInfo[MAX_PLAYERS][pInfo];



Re: Can I use such arrays? - Darth1993 - 02.04.2013

Quote:
Originally Posted by faff
Посмотреть сообщение
pawn Код:
enum pInfo
{
    ranklvl,
    experience,
    Float:health,
    Float:armor,
    credits,
    kills,
    deaths,
    score,
    timePlayed,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
I'm using such enum for account data, but as I said, I have four characters (classes) per account, so I need to store classes in different way. I need to have individual enum for each character (class).


Re: Can I use such arrays? - faff - 02.04.2013

Quote:
Originally Posted by Darth1993
Посмотреть сообщение
I'm using such enum for account data, but as I said, I have four characters (classes) per account, so I need to store classes in different way. I need to have individual enum for each character (class).
Ahh, I dont know if it's possible.
I never tested it.. so ehmm.. I dont know.


Re: Can I use such arrays? - Darth1993 - 02.04.2013

Quote:
Originally Posted by Dwane
Посмотреть сообщение
Sometimes that happens when for example, instead of printing an integer, you're using '%s' which is for strings or the opposite, I don't remember.

Would you mind to show us the part that prints the values?
I just noticed that I'm using printf(PlayerInfo[playerid][classid][experience]);

Changed to printf("Exp: %d", PlayerInfo[playerid][classid][experience]); and it's showing the right value.

So, problem solved.


Re: Can I use such arrays? - Pottus - 02.04.2013

If your going to use something like this....

new PlayerInfo[MAX_PLAYERS][4][pInfo];

At least make some defines.....

#define MAX_CLASSES 4
#define CLASS_CLASSNAME1 0
#define CLASS_CLASSNAME2 1
#define CLASS_CLASSNAME3 2
#define CLASS_CLASSNAME4 3

This is much easier to keep track of what your writing.

new PlayerInfo[MAX_PLAYERS][MAX_CLASSES ][pInfo];

for(new i = 0; i < MAX_CLASSES; i++)

if(PlayerInfo[playerid][CLASS_CLASSNAME][p_Kill] == 10) KillSpree = true;

It looks a lot better I think.


Re: Can I use such arrays? - glbracer - 02.04.2013

For an array inside an enum (example would be pInfo) you'd have to do
PlayerInfo[playerid][pInfo][array];
So, for this you should try
pawn Код:
enum pInfo
{
  kills[4],
  deaths[4],
  score[4],
  // The rest of your pInfo enumerator.
}
new PlayerInfo[MAX_PLAYERS][pInfo];

// Insert this and edit where needed and appropriate.
if(PlayerInfo[playerid][pClass] == 0) { PlayerInfo[playerid][kills][0]++; } // And so on.