new pLastMsg[100][MAX_PLAYERS];
public OnPlayerText(playerid, text[])
{
format(pLastMsg[playerid], 100, text);
if(!strcmp(text, pLastMsg[playerid], true))
{
//Have wrote the same message
//Do something
//return 0; to prevent sending the message
}
}
PHP код:
|
public OnPlayerText(playerid, text[])
{
if(!strcmp(text, pLastMsg[playerid], true))
{
//Have wrote the same message
//Do something
//return 0; to prevent sending the message
}
format(pLastMsg[playerid], 100, text);
}
new ChatTime[MAX_PLAYERS],
ChatText[MAX_PLAYERS][144];
public OnPlayerDisconnect(playerid, reason)
{
ChatTime[playerid] = 0;
format(ChatText[playerid], 144, "");
return 1;
}
public OnPlayerText(playerid, text[])
{
if((GetTickCount() - ChatTime[playerid]) < 1000)
{
SendClientMessage(playerid, 0xFF0000FF, "Message has been blocked");
return 0;
}
if(strlen(text) == strlen(ChatText[playerid]) && !strcmp(ChatText[playerid], text, false))
{
SendClientMessage(playerid, 0xFF0000FF, "Your message has been blocked as spam");
format(ChatText[playerid], 144, "%s", text);
return 0;
}
ChatTime[playerid] = GetTickCount();
format(ChatText[playerid], 144, "%s", text);
return 1;
}
new LastMsg[MAX_PLAYERS]; public OnPlayerConnect(playerid) { LastMsg[playerid] = 0; } public OnPlayerText(playerid, text[]) { if(strfind(LastText[playerid], text, false) != -1) { LastMsg[playerid]++; if(LastMsg[playerid] >= 2) // If he repeats it twice { SendClientMessage(playerid, COLOR_RED, "Don't repeat your message."); return false; } else LastMsg[playerid] = 0; strmid(LastText[playerid], text, 0, strlen(text), sizeof(LastText[])); } }
it wont work because you store the text to a var and then check both the vars are same or not (that logic make no sense man) it will not allow him to type anything.
you can do the intialising after checking PHP код:
|
new pLastMsg[MAX_PLAYERS][129 char];
public OnPlayerConnect(playerid)
{
pLastMsg[playerid] = !"fghsfhdf";
return 1;
}
public OnPlayerText(playerid, text[])
{
if(!strcmp(text, pLastMsg[playerid], true))
{
//Have wrote the same message
//Do something
//return 0; to prevent sending the message
}
strpack(pLastMsg[playerid], text, sizeof(pLastMsg[]));
return 1;
}
Код:
new LastMsg[MAX_PLAYERS]; public OnPlayerConnect(playerid) { LastMsg[playerid] = 0; } public OnPlayerText(playerid, text[]) { if(strfind(LastText[playerid], text, false) != -1) { LastMsg[playerid]++; if(LastMsg[playerid] >= 2) // If he repeats it twice { SendClientMessage(playerid, COLOR_RED, "Don't repeat your message."); return false; } else LastMsg[playerid] = 0; strmid(LastText[playerid], text, 0, strlen(text), sizeof(LastText[])); } } |
new pLastMsg[100][MAX_PLAYERS];
public OnGameModeInit()
{
for(new i, j=MAX_PLAYERS; i<j; i++) { format(pLastMsg[i], 100, "!9sd4f"); }
return 1;
}
public OnPlayerText(playerid, text[])
{
if(!strcmp(text, pLastMsg[playerid], true))
{
//Have wrote the same message
//Do something
//return 0; to prevent sending the message
}
format(pLastMsg[playerid], 100, text);
return 1;
}