send command help
#1

Ok i have a command to send commands to my NPC so that they can "act" as real players... as of now it just shows the name of the person typing the command and not the NPC's name. :/

Will +rep for whoever helps me.
My code is going to be below

- I've tried adding playerb, and then it does not work at all...

pawn Code:
CMD:sendcmd(playerid, params[])
{
    new npcid, cmd[128], msg[128], sendedcmd[128];
    if(sscanf(params, "us[128]s[128]", npcid, cmd, sendedcmd))
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /sendcmd [playerid] [cmd] [cmdparams]");
        return 1;
    }
    if(!IsPlayerConnected(npcid))
    {
        SendClientMessage(playerid, COLOR_WHITE, "Invalid player!");
        return 1;
    }
    if(!IsPlayerNPC(npcid))
    {
        SendClientMessage(playerid, COLOR_GREY, "You can only use this command on NPC.");
        return 1;
    }
    if(!strcmp(cmd, "/ban")) return cmd_ban(playerid, sendedcmd);
    if(!strcmp(cmd, "/kick")) return cmd_kick(playerid, sendedcmd);
    if(!strcmp(cmd, "/slap")) return cmd_slap(playerid, sendedcmd);
    if(!strcmp(cmd, "/pm")) return cmd_pm(playerid, sendedcmd);
    if(!strcmp(cmd, "/o")) return cmd_o(playerid, sendedcmd);
    if(!strcmp(cmd, "/w")) return cmd_w(playerid, sendedcmd);
    format(msg, sizeof(msg), "/sendcmd %s.", cmd, sendedcmd);
    SendClientMessage(playerid, COLOR_WHITE, msg);
    return 1;
}
Reply
#2

Hmmmm... would this work?

pawn Code:
CMD:sendcmd(playerid, params[])
{
    new npcid, sendedcmd[150];
    if(sscanf(params, "us[150]", npcid, sendedcmd)) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /sendcmd [playerid] [cmd] [cmdparams]");
    if(!IsPlayerConnected(npcid)) return SendClientMessage(playerid, COLOR_WHITE, "Invalid player!");
    if(!IsPlayerNPC(npcid)) return SendClientMessage(playerid, COLOR_GREY, "You can only use this command on NPC.");
    if(OnPlayerCommandText(npcid, sendedcmd) == 0) return SendClientMessage(playerid, COLOR_GREY, "This is not a valid command!");
    format(sendedcmd, sizeof(sendedcmd), "/sendcmd %s.", sendedcmd);
    SendClientMessage(playerid, COLOR_WHITE, sendedcmd);
    return 1;
}
Reply
#3

I got this error... :/
pawn Code:
004 A-RP    5206    "function "zcmd_OnPlayerCommandText" is not implemented"
EDIT: Fixed let me test it IG quick

EDIT2: it's saying Tcmd Tslap %s %s.. and not acting as a real command. :/
Reply
#4

You are calling the commands for the playerid, shouldn't that be npcid? I don't know how npc commands work :P

example:

Code:
cmd_ban(playerid, sendedcmd);
Should be
Code:
cmd_ban(npcid, sendedcmd);
Reply
#5

That's what I had thought but it did not work, i typed the command and nothing ever happened
Reply
#6

https://sampforum.blast.hk/showthread.php?tid=276088


Try using SendCommand
Reply
#7

That is what I'm using for what I'm doing... I just edited it so it works for my server.... the only prob i have is it shows my name and not the NPC name. :/ can i define it or something so that playerid = GOD or something?
Reply
#8

Now that I think about it, this might make more sense:

pawn Code:
CMD:sendcmd(playerid, params[])
{
    new npcid, actualcmd[30], cmdparams[150];
    if(sscanf(params, "us[30]S[150]", npcid, actualcmd, cmdparams)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sendcmd [playerid] [cmd] [cmdparams]");
    if(cmdparams[0] != '/') return SendClientMessage(playerid, COLOR_WHITE, "Invalid command entered.");
    if(!IsPlayerConnected(npcid)) return SendClientMessage(playerid, COLOR_WHITE, "Invalid player!");
    if(!IsPlayerNPC(npcid)) return SendClientMessage(playerid, COLOR_GREY, "You can only use this command on an NPC.");
    format(actualcmd, sizeof(actualcmd), "cmd_%s", actualcmd);
    CallRemoteFunction(actualcmd, "is", npcid, cmdparams);
    return 1;
}
Reply
#9

no matter what command i type it says Invalid command entered.
Reply
#10

pawn Code:
CMD:sendcmd(playerid, params[])
{
    new npcid, cmd[128], msg[128], sendedcmd[128];
    if(!sscanf(params, "us[128]s[128]", npcid, cmd, sendedcmd))
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /sendcmd [playerid] [cmd] [cmdparams]");
        SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: ban - kick - slap - pm - o - w");
        return 1;
    }
    if(!IsPlayerConnected(npcid))
    {
        SendClientMessage(playerid, COLOR_WHITE, "Invalid player!");
        return 1;
    }
    if(!IsPlayerNPC(npcid))
    {
        SendClientMessage(playerid, COLOR_GREY, "You can only use this command on NPC.");
        return 1;
    }
   
    format(msg, sizeof(msg), "/%s", cmd);
    CallLocalFunction("OnPlayerCommandText", "is", npcid, msg);
   
    format(msg, sizeof(msg), "/sendcmd %s.", cmd, sendedcmd);
    SendClientMessage(playerid, COLOR_WHITE, msg);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)