Forcing a command by a command.
#1

Hey there, first of all thank you for even reading this.

I've been trying to make a /forcecmd ( force-command ) which will basically force a player to perform the command a certain admin chose.

This is my code:
pawn Код:
CMD:forcecmd(playerid, params[])
{
    new cmdToForce[50];
    if(PlayerInfo[playerid][AdminLevel] < 5) return SendClientMessage(playerid, COLOR_ERROR, "ERROR: You are not authorized to perform this command.");
    if(sscanf(params, "rs[50]", Target, cmdToForce)) return SendClientMessage(playerid, COLOR_USAGE, "USAGE: /forcecmd [playerid/PartOfName] [command-to-force]");
    return cmd_cmdToForce(Target, params[]);
}
Doesn't matter how I do it, I keep getting the following error:
Код:
error 017: undefined symbol "cmd_cmdToForce"
The line is ofcourse the following:
pawn Код:
return cmd_cmdToForce(Target, params[]);
What may I do?

Thank you in advance.
Reply
#2

I never worked with ZCMD, but try this:
pawn Код:
return cmd_params[2](Targer, params[]);
Reply
#3

https://sampwiki.blast.hk/wiki/CallLocalFunction

pawn Код:
new cmdname[32] = "cmd_";
strcat(cmdname, cmdToForce);
CallLocalFunction(cmdname, "s", params);
Should work, but I don't remember if it will work with non-public functions. Also - make sure params is never empty

@up:

Could you explain to me how your code works? Even if there was a macro like that, params[2] would point to third character of params string
Reply
#4

Quote:
Originally Posted by Misiur
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/CallLocalFunction

pawn Код:
new cmdname[32] = "cmd_";
strcat(cmdname, cmdToForce);
CallLocalFunction(cmdname, "s", params);
Should work, but I don't remember if it will work with non-public functions. Also - make sure params is never empty

@up:

Could you explain to me how your code works? Even if there was a macro like that, params[2] would point to third character of params string
It is not working, it just does not do anything.
And I will be greatful if you could explain the CallLocalFunction.
Reply
#5

Here you go my man calibrated just for you
(Stealing this idea for myself too hehe)

Код:
CMD:forcecmd(playerid, params[])
{

// Set your command prefix here
#define     cmdprefix       "cmd"

#if !defined isnull
    #define isnull(%1) \
                ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif

	new Target;
	new cmdParams[50];
    new cmdToForce[50];

    if(PlayerInfo[playerid][AdminLevel] < 5) SendClientMessage(playerid, COLOR_ERROR, "ERROR: You are not authorized to perform this command.");
	else
 	{
	    sscanf(params, "us[50]s[50]", Target, cmdToForce, cmdParams);

		if(isnull(cmdToForce)) SendClientMessage(playerid, COLOR_USAGE, "USAGE: /forcecmd [playerid/PartOfName] [command-to-force] [command-parameters]");
		else
		{
			if(!IsPlayerConnected(Target)) SendClientMessage(playerid, COLOR_USAGE, "Player is not connected - USAGE: /forcecmd [playerid/PartOfName] [command-to-force] [command-parameters]");
			else
			{
				format(cmdToForce, sizeof(cmdToForce), "%s_%s", cmdprefix, cmdToForce);
				if(funcidx(cmdToForce) != -1)
				{
					if(isnull(cmdParams)) CallLocalFunction(cmdToForce, "i", Target);
					else CallLocalFunction(cmdToForce, "is", Target, cmdParams);
				}
				else SendClientMessage(playerid, COLOR_USAGE, "FUNCTION DOES NOT EXIST - USAGE: /forcecmd [playerid/PartOfName] [command-to-force] [command-parameters]");
			}
		}
	}
	return 1;
}
Reply
#6

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Here you go my man calibrated just for you
(Stealing this idea for myself too hehe)

Код:
CMD:forcecmd(playerid, params[])
{

// Set your command prefix here
#define     cmdprefix       "cmd"

#if !defined isnull
    #define isnull(%1) \
                ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif

	new Target;
	new cmdParams[50];
    new cmdToForce[50];

    if(PlayerInfo[playerid][AdminLevel] < 5) SendClientMessage(playerid, COLOR_ERROR, "ERROR: You are not authorized to perform this command.");
	else
 	{
	    sscanf(params, "us[50]s[50]", Target, cmdToForce, cmdParams);

		if(isnull(cmdToForce)) SendClientMessage(playerid, COLOR_USAGE, "USAGE: /forcecmd [playerid/PartOfName] [command-to-force] [command-parameters]");
		else
		{
			if(!IsPlayerConnected(Target)) SendClientMessage(playerid, COLOR_USAGE, "Player is not connected - USAGE: /forcecmd [playerid/PartOfName] [command-to-force] [command-parameters]");
			else
			{
				format(cmdToForce, sizeof(cmdToForce), "%s_%s", cmdprefix, cmdToForce);
				if(funcidx(cmdToForce) != -1)
				{
					if(isnull(cmdParams)) CallLocalFunction(cmdToForce, "i", Target);
					else CallLocalFunction(cmdToForce, "is", Target, cmdParams);
				}
				else SendClientMessage(playerid, COLOR_USAGE, "FUNCTION DOES NOT EXIST - USAGE: /forcecmd [playerid/PartOfName] [command-to-force] [command-parameters]");
			}
		}
	}
	return 1;
}
At the beginning it did not work properly, I fixed it though.

Thank you so much - I'll now sit down and understand what you've done here.
You deserve a reputation point for wasting your time and making this command.

Thank you once again.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)