Script name into a string?
#1

Is there any way to get the name of the compiled script into a string?

If my script was named "derby.amx", could I get the word "derby" into a string via a function that detected the file name?

Hope I make sense :P
Reply
#2

As far as I know, there's no way of checking the file name in the file.

However, you could check the server.cfg for the AMX currently running in server.cfg, providing that you only have one, then you could extract the name from the gamemode string in server.cfg (using GetServerVarAsString).

pawn Код:
new gmName[20];
GetServerVarAsString("gamemode", gmName, sizeof(gmName));
You'd have to remove the "gamemode" part (as I think the line includes that), and any numbers included afterwards (like the ordering numbers, "gamemodes pseudogame 1").
Reply
#3

Looking to get the filterscript's name mainly, not worried about the gamemode.
Reply
#4

Quote:
Originally Posted by Austin
Посмотреть сообщение
Looking to get the filterscript's name mainly, not worried about the gamemode.
Replace "gamemode" with "filterscripts" then, although that wouldn't work if you had more than 1 filterscript running. Could you not internally store the file name?
Reply
#5

I could, I'm basically looking to track all of my loaded filterscripts into an array in the gamemode so that if I GMX, it will unload them all, not just the ones associated with the gamemode.
pawn Код:
CallRemoteFunction("TrackFS", "s", "derby");
Reply
#6

Quote:
Originally Posted by Austin
Посмотреть сообщение
I could, I'm basically looking to track all of my loaded filterscripts into an array in the gamemode so that if I GMX, it will unload them all, not just the ones associated with the gamemode.
pawn Код:
CallRemoteFunction("TrackFS", "s", "derby");
Oh I see, so if you need them all, just keep up with the server.cfg's stored lines and try to explode by spaces (or enter name of more efficient function to split with here) and load them in to an array, then run an RCON command to (re)load them?
Reply
#7

Rcon only returns filterscripts as the ones in the server.cfg, not the active ones.

*runs to check*

Yep. So anything I load outside of that scope doesn't get recorded anywhere unless I do it.
Reply
#8

Quote:
Originally Posted by Austin
Посмотреть сообщение
Rcon only returns filterscripts as the ones in the server.cfg, not the active ones.

*runs to check*

Yep. So anything I load outside of that scope doesn't get recorded anywhere unless I do it.
How do you load your filterscripts if you don't load them in server.cfg? If it's in your GM, then you could easily record which filterscripts you're loading in a file/array?
Reply
#9

But if you load another one that isn't something you'd usually be in your gamemode, then you'd be fucked.
Reply
#10

Quote:
Originally Posted by Austin
Посмотреть сообщение
But if you load another one that isn't something you'd usually be in your gamemode, then you'd be fucked.
Depends. I really stay away from filterscripts and implement everything I need in my gamemode script, but then again I stick particularly to scripting roleplaying servers/scripts.

Couldn't you create a function which stores the names of the files in Get/Set property (or GVars) so it can communicate cross-script and then just (un)load/(re)load when you need to then, but when you load a new filterscript? Seeing as you can't directly get a running AMX file name (again, afaik).
Reply
#11

Yes, but that would involve TYPING THE NAMES. Which if we go back to post 1, is the whole point of this post .
Reply
#12

Quote:
Originally Posted by Austin
Посмотреть сообщение
Yes, but that would involve TYPING THE NAMES. Which if we go back to post 1, is the whole point of this post .
Paste some code on how you exactly load the filterscripts, please? As that's what I'm trying to help you out with. I assume you load them during game run time seeing as you just said you don't use server.cfg. And unless I'm lost, you've already had them running before you try to GMX and you want them to reload? Or am I lost?
Reply
#13

Well sure, I load about 8 filterscripts within my gamemode, and yes, OnGameModeExit I unload them.

But let's not worry about that because I am trying to GET THE NAME OF THE COMPILED SCRIPT INTO A STRING, because I sometimes loadfs some other scripts that I am working on, and if I GMX, there will still be filterscripts hanging around that I don't want loaded.

Let's stick with the bold text there, and not lose focus.
Reply
#14

Код:
12:33	Calgon	You're Austin on the forums I assume?
12:33	Calgon	Easier to PM you here so we avoid any more confusion, as your most recent post was just as confusing as the others.
12:47	[NoV]Austin	yeah
12:47	[NoV]Austin	how is it confusing?
12:47	Calgon	Right; as I understand you want to get the FS name from a GM, correct?
12:47	[NoV]Austin	no
12:47	[NoV]Austin	I want a function
12:48	[NoV]Austin	that when executed within any script
12:48	[NoV]Austin	returns the name of the script it has been performed within
12:48	Calgon	Oh....
Reply
#15

