1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Implemented global and local player messaging customization.

This commit is contained in:
Sandu Liviu Catalin 2015-11-09 05:54:03 +02:00
parent 3c3e67bdaa
commit bcf9d603e7
6 changed files with 478 additions and 112 deletions

View File

@ -370,6 +370,13 @@ class LocalEvent;
#define SQMOD_MSGLENGTH 512
#define SQMOD_CMDLENGTH 512
/* ------------------------------------------------------------------------------------------------
* GENERIC LIMITS
*/
#define MAX_PLAYER_MESSAGE_PREFIXES 64
#define MAX_PLAYER_TEMPORARY_BUFFER 128
/* ------------------------------------------------------------------------------------------------
* INITIAL ENTITY POOLS
*/

View File

@ -84,6 +84,11 @@ bool Core::Init()
return false;
}
// Initialize the player message prefixes
Ent< CPlayer >::Prefixes.fill(Ent< CPlayer >::MsgPrefix::value_type());
// Initialize the player message styles
Ent< CPlayer >::MessageColor = 0x6599FFFF;
Ent< CPlayer >::AnnounceStyle = 1;
LogMsg("%s", CenterStr("SUCCESS", '*'));
return true;

View File

@ -5,6 +5,13 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
Ent< CPlayer >::MsgPrefix Ent< CPlayer >::Prefixes;
// ------------------------------------------------------------------------------------------------
SQUint32 Ent< CPlayer >::MessageColor;
SQInt32 Ent< CPlayer >::AnnounceStyle;
// ------------------------------------------------------------------------------------------------
EBlipCreated & GBlipCreated()
{

View File

@ -178,7 +178,7 @@ private:
} Instance;
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst)
static void Init(Instance & inst)
{
inst.World = SQMOD_UNKNOWN;
inst.Scale = SQMOD_UNKNOWN;
@ -188,7 +188,7 @@ private:
}
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst, SQInt32 index, SQInt32 world, SQFloat x, SQFloat y, SQFloat z,
static void Init(Instance & inst, SQInt32 index, SQInt32 world, SQFloat x, SQFloat y, SQFloat z,
SQInt32 scale, SQUint32 color, SQInt32 sprid)
{
inst.World = world;
@ -202,7 +202,7 @@ private:
}
// --------------------------------------------------------------------------------------------
static void Clear(Instance & inst)
static void Deinit(Instance & inst)
{
inst.BlipCreated.Clear();
inst.BlipDestroyed.Clear();
@ -358,13 +358,13 @@ private:
} Instance;
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst)
static void Init(Instance & inst)
{
SQMOD_UNUSED_VAR(inst);
}
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst, SQInt32 player, SQInt32 world, SQFloat x, SQFloat y, SQFloat z,
static void Init(Instance & inst, SQInt32 player, SQInt32 world, SQFloat x, SQFloat y, SQFloat z,
SQUint32 r, SQUint32 g, SQUint32 b, SQUint32 a, SQFloat radius)
{
SQMOD_UNUSED_VAR(inst);
@ -381,7 +381,7 @@ private:
}
// --------------------------------------------------------------------------------------------
static void Clear(Instance & inst)
static void Deinit(Instance & inst)
{
inst.CheckpointCreated.Clear();
inst.CheckpointDestroyed.Clear();
@ -553,7 +553,7 @@ private:
} Instance;
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst)
static void Init(Instance & inst)
{
inst.Primary = SQMOD_UNKNOWN;
inst.Secondary = SQMOD_UNKNOWN;
@ -562,7 +562,7 @@ private:
}
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst, SQInt32 slot, bool release, SQInt32 primary, SQInt32 secondary,
static void Init(Instance & inst, SQInt32 slot, bool release, SQInt32 primary, SQInt32 secondary,
SQInt32 alternative)
{
inst.Primary = primary;
@ -573,7 +573,7 @@ private:
}
// --------------------------------------------------------------------------------------------
static void Clear(Instance & inst)
static void Deinit(Instance & inst)
{
inst.KeybindCreated.Clear();
inst.KeybindDestroyed.Clear();
@ -737,13 +737,13 @@ private:
} Instance;
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst)
static void Init(Instance & inst)
{
SQMOD_UNUSED_VAR(inst);
}
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst, SQInt32 model, SQInt32 world, SQFloat x, SQFloat y, SQFloat z,
static void Init(Instance & inst, SQInt32 model, SQInt32 world, SQFloat x, SQFloat y, SQFloat z,
SQInt32 alpha)
{
SQMOD_UNUSED_VAR(inst);
@ -756,7 +756,7 @@ private:
}
// --------------------------------------------------------------------------------------------
static void Clear(Instance & inst)
static void Deinit(Instance & inst)
{
inst.ObjectCreated.Clear();
inst.ObjectDestroyed.Clear();
@ -921,13 +921,13 @@ private:
} Instance;
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst)
static void Init(Instance & inst)
{
SQMOD_UNUSED_VAR(inst);
}
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst, SQInt32 model, SQInt32 world, SQInt32 quantity,
static void Init(Instance & inst, SQInt32 model, SQInt32 world, SQInt32 quantity,
SQFloat x, SQFloat y, SQFloat z, SQInt32 alpha, bool automatic)
{
SQMOD_UNUSED_VAR(inst);
@ -942,7 +942,7 @@ private:
}
// --------------------------------------------------------------------------------------------
static void Clear(Instance & inst)
static void Deinit(Instance & inst)
{
inst.PickupCreated.Clear();
inst.PickupDestroyed.Clear();
@ -1036,6 +1036,15 @@ private:
// --------------------------------------------------------------------------------------------
typedef Reference< CPlayer > RefType;
public:
/* --------------------------------------------------------------------------------------------
* The container used to declare custom prexises for player messages.
*/
typedef std::array< String, MAX_PLAYER_MESSAGE_PREFIXES > MsgPrefix;
private:
/* --------------------------------------------------------------------------------------------
* Default destructor (disabled)
*/
@ -1066,6 +1075,18 @@ private:
// ----------------------------------------------------------------------------------------
SQInt32 Level;
// ----------------------------------------------------------------------------------------
MsgPrefix Prefixes;
// ----------------------------------------------------------------------------------------
SQUint32 MessageColor;
SQInt32 AnnounceStyle;
// ----------------------------------------------------------------------------------------
bool LocalPrefixes;
bool LocalMessageColor;
bool LocalAnnounceStyle;
// ----------------------------------------------------------------------------------------
SqTag Tag;
SqObj Data;
@ -1169,13 +1190,23 @@ private:
} Instance;
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst)
static void Init(Instance & inst)
{
SQMOD_UNUSED_VAR(inst);
// Reset the level of the previous instance
inst.Level = SQMOD_UNKNOWN;
// Reset the prefixes of the previous instance
inst.Prefixes.fill(MsgPrefix::value_type());
// Reset the message styles to the global ones
inst.MessageColor = MessageColor;
inst.AnnounceStyle = AnnounceStyle;
// Reset the message style options
inst.LocalPrefixes = false;
inst.LocalMessageColor = false;
inst.LocalAnnounceStyle = false;
}
// --------------------------------------------------------------------------------------------
static void Clear(Instance & inst)
static void Deinit(Instance & inst)
{
inst.PlayerCreated.Clear();
inst.PlayerDestroyed.Clear();
@ -1269,6 +1300,13 @@ public:
static constexpr SQInt32 DestroyEvID = EVT_PLAYERDESTROYED;
static constexpr SQInt32 CustomEvID = EVT_PLAYERCUSTOM;
// --------------------------------------------------------------------------------------------
static MsgPrefix Prefixes;
// --------------------------------------------------------------------------------------------
static SQUint32 MessageColor;
static SQInt32 AnnounceStyle;
// --------------------------------------------------------------------------------------------
typedef std::array< Instance, Limit > Instances;
@ -1510,13 +1548,13 @@ private:
} Instance;
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst)
static void Init(Instance & inst)
{
SQMOD_UNUSED_VAR(inst);
}
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst, SQInt32 player, SQInt32 world, SQFloat x, SQFloat y, SQFloat z,
static void Init(Instance & inst, SQInt32 player, SQInt32 world, SQFloat x, SQFloat y, SQFloat z,
SQUint32 r, SQUint32 g, SQUint32 b, SQFloat radius)
{
SQMOD_UNUSED_VAR(inst);
@ -1532,7 +1570,7 @@ private:
}
// --------------------------------------------------------------------------------------------
static void Clear(Instance & inst)
static void Deinit(Instance & inst)
{
inst.SphereCreated.Clear();
inst.SphereDestroyed.Clear();
@ -1697,13 +1735,13 @@ private:
} Instance;
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst)
static void Init(Instance & inst)
{
inst.Path.clear();
}
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst, SQInt32 index, const SQChar * file, SQInt32 xp, SQInt32 yp,
static void Init(Instance & inst, SQInt32 index, const SQChar * file, SQInt32 xp, SQInt32 yp,
SQInt32 xr, SQInt32 yr, SQFloat angle, SQInt32 alpha, bool rel)
{
inst.Path.assign(file);
@ -1718,7 +1756,7 @@ private:
}
// --------------------------------------------------------------------------------------------
static void Clear(Instance & inst)
static void Deinit(Instance & inst)
{
inst.SpriteCreated.Clear();
inst.SpriteDestroyed.Clear();
@ -1876,13 +1914,13 @@ private:
} Instance;
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst)
static void Init(Instance & inst)
{
inst.Text.clear();
}
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst, SQInt32 index, const SQChar * text, SQInt32 xp, SQInt32 yp,
static void Init(Instance & inst, SQInt32 index, const SQChar * text, SQInt32 xp, SQInt32 yp,
SQUint32 color, bool rel)
{
inst.Text.assign(text);
@ -1894,7 +1932,7 @@ private:
}
// --------------------------------------------------------------------------------------------
static void Clear(Instance & inst)
static void Deinit(Instance & inst)
{
inst.TextdrawCreated.Clear();
inst.TextdrawDestroyed.Clear();
@ -2056,13 +2094,13 @@ private:
} Instance;
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst)
static void Init(Instance & inst)
{
SQMOD_UNUSED_VAR(inst);
}
// --------------------------------------------------------------------------------------------
static void Store(Instance & inst, SQInt32 model, SQInt32 world, SQFloat x, SQFloat y, SQFloat z,
static void Init(Instance & inst, SQInt32 model, SQInt32 world, SQFloat x, SQFloat y, SQFloat z,
SQFloat angle, SQInt32 primary, SQInt32 secondary)
{
SQMOD_UNUSED_VAR(inst);
@ -2077,7 +2115,7 @@ private:
}
// --------------------------------------------------------------------------------------------
static void Clear(Instance & inst)
static void Deinit(Instance & inst)
{
inst.VehicleCreated.Clear();
inst.VehicleDestroyed.Clear();
@ -2735,8 +2773,8 @@ private:
// Disable this entity instance
RefType::s_Instances[id].ID = SQMOD_UNKNOWN;
// Clear any events that are still listening
EntType::Clear(RefType::s_Instances[id]);
// Deinitialize the instance and clear any events that are still listening
EntType::Deinit(RefType::s_Instances[id]);
// Successfully deactivated the instance
return true;
@ -2799,8 +2837,8 @@ private:
RefType::s_Instances[id].Data.Release();
}
// Store any specified values on the instance
EntType::Store(RefType::s_Instances[id], std::forward< Args >(args)...);
// Initialize the instance and store any specified values/arguments
EntType::Init(RefType::s_Instances[id], std::forward< Args >(args)...);
// Initialization successful
return true;

View File

@ -21,13 +21,6 @@ Vector3 CPlayer::s_Vector3;
// ------------------------------------------------------------------------------------------------
SQChar CPlayer::s_Buffer[MAX_PLAYER_TEMPORARY_BUFFER];
// ------------------------------------------------------------------------------------------------
CPlayer::Prefixes CPlayer::s_MsgPrefixes{{_SC("")}};
// ------------------------------------------------------------------------------------------------
SQUint32 CPlayer::s_MessageColor = 0x6599FFFF;
SQInt32 CPlayer::s_AnnounceStyle = 1;
// ------------------------------------------------------------------------------------------------
CPlayer::CPlayer(const Reference< CPlayer > & o)
: Reference(o)
@ -63,6 +56,196 @@ void CPlayer::SetLevel(SQInt32 val) const
}
}
// ------------------------------------------------------------------------------------------------
bool CPlayer::GetLocalPrefixes() const
{
if (VALID_ENTITY(m_ID))
{
return Get(m_ID).LocalPrefixes;
}
else
{
LogWrn(_SC("Attempting to <see if player uses local message prefixes> using an invalid reference: %d"),
m_ID);
}
return false;
}
// ------------------------------------------------------------------------------------------------
void CPlayer::SetLocalPrefixes(bool toggle) const
{
if (VALID_ENTITY(m_ID))
{
Get(m_ID).LocalPrefixes = toggle;
}
else
{
LogWrn(_SC("Attempting to <set whether player uses local message prefixes> using an invalid reference: %d"),
m_ID);
}
}
// ------------------------------------------------------------------------------------------------
bool CPlayer::GetLocalMessageColor() const
{
if (VALID_ENTITY(m_ID))
{
return Get(m_ID).LocalMessageColor;
}
else
{
LogWrn(_SC("Attempting to <see if player uses local message color> using an invalid reference: %d"),
m_ID);
}
return false;
}
// ------------------------------------------------------------------------------------------------
void CPlayer::SetLocalMessageColor(bool toggle) const
{
if (VALID_ENTITY(m_ID))
{
Get(m_ID).LocalMessageColor = toggle;
}
else
{
LogWrn(_SC("Attempting to <set whether player uses local message color> using an invalid reference: %d"),
m_ID);
}
}
// ------------------------------------------------------------------------------------------------
bool CPlayer::GetLocalAnnounceStyle() const
{
if (VALID_ENTITY(m_ID))
{
return Get(m_ID).LocalAnnounceStyle;
}
else
{
LogWrn(_SC("Attempting to <see if player uses local announce style> using an invalid reference: %d"),
m_ID);
}
return false;
}
// ------------------------------------------------------------------------------------------------
void CPlayer::SetLocalAnnounceStyle(bool toggle) const
{
if (VALID_ENTITY(m_ID))
{
Get(m_ID).LocalAnnounceStyle = toggle;
}
else
{
LogWrn(_SC("Attempting to <set whether player uses local announce style> using an invalid reference: %d"),
m_ID);
}
}
// ------------------------------------------------------------------------------------------------
const SQChar * CPlayer::GetMessagePrefix(SQUint32 index) const
{
if (VALID_ENTITY(m_ID) && index < MAX_PLAYER_MESSAGE_PREFIXES)
{
return Get(m_ID).Prefixes[index].c_str();
}
else if (index >= MAX_PLAYER_MESSAGE_PREFIXES)
{
LogWrn(_SC("Attempting to <get player local message prefix> using an out of bounds index: %u"),
index);
}
else
{
LogWrn(_SC("Attempting to <get player local message prefix> using an invalid reference: %d"),
m_ID);
}
return _SC("");
}
// ------------------------------------------------------------------------------------------------
void CPlayer::SetMessagePrefix(SQUint32 index, const SQChar * prefix) const
{
if (VALID_ENTITY(m_ID) && index < MAX_PLAYER_MESSAGE_PREFIXES)
{
Get(m_ID).Prefixes[index].assign(prefix);
}
else if (index >= MAX_PLAYER_MESSAGE_PREFIXES)
{
LogWrn(_SC("Attempting to <set player local message prefix> using an out of bounds index: %u"),
index);
}
else
{
LogWrn(_SC("Attempting to <set player local message prefix> using an invalid reference: %d"),
m_ID);
}
}
// ------------------------------------------------------------------------------------------------
SQUint32 CPlayer::GetMessageColor() const
{
if (VALID_ENTITY(m_ID))
{
return Get(m_ID).MessageColor;
}
else
{
LogWrn(_SC("Attempting to <get player local message color> using an invalid reference: %d"),
m_ID);
}
return 0x0;
}
// ------------------------------------------------------------------------------------------------
void CPlayer::SetMessageColor(SQUint32 color) const
{
if (VALID_ENTITY(m_ID))
{
Get(m_ID).MessageColor = color;
}
else
{
LogWrn(_SC("Attempting to <set player local message color> using an invalid reference: %d"),
m_ID);
}
}
// ------------------------------------------------------------------------------------------------
SQInt32 CPlayer::GetAnnounceStyle() const
{
if (VALID_ENTITY(m_ID))
{
return Get(m_ID).AnnounceStyle;
}
else
{
LogWrn(_SC("Attempting to <get player local announce style> using an invalid reference: %d"),
m_ID);
}
return SQMOD_UNKNOWN;
}
// ------------------------------------------------------------------------------------------------
void CPlayer::SetAnnounceStyle(SQInt32 style) const
{
if (VALID_ENTITY(m_ID))
{
Get(m_ID).AnnounceStyle = style;
}
else
{
LogWrn(_SC("Attempting to <set player local announce style> using an invalid reference: %d"),
m_ID);
}
}
// ------------------------------------------------------------------------------------------------
bool CPlayer::IsStreamedFor(const Reference < CPlayer > & player) const
{
@ -1735,34 +1918,6 @@ bool CPlayer::Redirect(const SQChar * ip, SQUint32 port, const SQChar * nick, \
return false;
}
// ------------------------------------------------------------------------------------------------
const SQChar * CPlayer::GetMessagePrefix(SQUint32 index)
{
if (index < MAX_PLAYER_MESSAGE_PREFIXES)
{
return s_MsgPrefixes[index].c_str();
}
else
{
LogWrn(_SC("Attempting to <get player message prefix> using an out of bounds index: %u"), index);
}
return _SC("");
}
// ------------------------------------------------------------------------------------------------
void CPlayer::SetMessagePrefix(SQUint32 index, const SQChar * prefix)
{
if (index < MAX_PLAYER_MESSAGE_PREFIXES)
{
s_MsgPrefixes[index].assign(prefix);
}
else
{
LogWrn(_SC("Attempting to <set player message prefix> using an out of bounds index: %u"), index);
}
}
// ------------------------------------------------------------------------------------------------
SQInteger CPlayer::Msg(HSQUIRRELVM vm)
{
@ -1886,8 +2041,8 @@ SQInteger CPlayer::MsgP(HSQUIRRELVM vm)
// Pop any pushed values pushed to the stack
sq_settop(vm, top);
// Send the specified string
_Func->SendClientMessage(_SCI32(inst.value), s_MessageColor, "%s%s",
s_MsgPrefixes[index.value].c_str(), msg);
_Func->SendClientMessage(_SCI32(inst.value), FetchMessageColor(_SCI32(inst.value)), "%s%s",
FetchMessagePrefix(_SCI32(inst.value), index.value), msg);
}
else if (top > 3)
{
@ -1902,8 +2057,8 @@ SQInteger CPlayer::MsgP(HSQUIRRELVM vm)
return 0;
}
// Send the resulted string
_Func->SendClientMessage(_SCI32(inst.value), s_MessageColor, "%s%s",
s_MsgPrefixes[index.value].c_str(), msg);
_Func->SendClientMessage(_SCI32(inst.value), FetchMessageColor(_SCI32(inst.value)), "%s%s",
FetchMessagePrefix(_SCI32(inst.value), index.value), msg);
}
else
{
@ -2023,7 +2178,7 @@ SQInteger CPlayer::Message(HSQUIRRELVM vm)
// Pop any pushed values pushed to the stack
sq_settop(vm, top);
// Send the specified string
_Func->SendClientMessage(_SCI32(inst.value), s_MessageColor, "%s", msg);
_Func->SendClientMessage(_SCI32(inst.value), FetchMessageColor(_SCI32(inst.value)), "%s", msg);
}
else if (top > 2)
{
@ -2038,7 +2193,7 @@ SQInteger CPlayer::Message(HSQUIRRELVM vm)
return 0;
}
// Send the resulted string
_Func->SendClientMessage(_SCI32(inst.value), s_MessageColor, "%s", msg);
_Func->SendClientMessage(_SCI32(inst.value), FetchMessageColor(_SCI32(inst.value)), "%s", msg);
}
else
{
@ -2085,7 +2240,7 @@ SQInteger CPlayer::Announce(HSQUIRRELVM vm)
// Pop any pushed values pushed to the stack
sq_settop(vm, top);
// Send the specified string
_Func->SendGameMessage(_SCI32(inst.value), 1, "%s", msg);
_Func->SendGameMessage(_SCI32(inst.value), FetchAnnounceStyle(_SCI32(inst.value)), "%s", msg);
}
else if (top > 2)
{
@ -2100,7 +2255,7 @@ SQInteger CPlayer::Announce(HSQUIRRELVM vm)
return 0;
}
// Send the resulted string
_Func->SendGameMessage(_SCI32(inst.value), 1, "%s", msg);
_Func->SendGameMessage(_SCI32(inst.value), FetchAnnounceStyle(_SCI32(inst.value)), "%s", msg);
}
else
{
@ -2181,6 +2336,94 @@ SQInteger CPlayer::AnnounceEx(HSQUIRRELVM vm)
return 0;
}
// ------------------------------------------------------------------------------------------------
const SQChar * CPlayer::FetchMessagePrefix(SQInt32 player, SQUint32 index)
{
/* Assuming that the caller verified if the player identifier and prefix index is in range! */
if (Get(player).LocalPrefixes)
{
return Get(player).Prefixes[index].c_str();
}
// Fallback to the global value
return Ent< CPlayer >::Prefixes[index].c_str();
}
// ------------------------------------------------------------------------------------------------
SQUint32 CPlayer::FetchMessageColor(SQInt32 player)
{
/* Assuming that the caller verified if the player identifier is in range! */
if (Get(player).LocalMessageColor)
{
return Get(player).MessageColor;
}
// Fallback to the global value
return Ent< CPlayer >::MessageColor;
}
// ------------------------------------------------------------------------------------------------
SQInteger CPlayer::FetchAnnounceStyle(SQInt32 player)
{
/* Assuming that the caller verified if the player identifier is in range! */
if (Get(player).LocalAnnounceStyle)
{
return Get(player).AnnounceStyle;
}
// Fallback to the global value
return Ent< CPlayer >::AnnounceStyle;
}
// ------------------------------------------------------------------------------------------------
static const SQChar * GetPlayerMessagePrefix(SQUint32 index)
{
if (index < MAX_PLAYER_MESSAGE_PREFIXES)
{
return Ent< CPlayer >::Prefixes[index].c_str();
}
else
{
LogWrn(_SC("Attempting to <get player global message prefix> using an out of bounds index: %u"), index);
}
return _SC("");
}
// ------------------------------------------------------------------------------------------------
static void SetPlayerMessagePrefix(SQUint32 index, const SQChar * prefix)
{
if (index < MAX_PLAYER_MESSAGE_PREFIXES)
{
Ent< CPlayer >::Prefixes[index].assign(prefix);
}
else
{
LogWrn(_SC("Attempting to <set player global message prefix> using an out of bounds index: %u"), index);
}
}
// ------------------------------------------------------------------------------------------------
static SQUint32 GetPlayerMessageColor()
{
return Ent< CPlayer >::MessageColor;
}
// ------------------------------------------------------------------------------------------------
static void SetPlayerMessageColor(SQUint32 color)
{
Ent< CPlayer >::MessageColor = color;
}
// ------------------------------------------------------------------------------------------------
static SQUint32 GetPlayerAnnounceStyle()
{
return Ent< CPlayer >::AnnounceStyle;
}
// ------------------------------------------------------------------------------------------------
static void SetPlayerAnnounceStyle(SQInt32 style)
{
Ent< CPlayer >::AnnounceStyle = style;
}
// ================================================================================================
bool Register_CPlayer(HSQUIRRELVM vm)
{
@ -2201,6 +2444,15 @@ bool Register_CPlayer(HSQUIRRELVM vm)
.Ctor()
.Ctor< SQInt32 >()
/* Properties */
.Prop(_SC("level"), &CPlayer::GetLevel, &CPlayer::SetLevel)
.Prop(_SC("lprefix"), &CPlayer::GetLocalPrefixes, &CPlayer::SetLocalPrefixes)
.Prop(_SC("lmsg_color"), &CPlayer::GetLocalMessageColor, &CPlayer::SetLocalMessageColor)
.Prop(_SC("lmessage_color"), &CPlayer::GetLocalMessageColor, &CPlayer::SetLocalMessageColor)
.Prop(_SC("ltext_style"), &CPlayer::GetLocalAnnounceStyle, &CPlayer::SetLocalAnnounceStyle)
.Prop(_SC("lannounce_style"), &CPlayer::GetLocalAnnounceStyle, &CPlayer::SetLocalAnnounceStyle)
.Prop(_SC("message_color"), &CPlayer::GetMessageColor, &CPlayer::SetMessageColor)
.Prop(_SC("announce_style"), &CPlayer::GetAnnounceStyle, &CPlayer::SetAnnounceStyle)
.Prop(_SC("level"), &CPlayer::GetLevel, &CPlayer::SetLevel)
.Prop(_SC("cls"), &CPlayer::GetClass)
.Prop(_SC("admin"), &CPlayer::GetAdmin, &CPlayer::SetAdmin)
.Prop(_SC("ip"), &CPlayer::GetIP)
@ -2261,6 +2513,8 @@ bool Register_CPlayer(HSQUIRRELVM vm)
.Prop(_SC("aim_dir"), &CPlayer::GetAimDir)
.Prop(_SC("aim_direction"), &CPlayer::GetAimDir)
/* Functions */
.Func(_SC("get_msg_prefix"), &CPlayer::GetMessagePrefix)
.Func(_SC("set_msg_prefix"), &CPlayer::SetMessagePrefix)
.Func(_SC("streamed_for"), &CPlayer::IsStreamedFor)
.Func(_SC("kick"), &CPlayer::Kick)
.Func(_SC("ban"), &CPlayer::Ban)
@ -2311,8 +2565,13 @@ bool Register_CPlayer(HSQUIRRELVM vm)
// Output debugging information
LogDbg("Beginning registration of <Player functions> type");
// Several global functions
Sqrat::RootTable(vm).Func(_SC("GetPlayerMsgPrefix"), &CPlayer::GetMessagePrefix);
Sqrat::RootTable(vm).Func(_SC("SetPlayerMsgPrefix"), &CPlayer::SetMessagePrefix);
Sqrat::RootTable root(vm);
root.Func(_SC("GetPlayerMessagePrefix"), &GetPlayerMessagePrefix);
root.Func(_SC("SetPlayerMessagePrefix"), &SetPlayerMessagePrefix);
root.Func(_SC("GetPlayerMessageColor"), &GetPlayerMessageColor);
root.Func(_SC("SetPlayerMessageColor"), &SetPlayerMessageColor);
root.Func(_SC("GetPlayerAnnounceStyle"), &GetPlayerAnnounceStyle);
root.Func(_SC("SetPlayerAnnounceStyle"), &SetPlayerAnnounceStyle);
// Output debugging information
LogDbg("Registration of <Player functions> type was successful");
// Registration succeeded

View File

@ -4,24 +4,14 @@
// ------------------------------------------------------------------------------------------------
#include "Entity.hpp"
// ------------------------------------------------------------------------------------------------
#include <array>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
#define MAX_PLAYER_MESSAGE_PREFIXES 128
#define MAX_PLAYER_TEMPORARY_BUFFER 128
/* ------------------------------------------------------------------------------------------------
* Class responsible for managing the referenced player instance.
*/
class CPlayer : public Reference< CPlayer >
{
// --------------------------------------------------------------------------------------------
typedef std::array< String, MAX_PLAYER_MESSAGE_PREFIXES > Prefixes;
// --------------------------------------------------------------------------------------------
static CSkin s_Skin;
static CWeapon s_Weapon;
@ -33,13 +23,6 @@ class CPlayer : public Reference< CPlayer >
// --------------------------------------------------------------------------------------------
static SQChar s_Buffer[MAX_PLAYER_TEMPORARY_BUFFER];
// --------------------------------------------------------------------------------------------
static Prefixes s_MsgPrefixes;
// --------------------------------------------------------------------------------------------
static SQUint32 s_MessageColor;
static SQInt32 s_AnnounceStyle;
public:
/* --------------------------------------------------------------------------------------------
@ -60,7 +43,67 @@ public:
/* --------------------------------------------------------------------------------------------
* Set whether the referenced player instance has administrator privileges.
*/
void SetLevel(SQInt32 val) const;
void SetLevel(SQInt32 toggle) const;
/* --------------------------------------------------------------------------------------------
* Get whether referenced player instance uses the global or local message prefixes.
*/
bool GetLocalPrefixes() const;
/* --------------------------------------------------------------------------------------------
* Set whether referenced player instance uses the global or local message prefixes.
*/
void SetLocalPrefixes(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Get whether referenced player instance uses the global or local message color.
*/
bool GetLocalMessageColor() const;
/* --------------------------------------------------------------------------------------------
* Set whether referenced player instance uses the global or local message color.
*/
void SetLocalMessageColor(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Get whether referenced player instance uses the global or local announcement style.
*/
bool GetLocalAnnounceStyle() const;
/* --------------------------------------------------------------------------------------------
* Set whether referenced player instance uses the global or local announcement style.
*/
void SetLocalAnnounceStyle(bool toggle) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the local message prefix at the specified index for the referenced player instance.
*/
const SQChar * GetMessagePrefix(SQUint32 index) const;
/* --------------------------------------------------------------------------------------------
* Change the local message prefix at the specified index for the referenced player instance.
*/
void SetMessagePrefix(SQUint32 index, const SQChar * prefix) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the local message color for the referenced player instance.
*/
SQUint32 GetMessageColor() const;
/* --------------------------------------------------------------------------------------------
* Change the local message color for the referenced player instance.
*/
void SetMessageColor(SQUint32 color) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the local announcement style for the referenced player instance.
*/
SQInt32 GetAnnounceStyle() const;
/* --------------------------------------------------------------------------------------------
* Change the local announcement style for the referenced player instance.
*/
void SetAnnounceStyle(SQInt32 style) const;
/* --------------------------------------------------------------------------------------------
* See if the referenced player instance is streamed for the specified player.
@ -629,32 +672,22 @@ public:
const SQChar * pass, const SQChar * user);
/* --------------------------------------------------------------------------------------------
* Retrive the current value of a predefined message prefix.
*/
static const SQChar * GetMessagePrefix(SQUint32 index);
/* --------------------------------------------------------------------------------------------
* Change the current value of a predefined message prefix.
*/
static void SetMessagePrefix(SQUint32 index, const SQChar * prefix);
/* --------------------------------------------------------------------------------------------
* Send a chat message to the referenced player instance.
* Send a normal colored message to the referenced player instance.
*/
static SQInteger Msg(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a chat message to the referenced player instance.
* Send a normal prefixed message to the referenced player instance.
*/
static SQInteger MsgP(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a chat message to the referenced player instance.
* Send a normal colored message to the referenced player instance.
*/
static SQInteger MsgEx(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a chat message to the referenced player instance.
* Send a normal message to the referenced player instance.
*/
static SQInteger Message(HSQUIRRELVM vm);
@ -664,9 +697,26 @@ public:
static SQInteger Announce(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send an announcement message to the referenced player instance.
* Send a styled announcement message to the referenced player instance.
*/
static SQInteger AnnounceEx(HSQUIRRELVM vm);
protected:
/* --------------------------------------------------------------------------------------------
* Fetch the message prefix that a certain player instance must use.
*/
static const SQChar * FetchMessagePrefix(SQInt32 player, SQUint32 index);
/* --------------------------------------------------------------------------------------------
* Fetch the message color that a certain player instance must use.
*/
static SQUint32 FetchMessageColor(SQInt32 player);
/* --------------------------------------------------------------------------------------------
* Fetch the announce type that a certain player instance must use.
*/
static SQInteger FetchAnnounceStyle(SQInt32 player);
};
} // Namespace:: SqMod