Enabling/Disabling Commands
#1

Hello SA-MP !

I made a Enable/Disable commands system, but the problem is, when i close samp-server.exe and start it again, then all commands are disabled. I want to stay as it was. Example: I have enabled /kick command and then i close samp-server.exe and open it again, then it's disabled, i want to stay enabled.

Thanks !
Reply
#2

I didn't get you well but did you try saving in a file? and when the server runs again it reads from the file and generates.
Reply
#3

Quote:
Originally Posted by RowdyrideR
Посмотреть сообщение
I didn't get you well but did you try saving in a file? and when the server runs again it reads from the file and generates.
As he said use a file to save it and when server reopens read the value from it and set it to a variable... then check the variable in /kick cmd and you are done
Reply
#4

Okay, let me know if i am doing right.

Top:
pawn Код:
#define CmdsPath "TDM/Commands/%s.ini"

enum CommandInfo
{
    MakeadminCmd,
    KickCmd,
    BanCmd,
}
new cInfo[CommandInfo];
Stock:
pawn Код:
stock CmdPath()
{
    new str[150];
    format(str, sizeof(str), CmdsPath, "Commands");
    return str;
}
pawn Код:
public OnGameModeExit()
{
    new INI:file = INI_Open(CmdPath());
    INI_SetTag(file, "Enable/Disable Command:");
    INI_WriteInt(file, "Makeadmin", cInfo[MakeadminCmd]);
    INI_WriteInt(file, "Ban", cInfo[BanCmd]);
    INI_WriteInt(file, "Kick", cInfo[KickCmd]);
    INI_Close(file);
    return 1;
}
Is that okay ?
Reply
#5

Quote:
Originally Posted by Areax
Посмотреть сообщение
Okay, let me know if i am doing right.

Top:
pawn Код:
#define CmdsPath "TDM/Commands/%s.ini"

enum CommandInfo
{
    MakeadminCmd,
    KickCmd,
    BanCmd,
}
new cInfo[CommandInfo];
Stock:
pawn Код:
stock CmdPath()
{
    new str[150];
    format(str, sizeof(str), CmdsPath, "Commands");
    return str;
}
pawn Код:
public OnGameModeExit()
{
    new INI:file = INI_Open(CmdPath());
    INI_SetTag(file, "Enable/Disable Command:");
    INI_WriteInt(file, "Makeadmin", cInfo[MakeadminCmd]);
    INI_WriteInt(file, "Ban", cInfo[BanCmd]);
    INI_WriteInt(file, "Kick", cInfo[KickCmd]);
    INI_Close(file);
    return 1;
}
Is that okay ?
Hmm, Do you mean like disabling command with saving? why? that's just dumb to be honest, you could set a level where an admin can you the certain command for his level, I suggest you need to create a variable at every command and load it(If you're saving them)
Reply
#6

I mean to disable it if it get's bugged or something, just to disable it so it can't be used by anyone.
Reply
#7

Save it to files.


Example:
Код:
	new File:ffile;
	new filepath[128];
	new string[128];

	format(filepath,sizeof(filepath),"%s.txt",filename);
	ffile = fopen(filepath,io_append);
	format(string,sizeof(string)," %s\r\n",text);
	fwrite(ffile,string);
	fclose(ffile);
	return 1;
Reply
#8

I don't get it :/

Well this is long code, but please help.

Top defines:
pawn Код:
#define CmdsPath "TDM/Commands/%s.ini"
#define DIALOG_SETCMD        2
Top enum:
pawn Код:
enum CommandInfo
{
    MakeadminCmd,
    KickCmd,
    BanCmd,
}
new cInfo[CommandInfo];
Also top: (This are dialogs)
pawn Код:
new CmdMakeadmin = 3;
new CmdKick = 4;
new CmdBan = 5;
Stock:
pawn Код:
stock CmdPath()
{
    new str[150];
    format(str, sizeof(str), CmdsPath, "Commands");
    return str;
}
forward:
pawn Код:
forward loadcommands(name[], value[]);

