Filterscript use gamemode's variables
#1

Hi! I was wondering if there's any way to let a loaded filterscript use the variables that are in your gamemode itself, I've looked on ****** as well but couldn't find anything helpful.
Reply
#2

You have to pass them to the functions that need them as parameters.
Reply
#3

Quote:
Originally Posted by Infinity
Посмотреть сообщение
You have to pass them to the functions that need them as parameters.
I don't really get what you mean, could you explain it a bit more?
Reply
#4

I'll be giving an example as GetAdminLevel, you can change that of course.
In your gamemode:
pawn Код:
forward GetAdminLevel(playerid);
public GetPlayerAdmin(playerid)
{
    return YourAdminVariable[playerid];
}
In your filterscript:
pawn Код:
#define GetAdminLevel(%0) CallRemoteFunction("GetAdminLevel", "i", %0)
Or
pawn Код:
GetAdminLevel(playerid)
{
    return CallRemoteFunction("GetAdminLevel", "i", playerid);
}
I think the #define one is quicker as it's just CallRemoteFunction but with a different name and parameters.
Reply
#5

Here is what I usually.

1.) Create public functions that can access the data I want.
2.) Create an include to access those functions.

Example.

In gamemode.

pawn Код:
new SomeVariable;

forward GetSomeVariable();
public GetSomeVariable() { return SomeVariable; }

forward SetSomeVariable(value);
public SetSomeVariable(value) { SomeVariable = value; }
Your include.

pawn Код:
#define GetSomeVariable() CallRemoteFunction("GetSomeVariable","")
#define SetSomeVariable(%0) CallRemoteFunction("SetSomeVariable","i",%0)
Some people might recommend using PVars I am going to say that is a very lousy method and I will explain why. Any time that variable changes you need to set the PVar as well which is inefficient or replace all instances of that variable with Set/Get PVar functions which is again inefficient and you would also lose the benefit of error checking incorrect variable names.

@Stinged You will always want to use #define rather than a function.
Reply
#6

Both of your replies help me a bit more out, am I right that there's a way using includes too? So if I'd put all my enums and variable in a include I could set and retrieve them in both my gamemode and filterscript?
Reply
#7

Quote:
Originally Posted by Jimmy0wns
Посмотреть сообщение
Both of your replies help me a bit more out, am I right that there's a way using includes too? So if I'd put all my enums and variable in a include I could set and retrieve them in both my gamemode and filterscript?
That is not really how it works, the include is meant so that you can use it with multiple filterscripts all that happens when you use an include is that code is inserted into your gamemode/filterscript. The idea is you won't have to copy/paste your #define's into each and every filterscript rather just update the include and the changes are then accessible to all filterscripts.
Reply
#8

If you're looking for a tutorial in regarding this, I did write one - https://sampforum.blast.hk/showthread.php?tid=516617
Reply
#9

Thanks all! I managed to understand it and it works.
Reply
#10

Use PVars instead? I know they're slow but still way too simple for newbies..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)