GetEnumInt
#1

I want to be able to check enums between scripts without having to create a function for each.

I tried this
pawn Код:
public GetEnumInt(enumname[], id, var[]) return enumname[id][var];
Though it doesn't seem to work.

Basically, what i'm aiming to do, is if i'm in a different script module, I want to be able to use
pawn Код:
GetEnumInt("pInfo", playerid, "Admin");
to return their admin level, for example. I just don't want to have to create a separate function for each value, because of course, I could just use something like GetPlayerAdminLevel, or GetPlayer whatever. Though I don't want to spend all that time making all of those functions if I can get away with something a little neater.
Reply
#2

I just thought of a way to do it, i'll just use like GetPlayerInfo(playerid, "Admin"); will pretty much be the same thing, not sure why I didn't think of it before
Reply
#3

Okay, another problem.

I cant pull the variable from the array like that, this is what I've tried:
pawn Код:
forward GetPlayerInfo(playerid, var[]);
public GetPlayerInfo(playerid, var[]) return pInfo[playerid][var];
It returns array must be index error. I'm not sure how to make this work
Reply
#4

Use modules.
Reply
#5

Quote:
Originally Posted by Mionee
Посмотреть сообщение
Use modules.
I'm trying to take data from the gamemode to pass it through a module. For example, Get the player's admin level. But i'm trying to put it all in one function, so I don't need to make one for each variable, of course an option is PVars but...that's not happening.
Reply
#6

Quote:
Originally Posted by TakeiT
Посмотреть сообщение
I'm trying to take data from the gamemode to pass it through a module. For example, Get the player's admin level. But i'm trying to put it all in one function, so I don't need to make one for each variable, of course an option is PVars but...that's not happening.
You don't need to use a function like this when using modules.

Read Lordzy's tutorials:
https://sampforum.blast.hk/showthread.php?tid=540967
https://sampforum.blast.hk/showthread.php?tid=516617
Reply
#7

Quote:
Originally Posted by Mionee
Посмотреть сообщение
You don't need to use a function like this when using modules.

Read Lordzy's tutorials:
https://sampforum.blast.hk/showthread.php?tid=540967
https://sampforum.blast.hk/showthread.php?tid=516617
Those are just CallLocal/remoteFunction?

I'm aware that I need that, but in the core script you need the actual public function to call. That is the function that I am trying to make.
Reply
#8

Closest possible to what you are looking is:

In main script (Notice _: prefix in enum)
pawn Код:
enum _:PlayerInfo
{
    pAdmin,
    pBanned,
    pSomeString[24],
    pLevel,
    pMuted,
}
new pInfo[MAX_PLAYERS][PlayerInfo];

forward GetPlayerEnumInt(playerid, var);
public GetPlayerEnumInt(playerid, var)
{
    return pInfo[playerid][var];
}
Now you will have to copy same enum in your other script (You can name your enum however you want)

pawn Код:
enum _:EnumInFS//just example...
{
    pAdmin,
    pBanned,
    pString[24],
    pLevel,
    pMuted,
}
#define GetEnumInt(%0,%1)   CallRemoteFunction("GetPlayerEnumInt","%d%d",%0,%1)

//Now you can use it like   new something = GetEnumInt(playerid, pBanned);
//Or  if(GetEnumInt(playerid, pBanned) == 1) { do someting } ...

By the way i suggest you to use pVars, as they are meant for these and using these method you can not pass strings (at least not without getting char by char from other script...)
Reply
#9

Quote:
Originally Posted by TakeiT
Посмотреть сообщение
Those are just CallLocal/remoteFunction?

I'm aware that I need that, but in the core script you need the actual public function to call. That is the function that I am trying to make.
You don't need to follow Lordzy's tutorials if you use modules. Either way, try calling the enum variable's ID instead of the name.
Reply
#10

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
Closest possible to what you are looking is:

In main script (Notice _: prefix in enum)
pawn Код:
enum _:PlayerInfo
{
    pAdmin,
    pBanned,
    pSomeString[24],
    pLevel,
    pMuted,
}
new pInfo[MAX_PLAYERS][PlayerInfo];

forward GetPlayerEnumInt(playerid, var);
public GetPlayerEnumInt(playerid, var)
{
    return pInfo[playerid][var];
}
Now you will have to copy same enum in your other script (You can name your enum however you want)

pawn Код:
enum _:EnumInFS//just example...
{
    pAdmin,
    pBanned,
    pString[24],
    pLevel,
    pMuted,
}
#define GetEnumInt(%0,%1)   CallRemoteFunction("GetPlayerEnumInt","%d%d",%0,%1)

//Now you can use it like   new something = GetEnumInt(playerid, pBanned);
//Or  if(GetEnumInt(playerid, pBanned) == 1) { do someting } ...

By the way i suggest you to use pVars, as they are meant for these and using these method you can not pass strings (at least not without getting char by char from other script...)
Yes, that is what i'm trying to do. Though I don't like to use PVars, therefore I will not. The only thing I need help with is the part I posted

pawn Код:
public GetPlayerEnumInt(playerid, var)
{
    return pInfo[playerid][var];
}
That part. I tried something like that too, and it also doesn't work.

@Mionee, calling the ID returned tag mismatch.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)