From de588c77b9338c962a242dcf13a1a15cf9be1a6b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 2 Mar 2007 08:34:13 +0000 Subject: [PATCH] added state change function --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40564 --- core/smn_entities.cpp | 32 ++++++++++++++++++++++++++++++++ plugins/include/entity.inc | 13 +++++++++++++ 2 files changed, 45 insertions(+) diff --git a/core/smn_entities.cpp b/core/smn_entities.cpp index 77fa4d89..f39fd55f 100644 --- a/core/smn_entities.cpp +++ b/core/smn_entities.cpp @@ -437,8 +437,40 @@ static cell_t SetEntDataEnt(IPluginContext *pContext, const cell_t *params) return 1; } +IChangeInfoAccessor *CBaseEdict::GetChangeAccessor() +{ + return engine->GetChangeAccessor( (const edict_t *)this ); +} + +CSharedEdictChangeInfo *g_pSharedChangeInfo = NULL; + +static cell_t ChangeEdictState(IPluginContext *pContext, const cell_t *params) +{ + edict_t *pEdict = GetEdict(params[1]); + + if (!pEdict) + { + return pContext->ThrowNativeError("Edict %d is invalid", params[1]); + } + + if (!g_pSharedChangeInfo) + { + g_pSharedChangeInfo = engine->GetSharedEdictChangeInfo(); + } + + if (params[2]) + { + pEdict->StateChanged(params[2]); + } else { + pEdict->StateChanged(); + } + + return 1; +} + REGISTER_NATIVES(entityNatives) { + {"ChangeEdictState", ChangeEdictState}, {"CreateEdict", CreateEdict}, {"GetEdictClassname", GetEdictClassname}, {"GetEdictFlags", GetEdictFlags}, diff --git a/plugins/include/entity.inc b/plugins/include/entity.inc index 9277a6c9..6cb4f5e4 100644 --- a/plugins/include/entity.inc +++ b/plugins/include/entity.inc @@ -150,6 +150,19 @@ native bool:GetEntityNetClass(edict, String:clsname[], maxlength); * illegal values. Any range outside of the CBaseEntity structure's private * size will cause undefined behaviour or even crash. */ + +/** + * Marks an entity as state changed. This can be useful if you set an offset + * and wish for it to be immediately changed over the network. By default this + * is not done for offset setting functions. + * + * @param edict Index to the edict. + * @param offset Offset to mark as changed. If 0, + * the entire edict is marked as changed. + * @noreturn + * @error Invalid entity or offset out of bounds. + */ +native ChangeEdictState(edict, offset = 0); /** * Peeks into an entity's object data and retrieves the integer value at