/pm help! REP+ - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: /pm help! REP+ (
/showthread.php?tid=331501)
/pm help! REP+ -
TheMightyEddy - 05.04.2012
So for example I have 2 people in game:
John (ID 0)
Kyle (ID 1)
And I'm John. I want to /pm Kyle so I have to type this in: /pm 1 my message to kyle
how can I make it so when I type it in, I can just type in /pm kyle instead of /pm 1 ? Because when I type in /pm kyle my message , in game, it automatically sends a pm to ID 0 because I didn't put the ID in. I want it to be both ways so I can /pm kyle and /pm 1
Here is my code:
Код:
#include <a_samp>
#include "../include/gl_common.inc"
#define COLOR_YELLOW 0xFFFF00AA
//------------------------------------------------
public OnFilterScriptInit()
{
print("Private Message Script Loaded");
return 1;
}
//------------------------------------------------
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[256];
new tmp[256];
new Message[256];
new gMessage[256];
new pName[MAX_PLAYER_NAME+1];
new iName[MAX_PLAYER_NAME+1];
new idx;
cmd = strtok(cmdtext, idx);
// PM Command
if(strcmp("/pm", cmd, true) == 0)
{
tmp = strtok(cmdtext,idx);
if(!strlen(tmp) || strlen(tmp) > 5) {
SendClientMessage(playerid,COLOR_YELLOW,"Usage: /pm (ID) (message)");
return 1;
}
new id = strval(tmp);
gMessage = strrest(cmdtext,idx);
if(!strlen(gMessage)) {
SendClientMessage(playerid,COLOR_YELLOW,"Usage: /pm (ID) (message)");
return 1;
}
if(!IsPlayerConnected(id)) {
SendClientMessage(playerid,COLOR_YELLOW,"/pm : You Entered a Wrong ID!");
return 1;
}
if(playerid != id) {
GetPlayerName(id,iName,sizeof(iName));
GetPlayerName(playerid,pName,sizeof(pName));
format(Message,sizeof(Message),"PM Sent to %s(%d): %s",iName,id,gMessage);
SendClientMessage(playerid,COLOR_YELLOW,Message);
format(Message,sizeof(Message),"PM From %s(%d): %s",pName,playerid,gMessage);
SendClientMessage(id,COLOR_YELLOW,Message);
PlayerPlaySound(id,1085,0.0,0.0,0.0);
printf("PM: %s",Message);
}
else {
SendClientMessage(playerid,COLOR_YELLOW,"You Cannot Private Message Yourself.");
}
return 1;
}
return 0;
}
Re: /pm help! REP+ -
Catalyst- - 05.04.2012
Replace
With this...
pawn Код:
new id;
if(IsNumeric(tmp))
id = strval(tmp);
else
id = GetPlayerID(tmp);
And add this anywhere outside of any public functions...
pawn Код:
stock GetPlayerID(name[])
{
new pname[MAX_PLAYER_NAME];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
GetPlayerName(i, pname, MAX_PLAYER_NAME);
if(strfind(pname, name, true) != -1)
return i;
}
}
return INVALID_PLAYER_ID;
}
Re: /pm help! REP+ -
$$inSane - 05.04.2012
You can do that.. i can give you the code..
do u want??