CMD:sendcmd(playerid, params[])
{
new npcid, cmd[128], msg[128];
if(sscanf(params, "us[128]", npcid, cmd)) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /sendcmd [npc] [cmd]");
if(!IsPlayerConnected(npcid)) return SendClientMessage(playerid, 0xEE0000FF, "Invalid player!");
if(!IsPlayerNPC(npcid)) return SendClientMessage(playerid, 0xEE0000FF, "Player is not NPC!");
format(msg, sizeof(msg), "/sendcmd %s", cmd);
SendClientMessage(npcid, 123456, msg);
return 1;
}
CMD:playback(playerid, params[])
{
new npcid, playbacktype, recordname[64], msg[128];
if(sscanf(params, "uds[64]", npcid, playbacktype, recordname))
return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /playback [npc] [type] [name]");
if(!IsPlayerConnected(npcid)) return SendClientMessage(playerid, 0xEE0000FF, "Invalid player!");
if(!IsPlayerNPC(npcid)) return SendClientMessage(playerid, 0xEE0000FF, "Player is not NPC!");
format(msg, sizeof(msg), "/playback %d %s", playbacktype, recordname);
SendClientMessage(npcid, 123456, msg);
return 1;
}
public OnClientMessage(color, text[])
{
if(text[0] != '/' || color != 123456) return; // ignore all other client messages that NPC receives
new cmd[64], params[128];
sscanf(text, "s[64]s[128]", cmd, params);
if(strcmp(cmd, "/sendcmd", true) == 0)
{
SendCommand(params);
return;
}
if(strcmp(cmd, "/playback", true) == 0)
{
new playbacktype, recordname[64], msg[128];
sscanf(params, "ds[64]", playbacktype, recordname);
format(msg, sizeof(msg), "Starting playback (type: %d name: %s)", playbacktype, recordname);
SendChat(msg);
StartRecordingPlayback(playbacktype, recordname);
return;
}
}
/sendcmd 0 /me is a bot
/playback 0 2 animtest1
CMD:sendcmd(playerid, params[])
{
new npcid, cmd[128], msg[128], str[150];
if(sscanf(params, "us[128]s[150]", npcid, cmd, str)) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /sendcmd [npc] [cmd] [params]");
if(!IsPlayerConnected(npcid)) return SendClientMessage(playerid, 0xEE0000FF, "Invalid player!");
if(!IsPlayerNPC(npcid)) return SendClientMessage(playerid, 0xEE0000FF, "Player is not NPC!");
format(msg, sizeof(msg), "cmd_%s", cmd);
CallRemoteFunction(msg, "is", npcid, str);
return 1;
}
.
|
I don't really understand why you are sending a message to the NPC. Why don't you just call the ZCMD function or even the strcmp function directly from the command.
pawn Code:
. |
|
To send a command from gamemode/filterscript to NPC, you need to call a function in the npcmode. Normally you would use CallRemoteFunction. But CallRemoteFunction doesn't work for npcmodes, so you have to use something else, for example sending client messages.
|
|
Normally you would use CallRemoteFunction. But CallRemoteFunction doesn't work for npcmodes, so you have to use something else, for example sending client messages.
|
all who say bump f*ck you! i just wanted to thank the author and help others maybe
dcmd_sendcmd(playerid,params[])
{
#pragma unused params
new npcid, cmd[128], msg[128];
if(!IsPlayerConnected(npcid)) return SendClientMessage(playerid, 0xEE0000FF, "Invalid player!");
format(msg, sizeof(msg), "/sendcmd %s", cmd);
SendClientMessage(npcid, 123456, msg);
return 1;
}
public OnClientMessage(color, text[])
{
if(text[0] != '/' || color != 123456) return; // ignore all other client messages that NPC receives
new cmd[64], params[128];
sscanf(text, "s[64]s[128]", cmd, params);
if(strcmp(cmd, "/sendcmd", true) == 0)
{
SendCommand(params);
return;
}
return 1;
}