#define MAX_CHAT_LENGTH 144
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_GREY 0x808080FF
enum E_PLAYER_DATA {
pID,
pName[MAX_PLAYER_NAME + 1],
pPass[33],
pEmail[47],
pReferal[MAX_PLAYER_NAME + 1],
pDateReg[11],
pNations,
pAge,
pSex,
pSkin,
pMoney,
pLevel
}
static stock pInfo[MAX_PLAYERS][E_PLAYER_DATA];
#pragma pack(1)
static stock chatData[MAX_PLAYERS][MAX_CHAT_LENGTH char];
#pragma pack()
forward OnPlayerCheck(playerid);
public OnPlayerConnect(playerid) {
GetPlayerName(playerid, pInfo[playerid][pName], sizeof(pInfo[][pName]));
static const query_fmt[] = "SELECT `ID` FROM `users` WHERE `Name` = '%e' LIMIT 1";
new query[sizeof(query_fmt) + MAX_PLAYER_NAME * 2 - 2];
mysql_format(dbHandle, query, sizeof(query), query_fmt, pInfo[playerid][pName]);
mysql_tquery(dbHandle, query, "OnPlayerCheck", "d", playerid);
Clear(playerid);
PlayerTextDraws(playerid);
return 1;
}
#define IS_IN_RANGE(%0,%1,%2) (((%0) - (%1)) < ((%2) - (%1)))
public OnPlayerText(playerid, text[]) {
if (!text[0]) return 0;
new len = strlen(text);
if (len > 128) len = 128;
static const fmt[] = "%s [%d]: %s";
new total_len = sizeof(fmt) + MAX_PLAYER_NAME + 3 + len - 6; // -6 for format specifiers
new Float:pos[3];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
if (GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) {
ApplyAnimation(playerid, "PED", "IDLE_chat", 4.1, 0, 1, 1, 0, 3000, 1);
}
format(chatData[playerid], total_len, fmt, pInfo[playerid][pName], playerid, text);
new Float:dist, color;
for (new i = 0, j = GetPlayerPoolSize(); i <= j; i++) {
if (!IsPlayerConnected(i)) continue;
dist = GetPlayerDistanceFromPoint(i, pos[0], pos[1], pos[2]);
if (dist > 25.0) continue;
color = IS_IN_RANGE(dist, 0.0, 5.0) ? COLOR_WHITE :
IS_IN_RANGE(dist, 5.0, 10.0) ? (COLOR_WHITE & 0xFFFFFF00 | 0xCC) :
IS_IN_RANGE(dist, 10.0, 15.0) ? (COLOR_WHITE & 0xFFFFFF00 | 0x99) :
IS_IN_RANGE(dist, 15.0, 20.0) ? (COLOR_WHITE & 0xFFFFFF00 | 0x66) :
(COLOR_WHITE & 0xFFFFFF00 | 0x33);
SendClientMessage(i, color, chatData[playerid]);
}
return 0;
}
enum player
{
pID,
pName[MAX_PLAYER_NAME+1],
pPass[32+1],
pEmail[46+1],
pReferal[MAX_PLAYER_NAME+1],
pDateReg[10+1],
pNations,
pAge,
pSex,
pSkin,
pMoney,
pLevel,
ppName[MAX_PLAYER_NAME]
}
new pInfo[MAX_PLAYERS][player];
GetPlayerName(playerid, pInfo[ppName],MAX_PLAYER_NAME);
GetPlayerName(playerid, pInfo[playerid][pName], MAX_PLAYER_NAME);
static fmt_str[] = "SELECT `ID` FROM `users` WHERE `Name` = '%s' LIMIT 1";
new string[sizeof(fmt_str)+(-2+MAX_PLAYER_NAME)];
mysql_format(dbHandle, string, sizeof(string), fmt_str, pInfo[playerid][pName]);
mysql_function_query(dbHandle, string, true, "PlayerCheck", "d", playerid);
Clear(playerid);
PlayerTextDraws(playerid);
return true;
}
public OnPlayerDisconnect(playerid, reason)
{
KillTimers(playerid);
return true;
}
public OnPlayerSpawn(playerid)
{
if(login_check{playerid} == true)
SetPlayerSpawn(playerid);
return true;
}
public OnPlayerDeath(playerid, killerid, reason)
{
return true;
}
public OnVehicleSpawn(vehicleid)
{
return true;
}
public OnVehicleDeath(vehicleid, killerid)
{
return true;
}
public OnPlayerText(playerid, text[])
{
new string[144];
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
{
ApplyAnimation(playerid, "PED", "IDLE_chat", 1.6, 0, 1, 1, 1, 1);
SetTimerEx("ChatAnim", 3000, 0, "i", playerid);
}
format(string, sizeof(string), "%s [%d]: %s", pInfo[ppName], playerid, text);
ProxDetector(25.0, playerid, string, Color_White, Color_White, Color_White , Color_Grey, Color_White);
return 0;
}