(Filter)Script reinitialization
#1

Hi!

I had a problem with some of my filterscripts. That was problem with textdraws in one filterscript and vehicles in another.
It is as follows:
I have SA-MP server launched and a gamemode on it. Then i am loading a filterscript (there's the same, if it's launched with server). The filterscript creates a textdraw at startup. Gamemode too. After gmx or changemode the game behaves not, like it was supposed to. Instead of filterscript text, there is gamemode text showing up. The same with vehicles. It causes crashes in certain cases.

The problem is that, when the gamemode is reloaded, the filterscript isn't. All the cars, textdraws, objects, etc. ... gets deleted, and all reference are still in FS.
I have never seen people putting OnGameModeInit function in filterscript sources, but it seems to be good tend to put this on some filterscripts.

Now, the solution.

The aim is to do all the reinitialization code (e.g. recreate vehicles) at the same time, when gamemode is reloading, so we could just do:

pawn Код:
public OnFilterScriptInit()
{
    gVehicles = CreateVehicle(...);
    ...
    /* Your Code here */
}

public OnFilterScriptExit()
{
    DestroyVehicle(gVehicless);
    gVehicles = 0;

    /* Just an example */
}

/*  Then ...        */

public OnGameModeInit()
{
    OnFilterScriptInit();
}

public OnGameModeExit()
{
    OnFilterScriptExit();
}
Note that it's still a filterscript, not gamemode.

When you gmx, OnFilterScriptExit() executes, then OnFilterScriptInit(), and that's it.
Next time, you run serwer with your filterscript in cfg, you can see your OnFilterScriptInit() running going twice. That's very bad! (This is because gamemode starts after all filterscripts are initialized.)
You could do a variable then, to prevent that and let it know, when the gamemode exits. So finally it is:

pawn Код:
new ReloadFS = 0;

public OnFilterScriptInit()
{
    gVehicles = CreateVehicle(...);
    ...
    /* Your Code here */
}

public OnFilterScriptExit()
{
    DestroyVehicle(gVehicless);
    gVehicles = 0;

    /* Just an example */
}

/*  Then ...        */

public OnGameModeInit()
{
    if( ReloadFS )
        OnFilterScriptInit();
}

public OnGameModeExit()
{
    OnFilterScriptExit();
    ReloadFS = 1;
}
I hope, you have found it helpful.

Cheers!
Reply
#2

this is a tut. wrong section.
but still usefull
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)