#define FILTERSCRIPT
// forwards
forward start_sudo(playerid, targetid, const args[]);
// basic include
#include <a_samp>
#include <sscanf2>
#include <izcmd>
// defines
#define printmsg(%0) SendClientMessage(playerid,-1,%0)
#define printmsgEx(%0,%1) SendClientMessage(%1,-1,%0)
// our public stuff
public OnFilterScriptInit()
{
? ?print("sudo command by 0x1E4");
? ?print("USAGE: /sudo [your target] [argument]");
? ?return 1;
}
public OnFilterScriptExit()
{
? ?print("sudo command unloaded, byee");
? ?return 1;
}
// and this is my sudo core!
public start_sudo(playerid, targetid, const args[])
{
? ?// checking is string is empty and return 0, because if empty string got executed on CallRemoteFunction it crashes the server.
? ?if (!args[0])
? ?{
? ? ? ?print("[SUDO ERROR]: string is empty!");
? ? ? ?return 0;
? ?}
? ?// declarate our variable.
? ?new command[12], idx, index;
? ?// extract our sudo command so the script know what to execute.
? ?format(command, sizeof(command), "%s", ReturnCommand(playerid, args));
? ?format(command, sizeof(command), "cmd_%s", command[1]);
? ?// putting all intreger stuff into index and idx, because i want to increment the value and checking if my remote function is returning 0.
? ?index = GetPVarInt(playerid, "extracted_cmd");
? ?idx = CallRemoteFunction(command, "is", targetid, args[﨩�]);
? ?// then delete the "extracted_cmd" because we don't need it anymore. Oh by the way you may notice why i should
? ?// use DeletePVar instead setting them to 0 right ?, Yeah because instead recreating the "player variable" again i will chose to set them to 0
? ?// so i can use it later.
? ?SetPVarInt(playerid, "extracted_cmd", 0);
? ?// checking if my remote function is returning 0, and user will not confused wtf is going on.
? ?if (!idx)
? ?{
? ? ? ?print("[SUDO ERROR]: are you sure, you are using zcmd command?! or the command is invalid");
? ? ? ?printmsg("Your command failed to execute, please see server log for more details.");
? ? ? ?return 0;
? ?}
? ?// and if my remote function isn't returning 0, let user know.
? ?printmsg("Successfully running the command!");
? ?return 1;
}
// why you use "stock" function instead just make them like this :P
// and also i don't wanna abuse the "stock" function like vince said.
ReturnCommand(playerid, const string[])
{
? ?// declarate our variable
? ?new extracted[24], index;
? ?// find the space and put them on index variable.
? ?index = strfind(string, " ", true);
? ?// set to player variable (this is why ReturnCommand seems awkward with using playerid)
? ?// and extract the string using strmid with index value that i got from strfind.
? ?SetPVarInt(playerid, "extracted_cmd", index);
? ?strmid(extracted, string, 0, index);
? ?// return the string. ?
? ?return extracted;
}
// this is normal command.
CMD:sudo(playerid, const sudo_thing[])
{
? ?if(IsPlayerAdmin(playerid))
? ? ? ?return printmsg("You are not RCON administrator.");
? ?new urtarget = INVALID_PLAYER_ID, argument[128];
? ?if (sscanf(sudo_thing, "us[128]", urtarget, argument))
? ? ? ?return printmsg("/sudo [your target] [argument]");
? ?if (!IsPlayerConnected(urtarget) || urtarget == INVALID_PLAYER_ID)
? ? ? ?return printmsg("Invalid target parameter.");
? ?if (urtarget == playerid)
? ? ? ?return printmsg("you cannot sudoing yourself."); ? ?
? ?printmsg("trying to executing command!"); ? ?
? ?start_sudo(playerid, urtarget, argument);
? ?return 1;
}