SA-MP Forums Archive
How to delete a gamemode.amx file? - 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: How to delete a gamemode.amx file? (/showthread.php?tid=408920)



How to delete a gamemode.amx file? - Tamer - 19.01.2013

I am using this to prevent someone to use the script on another IP that is not specified.

pawn Код:
public OnGameModeInit()
{
    new
        ip[16];
    GetServerVarAsString("bind", ip, sizeof (ip));
    if (!ip[0] || strcmp(ip, "192.168.0.127"))
    {
        for (;;)
        {
            printf("Failed to  load the script!");
        }
    }
}
Now,what I want it to do is,when it is printing it failed to load the script,it will also delete the GameMode.amx file on /gamemodes folder in server directory,I have no idea how to do this. I think it is possible for it to be done as a .dll (writing del root function) but that is for windows servers and I don't know how can I start a plugin via the script.

I want this because it will prevent anyone to use the script if it is in the wrong IP and it will also make the script unusable again.


Re: How to delete a gamemode.amx file? - Calgon - 19.01.2013

The only way is to use a plugin, because you can't access any items outside of the scriptfiles folder in Pawn.

I used to use some similar code in one of my scripts and I used this plugin, but obviously the plugin can be deleted.

I would possibly do more in the script to ensure that it can't be loaded, you could delete all of the scriptfiles and create a bunch of random text files in the scriptfiles folder instead or something.


Re: How to delete a gamemode.amx file? - mineralo - 19.01.2013

pawn Код:
public OnGameModeInit()
{
    new
        ip[16];
    GetServerVarAsString("bind", ip, sizeof (ip));
    if (!ip[0] || strcmp(ip, "192.168.0.127"))
    {
        print("you failed, gm was removed !");
        fremove("../gamemodes/name.amx");
    }
}
untested


Re: How to delete a gamemode.amx file? - DeathOnaStick - 19.01.2013

Quote:
Originally Posted by Tamer T
Посмотреть сообщение
I think it is possible for it to be done as a .dll (writing del root function)
At first, this is probably correct, although I'm not sure how far your R/W permissions go. If outside the scriptfiles folder or not. Still this is the only thing that might work, due to the fact that your scripts can only access the scriptfiles.

Quote:
Originally Posted by Tamer T
Посмотреть сообщение
but that is for windows servers and I don't know how can I start a plugin via the script.
You don't need to start it, you just need to trigger the method that deletes the file. Still it's questionable if it's possible to delete a running gamemode. You should try that out manually first. Just backup your gamemode, run your server and try to delete the gamemode while the server is running.
Back to how you call the method: It's just like a normal function that you implemented into the library, you can just call it with e.g. DeleteGM();, or however you called the method.


Re: How to delete a gamemode.amx file? - Vince - 19.01.2013

Nothing else can be done as long as that loop is spamming. Remember, single threaded.


Re: How to delete a gamemode.amx file? - gnoomen2 - 19.01.2013

This might be what you need:

https://sampforum.blast.hk/showthread.php?tid=92246

A filemanager, it says it dosent limit you to the scriptfiles folder and i saw a delete file function there.


Re: How to delete a gamemode.amx file? - Calgon - 20.01.2013

Quote:
Originally Posted by gnoomen2
Посмотреть сообщение
This might be what you need:

https://sampforum.blast.hk/showthread.php?tid=92246

A filemanager, it says it dosent limit you to the scriptfiles folder and i saw a delete file function there.
Quote:
Originally Posted by mineralo
Посмотреть сообщение
pawn Код:
public OnGameModeInit()
{
    new
        ip[16];
    GetServerVarAsString("bind", ip, sizeof (ip));
    if (!ip[0] || strcmp(ip, "192.168.0.127"))
    {
        print("you failed, gm was removed !");
        fremove("../gamemodes/name.amx");
    }
}
untested
Great job reading the other posts.


Re: How to delete a gamemode.amx file? - Tamer - 20.01.2013

I have tried it out,it doesn't delete it. What is wrong?
pawn Код:
{
    new
        ip[16];
    GetServerVarAsString("bind", ip, sizeof (ip));
    if (!ip[0] || strcmp(ip, "111.168.0.127"))
    {
        for (;;)
        {
            printf("Failed to  load the script!");
            file_delete("../gamemodes/gamemode.amx[]");
            dir_delete("../gamemodes[]");  // this doesn't work aswell (tried using them both but not at the same time)          

        }
    }
}



Re: How to delete a gamemode.amx file? - mineralo - 20.01.2013

pawn Код:
{
    new
        ip[16];
    GetServerVarAsString("bind", ip, sizeof (ip));
    if (!ip[0] || strcmp(ip, "111.168.0.127"))
    {
        for (;;)
        {
            printf("Failed to  load the script!");
            file_delete("../gamemodes/gamemode.amx");//without []      

        }
    }
}
if same problem then try to stop server and after remove it, I think the problem that you can't delete it that while server running gm you can't delete/move etc
btw, its good idea to delete gm if its other ip well, I know one method to avoid this problem
pawn Код:
public OnGameModeInit()
{
new
        ip[16];
    GetServerVarAsString("bind", ip, sizeof (ip));
    if (!ip[0] || strcmp(ip, "111.168.0.127"))
    {
          SendRconCommand("exit");
     }
return 1;
}
this should work, this function will stop server


Re: How to delete a gamemode.amx file? - Tamer - 20.01.2013

I know the exit cmd,but that will just stop it,I want it to make the game mode unuseable