SA-MP Forums Archive
Filterscript use gamemode's variables - 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: Filterscript use gamemode's variables (/showthread.php?tid=537046)



Filterscript use gamemode's variables - Jimmy0wns - 13.09.2014

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.


Re: Filterscript use gamemode's variables - Infinity - 13.09.2014

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


Re: Filterscript use gamemode's variables - Jimmy0wns - 13.09.2014

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?


Re: Filterscript use gamemode's variables - Stinged - 13.09.2014

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.


Re: Filterscript use gamemode's variables - Pottus - 13.09.2014

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.


Re: Filterscript use gamemode's variables - Jimmy0wns - 13.09.2014

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?


Re: Filterscript use gamemode's variables - Pottus - 13.09.2014

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.


Re: Filterscript use gamemode's variables - Lordzy - 13.09.2014

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


Re: Filterscript use gamemode's variables - Jimmy0wns - 13.09.2014

Thanks all! I managed to understand it and it works.


Re: Filterscript use gamemode's variables - PMH - 13.09.2014

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