• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Filterscript] sudo command
#1
It just an simple filterscript that can execute any command to target and pretending that he use that command (like minecraft)

But you must careful about what are you want to execute the command or else you'll get caught XD



PHP Code:
#define FILTERSCRIPT



// forwards

forward start_sudo(playeridtargetid, 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(playeridtargetid, 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], idxindex;



? ?
// extract our sudo command so the script know what to execute.

? ?format(commandsizeof(command), "%s"ReturnCommand(playeridargs));

? ?
format(commandsizeof(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"targetidargs[﨩�]);



? ?
// 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(extractedstring0index); 



? ?
// 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_IDargument[128];

? ?if (
sscanf(sudo_thing"us[128]"urtargetargument))

? ? ? ?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(playeridurtargetargument);

? ?return 
1;


  Reply
#2
This solution seems so complex, here's what I use in my code:



PHP Code:
PlayerExecute(playeridtext[])

{

? ??if(
text[0] == '/'Command_ReProcessEx(playeridtext);

? ? else 
OnPlayerText(playeridtext);

? ? return 
1;





PHP Code:
stock Command_ReProcessEx(playeridcmdtext[])

{

? ??
#if defined PAWNCMD_INC_

? ? ? ? PC_EmulateCommand(playeridcmdtext);

? ? 
#else

? ? ? ? Command_ReProcess(playeridcmdtextfalse);

? ? 
#endif

? ? return 1;


[Image: c9CyzPf.png]
  Reply


Forum Jump: