11.03.2009, 01:21
Yay I finally have done it! Inspired by this, I made a *******-style PM system (but you can actually make a real SA:MP ******* with this
)
Syntax: "@name/id message" or "@ name/id message" - both work (I haven't tested it with names w/ spaces tho).
Ok I hope I don't miss a part of the code :P And pls don't dis this code because even I'm quite surprised it works, since it came to me while daydreaming :P
So here we go.
Above all:
in OnPlayerText:
out of callbacks:
Feel free to use it and add parameters and IsPlayerConnected's and whatever
)Syntax: "@name/id message" or "@ name/id message" - both work (I haven't tested it with names w/ spaces tho).
Ok I hope I don't miss a part of the code :P And pls don't dis this code because even I'm quite surprised it works, since it came to me while daydreaming :P
So here we go.
Above all:
pawn Code:
forward OnPlayerAtCmd(playerid, cmdtext[]);
pawn Code:
if(text[0] == '@') {OnPlayerAtCmd(playerid, text[1]); return 0;}
pawn Code:
public OnPlayerAtCmd(playerid, cmdtext[])
{
new idx;
new string[128];
new sendername[MAX_PLAYER_NAME];
new giveplayer[MAX_PLAYER_NAME];
new cmd[128];
new tmp[128];
new giveplayerid;
cmd[idx] = cmdtext[0]; // this is important - it's what lets you *not* have the whole command and enter the name right after '@'
//The rest except the one above line is pretty much usual PM stuff. This sample is from GodFather (sorry, haters :))
//Also, I'm not sure, but I think that [idx] and [0] can be different. I tried replacing [0] with [1] and [2], but no change whatsoever.
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COL_HELP, "USAGE: @[Player ID/Name] [Message]");
return 1;
}
giveplayerid = ReturnUser(tmp);
if (IsPlayerConnected(giveplayerid))
{
GetPlayerName(playerid, sendername, sizeof(sendername));
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[64];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COL_HELP, "USAGE: @[Player ID/Name] [Message]");
return 1;
}
format(string, sizeof(string), "New reply from %s (ID: %d): '%s'", sendername, playerid, (result));
SendClientMessage(giveplayerid, COL_REPLY, string);
return 1;
} else {
SendClientMessage(giveplayerid, COL_ERROR, "Recipient not online");
}
return 1;
}

