Retrieving variables from GM to FS
#1

Hey there, Is it possible to retrieve some PARTICULAR player variable(s) from the gamemode to fs? For example, How can I retrieve the player's admin level from gamemode and store it in player's admin level which is inside the filterscript.

I've heard something like this, but still can't remember how it was possible.

Hope someone would help me,
Thanks.
Reply
#2

An easy way to do this is PVars.

https://sampwiki.blast.hk/wiki/SetPVarInt
https://sampwiki.blast.hk/wiki/GetPVarInt

An example of this:
pawn Код:
//In an admin filterscript
SetPVarInt(playerid, "AdminLevel", 4); //Set my admin level to 4.
pawn Код:
//In my main gamemode...
new adminlevel = GetPVarInt(playerid, "AdminLevel"); //This will return '4', so adminlevel = 4.
if(adminlevel < 5) return SendClientMessage(playerid, -1, "You must be at least admin level 5 to use this.");
The parameter 'varname' is important in both. You can't have SetPVarInt(playerid, "ADMIN"), and then GetPVarInt(playerid, "ADMINLEVEL"), because they are two different varnames. You must use the same, like in the example 'AdminLevel' and 'AdminLevel'. I believe these are case sensitive?

Also note:
Quote:
Originally Posted by SA-MP Wiki
Variables aren't reset until after OnPlayerDisconnect is called, so the values are still accessible in OnPlayerDisconnect.
Reply
#3

Well, I'll be a bit more clear. In the current gamemode i'm running, it retrieves the data from the MySQL database.
So, should I add SetPVarInt(playerid,"AdminLevel",PInfo[playerid][Level]); in LoadStats function?
Reply
#4

Pretty much, yeah. Then in your filterscript, you would use 'GetPVarInt(playerid, "AdminLevel")' to retrieve the admin level.
Reply
#5

You can use this:
pawn Код:
// In your gamemode
forward GetPlayerAdminLevel(playerid);
public GetPlayerAdminLevel(playerid)
{
    return PlayerInformation[playerid][admin];
}

// In your filterscript
#define GetPlayerAdminLevel(%0) CallRemoteFunction("GetPlayerAdminLevel", "i", %0)
Then you easily use GetPlayerAdminLevel(playerid) in your filterscript like PlayerInformation[playerid][admin] in your gamemode.

(Change them to whatever you want, just giving an example)
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)