Skip to content

Instantly share code, notes, and snippets.

@ohmypxl
Created April 12, 2023 07:17
Show Gist options
  • Save ohmypxl/aad4203992656ab4a8e08015c1cf8aab to your computer and use it in GitHub Desktop.
Save ohmypxl/aad4203992656ab4a8e08015c1cf8aab to your computer and use it in GitHub Desktop.
Simple PM systema
#include <YSI_Coding\y_timers>
#include <YSI_Server\y_colours>
#include <YSI_Visual\y_commands>
// Gamemode Entry
main()
{
printf("Copyright (c) - 2023 Genesis Roleplay");
}
public OnScriptInit()
{
Command_SetDeniedReturn(true);
return 1;
}
static
g_sPlayerPmTarget[MAX_PLAYERS];
YCMD:pm(playerid, const string:text[], help)
{
if (help)
{
SendClientMessage(playerid, X11_GREY, "Help:{FFFFFF} This command for interacting with other player privately");
return 0;
}
new toplayerid, string:message[64];
if (sscanf(text, "rs[64]", toplayerid, message))
{
SendClientMessage(playerid, X11_GREY, "Syntax:{FFFFFF} /pm <playerid/name> <message>");
return 0;
}
if (toplayerid == playerid)
{
SendClientMessage(playerid, X11_RED, "Error:{FFFFFF} Cannot send pm to yourself!");
return 0;
}
SendPersonalMessage(playerid, toplayerid, text);
return 1;
}
YCMD:reply(playerid, const string:text[], help)
{
new toplayerid = g_sPlayerPmTarget[playerid];
if (!IsPlayerConnected(toplayerid))
{
return SendClientMessage(playerid, X11_RED, "ERROR: {FFFFFF}Invalid target id");
}
SendPersonalMessage(playerid, toplayerid, text);
return 1;
}
SendPersonalMessage(playerid, toplayerid, const string:message[])
{
if (!IsPlayerConnected(playerid) || !IsPlayerConnected(toplayerid))
{
return false;
}
g_sPlayerPmTarget[playerid] = toplayerid;
g_sPlayerPmTarget[toplayerid] = playerid;
SendClientMessage(playerid, X11_YELLOW, "(( Message to %s(%d): %s ))", ReturnPlayerRPName(toplayerid), toplayerid, message);
SendClientMessage(toplayerid, X11_YELLOW, "(( Message from %s(%d): %s ))", ReturnPlayerRPName(playerid), playerid, message);
return 1;
}
ResetPersonalMessage(playerid)
{
new targetid = g_sPlayerPmTarget[playerid];
// Sanity Check for targetid to avoid array out of bounds
if (targetid != INVALID_PLAYER_ID)
{
g_sPlayerPmTarget[targetid] = INVALID_PLAYER_ID;
}
g_sPlayerPmTarget[playerid] = INVALID_PLAYER_ID;
return 1;
}
// Reset on 5 minutes
ptask OnAutoResetPM[6000 * 5](playerid)
{
ResetPersonalMessage(playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
ResetPersonalMessage(playerid);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment