#1

Hello,

Could you explain to me how Enums work? I want to use them to create jobs, admin system and such.

Thank you in advance my friends.
Reply
#2

https://sampwiki.blast.hk/wiki/Keywords:Initialisers
Reply
#3

Thank you Lorenc_ for it. But, I need somebody to explain some stuff to me about those Enums or Initialisers :'[.
Reply
#4

An enum is practicly a couple variables, which is stored in one variable.
pawn Код:
enum pInfo {
    // everything you want to save goes down here Ex:
    Money,
    Admin
}
Now we got an enum but its unused. So lets use it.
pawn Код:
new PlayerInfo[MAX_PLAYERS][pInfo];
Now this variable holds 'MAX_PLAYERS', and 'pInfo'. MAX_PLAYERS is to bind the variable to an player, and the 'pInfo' holds the variables which are stored in the enum.
If you want to use the variables, you can do it like this:
pawn Код:
PlayerInfo[playerid][Admin] = 1;
if( PlayerInfo[playerid][Admin] == 1 )
PlayerInfo[playerid][Money] = 1;
if( PlayerInfo[playerid][Money] == 1 )
Those are just examples ofcourse, fit it to your needs, and if you dont get something just post again and im sure there will be someone to reply!
Reply
#5

Thanks a lot Wesley221! That was greatly helpful but I would like to go deeper in the Enums .
Reply
#6

Then you need to look for tutorials, or other people to help you. I cant really help you further, since i dont really work with enums alot.
And also like Lorenc_ said, just take a look at https://sampwiki.blast.hk/wiki/Keywords:Initialisers, and then you probably got some extra information aswell
Reply
#7

Enums are just a collection of several variables.
These variables can be anything: integers, floating point numbers and strings/arrays.

pawn Код:
enum PlayerInfo
{
    Money,
    Float:x, Float:y, Float:z,
    PlayerName[24]
}
new PlayerData[MAX_PLAYERS][PlayerInfo];
In this example, you create an enum that has 6 "fields" (or variables) inside it: 1 integer (Money), 3 floating point variables (x, y, z) and a string (PlayerName).
This enum holds all the data for only one player, so you need several copies of that enum to hold all data for ALL players at once.

Then you create an array to hold all this data for every player.
Since MAX_PLAYERS is by default set to 500, you now have 500 copies of that enum inside that array, one for every player.

But this code won't do much right now, let's use it:
pawn Код:
PlayerData[5][Money] = GetPlayerMoney(5);
GetPlayerPos(5, PlayerData[5][x], PlayerData[5][y], PlayerData[5][z]);
GetPlayerName(5, PlayerData[5][PlayerName], 24);
On the first line, you get the amount of money of the player with ID 5.
That value is returned by GetPlayerMoney and is stored in the Money variable of the enum for player 5.

Then the current position of the player gets stored in the x, y and z variables of the enum for player 5.

Finally the name is stored in the PlayerName variable of the enum of player 5.

You can use those variables too for checking data with if-statements and other things (while, for, ...):
pawn Код:
if (PlayerData[5][Money] > 100000)
    SendClientMessage(5, 0xFFFFFFFF, "You're rich");
This would send "You're rich" to the player with ID 5 when his money is more than 100.000.

Or to inform all players if they're rich:
pawn Код:
for (new playerid; playerid < MAX_PLAYERS; playerid++)
{
    if (PlayerData[playerid][Money] > 100000)
        SendClientMessage(playerid, 0xFFFFFFFF, "You're rich");
}
Reply
#8

Deleted.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)