3 * ================================================================
4 * SourceMod SDKTools Extension
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * ================================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License,
10 * version 3.0, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to
21 * link the code of this program (as well as its derivative works) to
22 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
23 * Game MODs that run on software by the Valve Corporation. You must
24 * obey the GNU General Public License in all respects for all other
25 * code used. Additionally, AlliedModders LLC grants this exception
26 * to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version
28 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
34 #include "CellRecipientFilter.h"
36 CellRecipientFilter g_TERecFilter;
37 TempEntityInfo *g_CurrentTE = NULL;
39 static cell_t smn_TEStart(IPluginContext *pContext, const cell_t *params)
41 if (!g_TEManager.IsAvailable())
43 return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
47 pContext->LocalToString(params[1], &name);
49 g_CurrentTE = g_TEManager.GetTempEntityInfo(name);
52 return pContext->ThrowNativeError("Invalid TempEntity name: \"%s\"", name);
58 static cell_t smn_TEWriteNum(IPluginContext *pContext, const cell_t *params)
60 if (!g_TEManager.IsAvailable())
62 return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
66 return pContext->ThrowNativeError("No TempEntity call is in progress");
70 pContext->LocalToString(params[1], &prop);
72 if (!g_CurrentTE->TE_SetEntData(prop, params[2]))
74 return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop);
80 static cell_t smn_TE_WriteFloat(IPluginContext *pContext, const cell_t *params)
82 if (!g_TEManager.IsAvailable())
84 return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
88 return pContext->ThrowNativeError("No TempEntity call is in progress");
92 pContext->LocalToString(params[1], &prop);
94 if (!g_CurrentTE->TE_SetEntDataFloat(prop, sp_ctof(params[2])))
96 return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop);
102 static cell_t smn_TEWriteVector(IPluginContext *pContext, const cell_t *params)
104 if (!g_TEManager.IsAvailable())
106 return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
110 return pContext->ThrowNativeError("No TempEntity call is in progress");
114 pContext->LocalToString(params[1], &prop);
117 pContext->LocalToPhysAddr(params[2], &addr);
118 float vec[3] = {sp_ctof(addr[0]), sp_ctof(addr[1]), sp_ctof(addr[2])};
120 if (!g_CurrentTE->TE_SetEntDataVector(prop, vec))
122 return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop);
128 static cell_t smn_TEWriteFloatArray(IPluginContext *pContext, const cell_t *params)
130 if (!g_TEManager.IsAvailable())
132 return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
136 return pContext->ThrowNativeError("No TempEntity call is in progress");
140 pContext->LocalToString(params[1], &prop);
143 pContext->LocalToPhysAddr(params[2], &addr);
145 if (!g_CurrentTE->TE_SetEntDataFloatArray(prop, addr, params[3]))
147 return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop);
153 static cell_t smn_TESend(IPluginContext *pContext, const cell_t *params)
155 if (!g_TEManager.IsAvailable())
157 return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
161 return pContext->ThrowNativeError("No TempEntity call is in progress");
165 pContext->LocalToPhysAddr(params[1], &cl_array);
167 g_TERecFilter.Reset();
168 g_TERecFilter.Initialize(cl_array, params[2]);
170 g_CurrentTE->Send(g_TERecFilter, sp_ctof(params[3]));
176 static cell_t smn_TEIsValidProp(IPluginContext *pContext, const cell_t *params)
178 if (!g_TEManager.IsAvailable())
180 return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
184 return pContext->ThrowNativeError("No TempEntity call is in progress");
188 pContext->LocalToString(params[1], &prop);
190 return g_CurrentTE->IsValidProp(prop) ? 1 : 0;
193 sp_nativeinfo_t g_TENatives[] =
195 {"TE_Start", smn_TEStart},
196 {"TE_WriteNum", smn_TEWriteNum},
197 {"TE_WriteFloat", smn_TE_WriteFloat},
198 {"TE_WriteVector", smn_TEWriteVector},
199 {"TE_WriteAngles", smn_TEWriteVector},
200 {"TE_Send", smn_TESend},
201 {"TE_IsValidProp", smn_TEIsValidProp},
202 {"TE_WriteFloatArray", smn_TEWriteFloatArray},