public loadcommands(name[], value[])
{
    INI_Int("Makeadmin", cInfo[MakeadminCmd]);
    INI_Int("Ban", cInfo[BanCmd]);
    INI_Int("Kick", cInfo[KickCmd]);
    return 1;
}
OnGameModeInit:
pawn Код:
if(fexist(CmdsPath))
    {
    INI_ParseFile(CmdsPath, "loadcommands", .bExtra = true);
    }
    else
    new INI:file = INI_Open(CmdPath());
    INI_SetTag(file, "Enable/Disable Command:");
    INI_WriteInt(file, "Makeadmin", cInfo[MakeadminCmd], 0);
    INI_WriteInt(file, "Ban", cInfo[BanCmd], 0);
    INI_WriteInt(file, "Kick", cInfo[KickCmd], 0);
    INI_Close(file);
OnGameModeExit:
pawn Код:
new INI:file = INI_Open(CmdPath());
    INI_SetTag(file, "Enable/Disable Command:");
    INI_WriteInt(file, "Makeadmin", cInfo[MakeadminCmd]);
    INI_WriteInt(file, "Ban", cInfo[BanCmd]);
    INI_WriteInt(file, "Kick", cInfo[KickCmd]);
    INI_Close(file);
OnDialogResponse:
pawn Код:
if(dialogid == DIALOG_SETCMD)
    {
    if(!response)return 0;
    if(response)
    {
    if(listitem == 0)return ShowPlayerDialog(playerid, CmdMakeadmin, DIALOG_STYLE_MSGBOX, "Command: /Makeadmin", "To enable this command, click 'Enable'\nTo disable it, click 'Disable'", "Enable", "Disable");
    if(listitem == 1)return ShowPlayerDialog(playerid, CmdKick, DIALOG_STYLE_MSGBOX, "Command: /Kick", "To enable this command, click 'Enable'\nTo disable it, click 'Disable'", "Enable", "Disable");
    if(listitem == 2)return ShowPlayerDialog(playerid, CmdBan, DIALOG_STYLE_MSGBOX, "Command: /Ban", "To enable this command, click 'Enable'\nTo disable it, click 'Disable'", "Enable", "Disable");
    }
    }
pawn Код:
if(dialogid == CmdMakeadmin)
    {
    if(!response)
    {
    cInfo[MakeadminCmd] = 0;
    GameTextForPlayer(playerid, "~y~/Makeadmin ~w~command has been ~r~disabled", 3000, 5);
    }
    if(response)
    {
    cInfo[MakeadminCmd] = 1;
    GameTextForPlayer(playerid, "~y~/Makeadmin ~w~command has been ~g~enabled", 3000, 5);
    }
    }
    if(dialogid == CmdKick)
    {
    if(!response)
    {
    cInfo[KickCmd] = 0;
    GameTextForPlayer(playerid, "~y~/Kick ~w~command has been ~r~disabled", 3000, 5);
    }
    if(response)
    {
    cInfo[KickCmd] = 1;
    GameTextForPlayer(playerid, "~y~/Kick ~w~command has been ~g~enabled", 3000, 5);
    }
    }
    if(dialogid == CmdBan)
    {
    if(!response)
    {
    cInfo[BanCmd] = 0;
    GameTextForPlayer(playerid, "~y~/Ban ~w~command has been ~r~disabled", 3000, 5);
    }
    if(response)
    {
    cInfo[BanCmd] = 1;
    GameTextForPlayer(playerid, "~y~/Ban ~w~command has been ~g~enabled", 3000, 5);
    }
    }
Then at the command /Makeadmin:
pawn Код:
if(cInfo[MakeadminCmd] == 0)return SendClientMessage(playerid, RED, "[SERVER]: This command is disabled !");
Then at the command /Kick:
pawn Код:
if(cInfo[KickCmd] == 0)return SendClientMessage(playerid, RED, "[SERVER]: This command is disabled !");
Then at the command /Ban:
pawn Код:
if(cInfo[BanCmd] == 0)return SendClientMessage(playerid, RED, "[SERVER]: This command is disabled !");
But still when I restart samp-server.exe are still all commands disabled :/
Reply
#9

Bump..
Reply
#10

Once the variable is changed, write your INI file to the New variable. Lets say like,

pawn Код:
/disablekickcommand
{
    Commandkick = 0; //You sir, this is what you call a variable.
     //Now add your INI_Write function here with the current variable.
      return 1;
}
Hopefully you get it.

Once you load the server, add a function to read from the INI file and place that function at OnGamemodeInit or FilterscriptInit
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)