Jump to content
  • 0

OnPlayerPrivmsg


Guest farse

Question

//Am rafacut functia OnPlayerPrivmsg  haha.gif


#include <a_samp>

#define COLOR_RED 0xE60000FF
#define COLOR_YELLOW 0xFFFF00FF
public OnFilterScriptInit()
{
print("\n-----OnPlayerPrivmsg-----");
return 1;
}

public OnFilterScriptExit()return 1;


public OnPlayerCommandText(playerid, cmdtext[])
{
   new cmd[128];
new tmp[128];
new idx;
cmd = strtok(cmdtext,idx);
if(strcmp(cmd, "/pm", true) == 0)
{
if (!strlen(tmp)) return SendClientMessage(playerid, COLOR_RED, "Use:/pm [id] [message]");
tmp = strtok(cmdtext, idx);
new giveplayerid = ReturnUser(tmp, playerid);
tmp = strtok(cmdtext, idx);
OnPlayerPrivmsg(playerid,giveplayerid,tmp);
return 1;
}
return 0;
}
forward OnPlayerPrivmsg(playerid,recieverid,text[]);
public OnPlayerPrivmsg(playerid,recieverid,text[])
{
new
PlayerName[MAX_PLAYER_NAME],
RecieverName[MAX_PLAYER_NAME],
string[256];
GetPlayerName(playerid,PlayerName,sizeof(PlayerName));
GetPlayerName(playerid,RecieverName,sizeof(RecieverName));
format(string,sizeof(string),"Pm from %s[ID:%d] :%s",PlayerName,playerid,text);
SendClientMessage(recieverid,COLOR_YELLOW,string);
format(string,sizeof(string),"Pm to %s[ID:%d] :%s",RecieverName,recieverid,text);
SendClientMessage(recieverid,COLOR_YELLOW,string);

return 1;
}
stock IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
if (string[i] > '9' || string[i] < '0')
   return 0;
return 1;
}

ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
new pos = 0;
while (text[pos] < 0x21)
{
if (text[pos] == 0) return INVALID_PLAYER_ID;
pos++;
}
new userid = INVALID_PLAYER_ID;
if (IsNumeric(text[pos]))
{
userid = strval(text[pos]);
if (userid >=0 && userid < MAX_PLAYERS)
{
if(!IsPlayerConnected(userid))
userid = INVALID_PLAYER_ID;
else return userid;
}
}
new len = strlen(text[pos]);
new count = 0;
new pname[MAX_PLAYER_NAME];
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i, pname, sizeof (pname));
if (strcmp(pname, text[pos], true, len) == 0)
{
if (len == strlen(pname)) return i;
else
{
count++;
userid = i;
}
}
}
}
if (count != 1)
{
if (playerid != INVALID_PLAYER_ID)
{
if (count) SendClientMessage(playerid, COLOR_RED, "There are multiple users, enter full playername.");
else SendClientMessage(playerid, COLOR_RED, "Playername not found.");
}
userid = INVALID_PLAYER_ID;
}
return userid;
}
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}

new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Este pusa pe wiki, prin FSurile din server 0.3 default. Deci n-ai facut mare branza si daca tineti neaparat OnPlayerPrivmsg e doar o comanda /pm [id] [text] si in ea inainte de SendClientMessageu ala cu PMu pui OnPlayerPrivmsg si o iei ca pe orice callback... mare inginerie

-Toate tutorialele postate intra aici sau puneti-le direct [url=http://www.sa-mp.ro/forum/index

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.