Not possible then I guess .
Reply
#16

pawn Код:
#define MAX_FILTERSCRIPTS 16
#define MAX_FILTERSCRIPT_NAME 30

new gFilterscripts[MAX_FILTERSCRIPTS][MAX_FILTERSCRIPT_NAME];

public OnGameModeInit()
{
    dcmd_loadfs(INVALID_PLAYER_ID, "derby");
    dcmd_loadfs(INVALID_PLAYER_ID, "racing");
}

public OnGameModeExit()
{
    new rcon[50];
    for(new x=0; x < MAX_FILTERSCRIPTS; x++)
    {
        if(!strlen(gFilterscripts[x])) continue;
        format(rcon, sizeof(rcon), "unloadfs %s", gFilterscripts[x]);
        SendRconCommand(rcon);
    }
}

public OnRconCommand(cmd[])
{
    new playerid = INVALID_PLAYER_ID;
   
    dcmd(reloadfs, 8, cmd);
    dcmd(loadfs, 6, cmd);
    dcmd(unloadfs, 8, cmd);
   
    return 0;
}

dcmd_loadfs(playerid, params[])
{
    if(playerid != INVALID_PLAYER_ID) return 0;
   
    new x = ExistingFS(params);
    if(x != -1)
    {
        dcmd_reloadfs(playerid, params);
        return 1;
    }
    // Check if we haven't loaded the maximum already
    for(x=0; x <= MAX_FILTERSCRIPTS; x++)
    {
        if(x == MAX_FILTERSCRIPTS) break;
        if(!strlen(gFilterscripts[x])) break;
    }
    // Too many loaded!!
    if(x == MAX_FILTERSCRIPTS)
    {
        print("Loaded too many filterscripts!!");
        return 1;
    }

    // Load the script and put it into the array
    new rcon[50];
    format(rcon, sizeof(rcon), "loadfs %s", params);
    format(gFilterscripts[x], MAX_FILTERSCRIPT_NAME, "%s", params);
    SendRconCommand(rcon);
   
    printf("/loadfs %s", params);
   
    return 1;
}

dcmd_unloadfs(playerid, params[])
{
    if(playerid != INVALID_PLAYER_ID) return 0;

    new x = ExistingFS(params);
    if(x == -1)
    {
        printf("Cannot unloadfs %s, it doesn't exist!", params);
        return 1;
    }
   
    // Unload the script and empty the array
    new rcon[50];
    format(rcon, sizeof(rcon), "unloadfs %s", params);
    gFilterscripts[x] = "";
    SendRconCommand(rcon);
   
    printf("/unloadfs %s", params);
   
    return 1;
}

dcmd_reloadfs(playerid, params[])
{
    if(playerid != INVALID_PLAYER_ID) return 0;

    if(ExistingFS(params) == -1)
    {
        dcmd_loadfs(playerid, params);
        return 1;
    }

    // Reload the script
    new rcon[50];
    format(rcon, sizeof(rcon), "reloadfs %s", params);
    SendRconCommand(rcon);
   
    printf("/reloadfs %s", params);
   
    return 1;
}

stock ExistingFS(params[])
{
    new x=0;
    // Check if it already exists and reload it if so
    for(x=0; x <= MAX_FILTERSCRIPTS; x++)
    {
        if(x == MAX_FILTERSCRIPTS) break;
        if(!strlen(gFilterscripts[x])) continue;
        if(!strcmp(params, gFilterscripts[x])) break;
    }
    // return x if it exists, return 0 if it does not
    if(x == MAX_FILTERSCRIPTS) return -1;
    else return x;
}
Seems to work just fine. Thanks for the idea Y_Less.

/rcon /loadfs derby
/rcon /reloadfs derby
/rcon /unloadfs derby

The loadfs command will kick you to reloadfs if the same name exists in the array, and the reloadfs command will kick you to loadfs if it doesn't exist already.

Can't load your filterscripts in the server.cfg file though if you do it this way.
Reply
#17

Oh, very true Y_Less!! Silly me!

I like to load mine through the gamemode, but you could get the server variable as a string and explode it.
Reply
#18

OH MY GOD
That's what I was trying to suggest....
Reply
#19

Quote:
Originally Posted by Y_Less
Посмотреть сообщение
I know, I was just clarifying it a bit.
I know, but I don't think the OP understood what I was trying to say. Nice to see at last he understands now though... (or I hope, at least)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)