From 6e98ba7080cb88dfe1695bc1c2bad7f017599090 Mon Sep 17 00:00:00 2001 From: Borja Ferrer Date: Thu, 5 Jul 2007 00:21:59 +0000 Subject: [PATCH] finalized TE setup stocks added TE_SetEntDataFloatArray native to sdktools --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401045 --- extensions/sdktools/tempents.cpp | 21 +- extensions/sdktools/tempents.h | 1 + extensions/sdktools/tenatives.cpp | 26 ++ plugins/include/sdktools.inc | 1 + plugins/include/sdktools_tempents.inc | 15 +- plugins/include/sdktools_tempents_stocks.inc | 402 +++++++++++++++++++ 6 files changed, 463 insertions(+), 3 deletions(-) create mode 100644 plugins/include/sdktools_tempents_stocks.inc diff --git a/extensions/sdktools/tempents.cpp b/extensions/sdktools/tempents.cpp index b8acfcca..4d7f6c12 100644 --- a/extensions/sdktools/tempents.cpp +++ b/extensions/sdktools/tempents.cpp @@ -126,9 +126,28 @@ bool TempEntityInfo::TE_SetEntDataVector(const char *name, float vector[3]) return true; } +bool TempEntityInfo::TE_SetEntDataFloatArray(const char *name, cell_t *array, int size) +{ + /* Search for our offset */ + int offset = _FindOffset(name); + + if (offset < 0) + { + return false; + } + + float *base = (float *)((uint8_t *)m_Me + offset); + for (int i=0; iPlaybackTempEntity(filter, delay, (void *)m_Me, m_Sc->m_pTable, m_Sc->m_ClassID); + engine->PlaybackTempEntity(filter, delay, m_Me, m_Sc->m_pTable, m_Sc->m_ClassID); } /********************** diff --git a/extensions/sdktools/tempents.h b/extensions/sdktools/tempents.h index 52b14600..f294be4f 100644 --- a/extensions/sdktools/tempents.h +++ b/extensions/sdktools/tempents.h @@ -41,6 +41,7 @@ public: bool TE_SetEntData(const char *name, int value); bool TE_SetEntDataFloat(const char *name, float value); bool TE_SetEntDataVector(const char *name, float vector[3]); + bool TE_SetEntDataFloatArray(const char *name, cell_t *array, int size); void Send(IRecipientFilter &filter, float delay); private: int _FindOffset(const char *name, int *size=NULL); diff --git a/extensions/sdktools/tenatives.cpp b/extensions/sdktools/tenatives.cpp index db682763..a1a90a9f 100644 --- a/extensions/sdktools/tenatives.cpp +++ b/extensions/sdktools/tenatives.cpp @@ -116,6 +116,31 @@ static cell_t smn_TEWriteVector(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t smn_TEWriteFloatArray(IPluginContext *pContext, const cell_t *params) +{ + if (!g_TEManager.IsAvailable()) + { + return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report"); + } + if (!g_CurrentTE) + { + return pContext->ThrowNativeError("No TempEntity call is in progress"); + } + + char *prop; + pContext->LocalToString(params[1], &prop); + + cell_t *addr; + pContext->LocalToPhysAddr(params[2], &addr); + + if (!g_CurrentTE->TE_SetEntDataFloatArray(prop, addr, params[3])) + { + return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop); + } + + return 1; +} + static cell_t smn_TESend(IPluginContext *pContext, const cell_t *params) { if (!g_TEManager.IsAvailable()) @@ -165,5 +190,6 @@ sp_nativeinfo_t g_TENatives[] = {"TE_WriteAngles", smn_TEWriteVector}, {"TE_Send", smn_TESend}, {"TE_IsValidProp", smn_TEIsValidProp}, + {"TE_WriteFloatArray", smn_TEWriteFloatArray}, {NULL, NULL} }; diff --git a/plugins/include/sdktools.inc b/plugins/include/sdktools.inc index 94617190..685c3b4f 100644 --- a/plugins/include/sdktools.inc +++ b/plugins/include/sdktools.inc @@ -21,6 +21,7 @@ #include #include #include +#include enum SDKCallType { diff --git a/plugins/include/sdktools_tempents.inc b/plugins/include/sdktools_tempents.inc index 5ad21fbb..8a34f90d 100644 --- a/plugins/include/sdktools_tempents.inc +++ b/plugins/include/sdktools_tempents.inc @@ -63,7 +63,7 @@ native TE_WriteFloat(const String:prop[], Float:value); * @noreturn * @error Property not found. */ -native TE_WriteVector(const String:prop[], Float:vector[3]); +native TE_WriteVector(const String:prop[], const Float:vector[3]); /** * Sets a QAngle in the current temp entity. @@ -73,7 +73,18 @@ native TE_WriteVector(const String:prop[], Float:vector[3]); * @return True on success, otherwise false. * @error Property not found. */ -native TE_WriteAngles(const String:prop[], Float:angles[3]); +native TE_WriteAngles(const String:prop[], const Float:angles[3]); + +/** + * Sets an array of floats in the current temp entity. + * + * @param prop Property to use. + * @param array Array of values to copy. + * @param arraySize Number of values to copy. + * @return True on success, otherwise false. + * @error Property not found. + */ +native TE_WriteFloatArray(const String:prop[], const Float:array[], arraySize); /** * Sends the current temp entity to one or more clients. diff --git a/plugins/include/sdktools_tempents_stocks.inc b/plugins/include/sdktools_tempents_stocks.inc new file mode 100644 index 00000000..5b590a73 --- /dev/null +++ b/plugins/include/sdktools_tempents_stocks.inc @@ -0,0 +1,402 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This file is part of the SourceMod/SourcePawn SDK. This file may only be used + * or modified under the Terms and Conditions of its License Agreement, which is found + * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins + * may change at any time. To view the latest information, see: + * http://www.sourcemod.net/license.php + * + * Version: $Id$ + */ + +#if defined _te_stocks_included + #endinput +#endif +#define _te_stocks_included + +/** + * Sets up a sparks effect. + * + * @param pos Position of the sparks. + * @param dir Direction of the sparks. + * @param Magnitude Sparks size. + * @param TrailLength Trail lenght of the sparks. + * @noreturn + */ +stock TE_SetupSparks(const Float:pos[3], const Float:dir[3], Magnitude, TrailLength) +{ + TE_Start("Sparks"); + TE_WriteVector("m_vecOrigin[0]", pos); + TE_WriteVector("m_vecDir", dir); + TE_WriteNum("m_nMagnitude", Magnitude); + TE_WriteNum("m_nTrailLength", TrailLength); +} + +/** + * Sets up a smoke effect. + * + * @param pos Position of the smoke. + * @param Model Precached model index. + * @param Scale Scale of the smoke. + * @param Framerate Frame rate of the smoke. + * @noreturn + */ +stock TE_SetupSmoke(const Float:pos[3], Model, Float:Scale, FrameRate) +{ + TE_Start("Smoke"); + TE_WriteVector("m_vecOrigin", pos); + TE_WriteNum("m_nModelIndex", Model); + TE_WriteFloat("m_fScale", Scale); + TE_WriteNum("m_nFrameRate", FrameRate); +} + +/** + * Sets up a dust cloud effect. + * + * @param pos Position of the dust. + * @param dir Direction of the dust. + * @param Size Dust cloud size. + * @param Speed Dust cloud speed. + * @noreturn + */ +stock TE_SetupDust(const Float:pos[3], const Float:dir[3], Float:Size, Float:Speed) +{ + TE_Start("Dust"); + TE_WriteVector("m_vecOrigin[0]", pos); + TE_WriteVector("m_vecDirection", dir); + TE_WriteFloat("m_flSize", Size); + TE_WriteFloat("m_flSpeed", Speed); +} + +/** + * Sets up a muzzle flash effect. + * + * @param pos Position of the muzzle flash. + * @param angles Rotation angles of the muzzle flash. + * @param Scale Scale of the muzzle flash. + * @param Type Muzzle flash type to render (Mod specific). + * @noreturn + */ +stock TE_SetupMuzzleFlash(const Float:pos[3], const Float:angles[3], Float:Scale, Type) +{ + TE_Start("MuzzleFlash"); + TE_WriteVector("m_vecOrigin", pos); + TE_WriteVector("m_vecAngles", angles); + TE_WriteFloat("m_flScale", Scale); + TE_WriteNum("m_nType", Type); +} + +/** + * Sets up a metal sparks effect. + * + * @param pos Position of the metal sparks. + * @param dir Direction of the metal sparks. + * @noreturn + */ +stock TE_SetupMetalSparks(const Float:pos[3], const Float:dir[3]) +{ + TE_Start("Metal Sparks"); + TE_WriteVector("m_vecPos", pos); + TE_WriteVector("m_vecDir", dir); +} + +/** + * Sets up an energy splash effect. + * + * @param pos Position of the energy splash. + * @param dir Direction of the energy splash. + * @param Explosive Makes the effect explosive. + * @noreturn + */ +stock TE_SetupEnergySplash(const Float:pos[3], const Float:dir[3], bool:Explosive) +{ + TE_Start("Energy Splash"); + TE_WriteVector("m_vecPos", pos); + TE_WriteVector("m_vecDir", dir); + TE_WriteNum("m_bExplosive", Explosive); +} + +/** + * Sets up an armor ricochet effect. + * + * @param pos Position of the armor ricochet. + * @param dir Directon of the armor ricochet. + * @noreturn + */ +stock TE_SetupArmorRicochet(const Float:pos[3], const Float:dir[3]) +{ + TE_Start("Armor Ricochet"); + TE_WriteVector("m_vecPos", pos); + TE_WriteVector("m_vecDir", dir); +} + +/** + * Sets up a glowing sprite effect. + * + * @param pos Position of the sprite. + * @param Model Precached model index. + * @param Life Time duration of the sprite. + * @param Size Sprite size. + * @param Brightness Sprite brightness. + * @noreturn + */ +stock TE_SetupGlowSprite(const Float:pos[3], Model, Float:Life, Float:Size, Brightness) +{ + TE_Start("GlowSprite"); + TE_WriteVector("m_vecOrigin", pos); + TE_WriteNum("m_nModelIndex", Model); + TE_WriteFloat("m_fScale", Size); + TE_WriteFloat("m_fLife", Life); + TE_WriteNum("m_nBrightness", Brightness); +} + +/* :TODO: expose the flags */ +/** + * Sets up a explosion effect. + * + * @param pos Explosion position. + * @param Model Precached model index. + * @param Scale Explosion scale. + * @param Framerate Explosion frame rate. + * @param Flags Explosion flags. + * @param Radius Explosion radius. + * @param Magnitude Explosion size. + * @param normal Normal vector to the explosion. + * @param MaterialType Exploded material type. + * @noreturn + */ +stock TE_SetupExplosion(const Float:pos[3], Model, Float:Scale, Framerate, Flags, Radius, Magnitude, const Float:normal[3]={0.0, 0.0, 1.0}, MaterialType='C') +{ + TE_Start("Explosion"); + TE_WriteVector("m_vecOrigin[0]", pos); + TE_WriteVector("m_vecNormal", normal); + TE_WriteNum("m_nModelIndex", Model); + TE_WriteFloat("m_fScale", Scale); + TE_WriteNum("m_nFrameRate", Framerate); + TE_WriteNum("m_nFlags", Flags); + TE_WriteNum("m_nRadius", Radius); + TE_WriteNum("m_nMagnitude", Magnitude); + TE_WriteNum("m_chMaterialType", MaterialType); +} + +/** + * Sets up a blood sprite effect. + * + * @param pos Position of the sprite. + * @param dir Sprite direction. + * @param color Color array (r, g, b, a). + * @param Size Sprite size. + * @param SprayModel Precached model index. + * @param BloodDropModel Precached model index. + * @noreturn + */ +stock TE_SetupBloodSprite(const Float:pos[3], const Float:dir[3], const color[4], Size, SprayModel, BloodDropModel) +{ + TE_Start("Blood Sprite"); + TE_WriteVector("m_vecOrigin", pos); + TE_WriteVector("m_vecDirection", dir); + TE_WriteNum("r", color[0]); + TE_WriteNum("g", color[1]); + TE_WriteNum("b", color[2]); + TE_WriteNum("a", color[3]); + TE_WriteNum("m_nSize", Size); + TE_WriteNum("m_nSprayModel", SprayModel); + TE_WriteNum("m_nDropModel", BloodDropModel); +} + +/* :TODO: expose flags */ +/** + * Sets up a beam ring point effect. + * + * @param center Center position of the ring. + * @param Start_Radius Initial ring radius. + * @param End_Radius Final ring radius. + * @param ModelIndex Precached model index. + * @param HaloIndex Precached model index. + * @param StartFrame Initital frame to render. + * @param FrameRate Ring frame rate. + * @param Life Time duration of the ring. + * @param Width Beam width. + * @param Amplitude Beam amplitude. + * @param color Color array (r, g, b, a). + * @param Speed Speed of the beam. + * @param Flags Beam flags. + * @noreturn + */ +stock TE_SetupBeamRingPoint(const Float:center[3], Float:Start_Radius, Float:End_Radius, ModelIndex, HaloIndex, StartFrame, + FrameRate, Float:Life, Float:Width, Float:Amplitude, const Color[4], Speed, Flags) +{ + TE_Start("BeamRingPoint"); + TE_WriteVector("m_vecCenter", center); + TE_WriteFloat("m_flStartRadius", Start_Radius); + TE_WriteFloat("m_flEndRadius", End_Radius); + TE_WriteNum("m_nModelIndex", ModelIndex); + TE_WriteNum("m_nHaloIndex", HaloIndex); + TE_WriteNum("m_nStartFrame", StartFrame); + TE_WriteNum("m_nFrameRate", FrameRate); + TE_WriteFloat("m_fLife", Life); + TE_WriteFloat("m_fWidth", Width); + TE_WriteFloat("m_fEndWidth", Width); + TE_WriteFloat("m_fAmplitude", Amplitude); + TE_WriteNum("r", Color[0]); + TE_WriteNum("g", Color[1]); + TE_WriteNum("b", Color[2]); + TE_WriteNum("a", Color[3]); + TE_WriteNum("m_nSpeed", Speed); + TE_WriteNum("m_nFlags", Flags); + TE_WriteNum("m_nFadeLength", 0); +} + +/** + * Sets up a point to point beam effect. + * + * @param start Start position of the beam. + * @param end End position of the beam. + * @param ModelIndex Precached model index. + * @param HaloIndex Precached model index. + * @param StartFrame Initital frame to render. + * @param FrameRate Beam frame rate. + * @param Life Time duration of the beam. + * @param Width Initial beam width. + * @param EndWidth Final beam width. + * @param FadeLength Beam fade time duration. + * @param Amplitude Beam amplitude. + * @param color Color array (r, g, b, a). + * @param Speed Speed of the beam. + * @noreturn + */ +stock TE_SetupBeamPoints(const Float:start[3], const Float:end[3], ModelIndex, HaloIndex, StartFrame, FrameRate, Float:Life, + Float:Width, Float:EndWidth, FadeLength, Float:Amplitude, const Color[4], Speed) +{ + TE_Start("BeamPoints"); + TE_WriteVector("m_vecStartPoint", start); + TE_WriteVector("m_vecEndPoint", end); + TE_WriteNum("m_nModelIndex", ModelIndex); + TE_WriteNum("m_nHaloIndex", HaloIndex); + TE_WriteNum("m_nStartFrame", StartFrame); + TE_WriteNum("m_nFrameRate", FrameRate); + TE_WriteFloat("m_fLife", Life); + TE_WriteFloat("m_fWidth", Width); + TE_WriteFloat("m_fEndWidth", EndWidth); + TE_WriteFloat("m_fAmplitude", Amplitude); + TE_WriteNum("r", Color[0]); + TE_WriteNum("g", Color[1]); + TE_WriteNum("b", Color[2]); + TE_WriteNum("a", Color[3]); + TE_WriteNum("m_nSpeed", Speed); + TE_WriteNum("m_nFadeLength", FadeLength); +} + +/** + * Sets up an entity to entity laser effect. + * + * @param StartEntity Entity index from where the beam starts. + * @param EndEntity Entity index from where the beam ends. + * @param ModelIndex Precached model index. + * @param HaloIndex Precached model index. + * @param StartFrame Initital frame to render. + * @param FrameRate Beam frame rate. + * @param Life Time duration of the beam. + * @param Width Initial beam width. + * @param EndWidth Final beam width. + * @param FadeLength Beam fade time duration. + * @param Amplitude Beam amplitude. + * @param color Color array (r, g, b, a). + * @param Speed Speed of the beam. + * @noreturn + */ +stock TE_SetupBeamLaser(StartEntity, EndEntity, ModelIndex, HaloIndex, StartFrame, FrameRate, Float:Life, + Float:Width, Float:EndWidth, FadeLength, Float:Amplitude, const Color[4], Speed) +{ + TE_Start("BeamLaser"); + TE_WriteEncodedEnt("m_nStartEntity", StartEntity); + TE_WriteEncodedEnt("m_nEndEntity", EndEntity); + TE_WriteNum("m_nModelIndex", ModelIndex); + TE_WriteNum("m_nHaloIndex", HaloIndex); + TE_WriteNum("m_nStartFrame", StartFrame); + TE_WriteNum("m_nFrameRate", FrameRate); + TE_WriteFloat("m_fLife", Life); + TE_WriteFloat("m_fWidth", Width); + TE_WriteFloat("m_fEndWidth", EndWidth); + TE_WriteFloat("m_fAmplitude", Amplitude); + TE_WriteNum("r", Color[0]); + TE_WriteNum("g", Color[1]); + TE_WriteNum("b", Color[2]); + TE_WriteNum("a", Color[3]); + TE_WriteNum("m_nSpeed", Speed); + TE_WriteNum("m_nFadeLength", FadeLength); +} + +/** + * Sets up a beam ring effect. + * + * @param StartEntity Entity index from where the ring starts. + * @param EndEntity Entity index from where the ring ends. + * @param ModelIndex Precached model index. + * @param HaloIndex Precached model index. + * @param StartFrame Initital frame to render. + * @param FrameRate Ring frame rate. + * @param Life Time duration of the ring. + * @param Width Beam width. + * @param Amplitude Beam amplitude. + * @param color Color array (r, g, b, a). + * @param Speed Speed of the beam. + * @param Flags Beam flags. + * @noreturn + */ +stock TE_BeamRing(StartEntity, EndEntity, ModelIndex, HaloIndex, StartFrame, FrameRate, Float:Life, Float:Width, Float:Amplitude, const Color[4], Speed, Flags) +{ + TE_Start("BeamRing"); + TE_WriteEncodedEnt("m_nStartEntity", StartEntity); + TE_WriteEncodedEnt("m_nEndEntity", EndEntity); + TE_WriteNum("m_nModelIndex", ModelIndex); + TE_WriteNum("m_nHaloIndex", HaloIndex); + TE_WriteNum("m_nStartFrame", StartFrame); + TE_WriteNum("m_nFrameRate", FrameRate); + TE_WriteFloat("m_fLife", Life); + TE_WriteFloat("m_fWidth", Width); + TE_WriteFloat("m_fEndWidth", Width); + TE_WriteFloat("m_fAmplitude", Amplitude); + TE_WriteNum("r", Color[0]); + TE_WriteNum("g", Color[1]); + TE_WriteNum("b", Color[2]); + TE_WriteNum("a", Color[3]); + TE_WriteNum("m_nSpeed", Speed); + TE_WriteNum("m_nFadeLength", 0); + TE_WriteNum("m_nFlags", Flags); +} + +/** + * Sets up a follow beam effect. + * + * @param EntIndex Entity index from where the beam starts. + * @param ModelIndex Precached model index. + * @param HaloIndex Precached model index. + * @param Life Time duration of the beam. + * @param Width Initial beam width. + * @param EndWidth Final beam width. + * @param FadeLength Beam fade time duration. + * @param color Color array (r, g, b, a). + * @noreturn + */ +stock TE_BeamFollow(EntIndex, ModelIndex, HaloIndex, Float:Life, Float:Width, Float:EndWidth, FadeLength, const Color[4]) +{ + TE_Start("BeamFollow"); + TE_WriteEncodedEnt("m_iEntIndex", EntIndex); + TE_WriteNum("m_nModelIndex", ModelIndex); + TE_WriteNum("m_nHaloIndex", HaloIndex); + TE_WriteNum("m_nStartFrame", 0); + TE_WriteNum("m_nFrameRate", 0); + TE_WriteFloat("m_fLife", Life); + TE_WriteFloat("m_fWidth", Width); + TE_WriteFloat("m_fEndWidth", EndWidth); + TE_WriteNum("m_nFadeLength", FadeLength); + TE_WriteNum("r", Color[0]); + TE_WriteNum("g", Color[1]); + TE_WriteNum("b", Color[2]); + TE_WriteNum("a", Color[3]); +}