How to write a command as someone else
#1

Hey guys, I am trying to make a troll command for admins, this is my code so far:
PHP код:
CMD:fakechat(playeridparams[])
{
    if(!
IsAllowed(playerid5)) return NoAuth(playerid);
    new 
playerbstring[128];
    if(
sscanf(params"us[128]"playerbstring)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /fakechat [playerid] [text]");
    if(!
IsPlayerConnected(playerb) || playerid == playerb) return SendClientMessage(playeridCOLOR_WHITE"Invalid ID.");
    if(
IsImmune(playeridplayerb)) return NotImmune(playerid);
    
SendPlayerMessageToAll(playerbstring);
    
format(stringsizeof(string), "%s sent a fake message from %s: %s"RPN(playerid), RPN(playerb), string);
    
Log("logs/fakechat.log"string);
    return 
1;

Chatting works fine, but I couldn't write commands, it simply writes down the command in the chat
I am using ZCMD
Maybe I should call the command with the callback OnPlayerCommandReceived if the first char is "/" ?
Reply
#2

PHP код:
CMD:fakecmd(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid))
        return 
SCM(...);
    new 
idcmd[18];
    if(
sscanf(params"us[18]"idcmd))
        return 
SCM(...);
    if(!
strcmp(cmd"/", .length 1))
    {
        
CallRemoteFunction("OnPlayerCommandText""is"idcmd); 
    }
    else 
        
SCM(...);
    return 
1;

Reply
#3

I tried this:
PHP код:
CMD:fakechat(playeridparams[])
{
    if(!
IsAllowed(playerid5)) return NoAuth(playerid);
    new 
playerbstring[128];
    if(
sscanf(params"us[128]"playerbstring)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /fakechat [playerid] [text]");
    if(!
IsPlayerConnected(playerb) || playerid == playerb) return SendClientMessage(playeridCOLOR_WHITE"Invalid ID.");
    if(
IsImmune(playeridplayerb)) return NotImmune(playerid);
    if(
strfind(string"/") == 0CallLocalFunction("OnPlayerCommandReceived""is"playerbstring);
    else 
SendPlayerMessageToAll(playerbstring);
    
format(stringsizeof(string), "%s sent a fake message from %s: %s"RPN(playerid), RPN(playerb), string);
    
Log("logs/fakechat.log"string);
    return 
1;

Focus:
PHP код:
if(strfind(string"/") == 0CallLocalFunction("OnPlayerCommandReceived""is"playerbstring);
    else 
SendPlayerMessageToAll(playerbstring); 
The command is simply not sent ...
Reply
#4

try this
Код:
CMD:fakechat(playerid, params[])
{
    if(!IsAllowed(playerid, 5)) return NoAuth(playerid);
    new playerb, string[128];
    if(sscanf(params, "us[128]", playerb, string)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /fakechat [playerid] [text]");
    if(!IsPlayerConnected(playerb) || playerid == playerb) return SendClientMessage(playerid, COLOR_WHITE, "Invalid ID.");
    if(IsImmune(playerid, playerb)) return NotImmune(playerid);
    OnPlayerCommandText(playerb, string);
    else SendPlayerMessageToAll(playerb, string);
    format(string, sizeof(string), "%s sent a fake message from %s: %s", RPN(playerid), RPN(playerb), string);
    Log("logs/fakechat.log", string);
    return 1;
}
Reply
#5

OnPlayerCommandText works even if you have/do not have ZCMD.
I tested my code, It works fine.
Reply
#6

Use CallLocalFunction with the specified player's ID.

CMDs are functions (in CallLocalFunction based command processors), most of them start the functions off with "cmd_".
Reply
#7

Anyways, I should have just checked ZCMD inc, solved.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)