Added check to make sure player are alive to perform sm_slap, sm_burn, sm_slay.
3 * ================================================================
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>.
33 #include "sm_globals.h"
37 #define SET_VECTOR(addr, vec) \
38 addr[0] = sp_ftoc(vec.x); \
39 addr[1] = sp_ftoc(vec.y); \
40 addr[2] = sp_ftoc(vec.z);
42 static cell_t GetVectorLength(IPluginContext *pContext, const cell_t *params)
46 pContext->LocalToPhysAddr(params[1], &addr);
48 Vector source(sp_ctof(addr[0]), sp_ctof(addr[1]), sp_ctof(addr[2]));
52 return sp_ftoc(source.Length());
54 return sp_ftoc(source.LengthSqr());
58 static cell_t GetVectorDistance(IPluginContext *pContext, const cell_t *params)
60 cell_t *addr1, *addr2;
62 pContext->LocalToPhysAddr(params[1], &addr1);
63 pContext->LocalToPhysAddr(params[2], &addr2);
65 Vector source(sp_ctof(addr1[0]), sp_ctof(addr1[1]), sp_ctof(addr1[2]));
66 Vector dest(sp_ctof(addr2[0]), sp_ctof(addr2[1]), sp_ctof(addr2[2]));
70 return sp_ftoc(source.DistTo(dest));
72 return sp_ftoc(source.DistToSqr(dest));
76 static cell_t GetVectorDotProduct(IPluginContext *pContext, const cell_t *params)
78 cell_t *addr1, *addr2;
80 pContext->LocalToPhysAddr(params[1], &addr1);
81 pContext->LocalToPhysAddr(params[2], &addr2);
83 Vector source(sp_ctof(addr1[0]), sp_ctof(addr1[1]), sp_ctof(addr1[2]));
84 Vector dest(sp_ctof(addr2[0]), sp_ctof(addr2[1]), sp_ctof(addr2[2]));
86 return sp_ftoc(source.Dot(dest));
89 static cell_t GetVectorCrossProduct(IPluginContext *pContext, const cell_t *params)
91 cell_t *addr1, *addr2, *set;
93 pContext->LocalToPhysAddr(params[1], &addr1);
94 pContext->LocalToPhysAddr(params[2], &addr2);
95 pContext->LocalToPhysAddr(params[3], &set);
97 Vector vec1(sp_ctof(addr1[0]), sp_ctof(addr1[1]), sp_ctof(addr1[2]));
98 Vector vec2(sp_ctof(addr2[0]), sp_ctof(addr2[1]), sp_ctof(addr2[2]));
100 Vector vec3 = vec1.Cross(vec2);
102 SET_VECTOR(set, vec3);
107 static cell_t GetAngleVectors(IPluginContext *pContext, const cell_t *params)
111 pContext->LocalToPhysAddr(params[1], &ang_addr);
113 QAngle angle(sp_ctof(ang_addr[0]), sp_ctof(ang_addr[1]), sp_ctof(ang_addr[2]));
114 Vector fwd, right, up;
116 AngleVectors(angle, &fwd, &right, &up);
118 cell_t *addr_fwd, *addr_right, *addr_up;
119 pContext->LocalToPhysAddr(params[2], &addr_fwd);
120 pContext->LocalToPhysAddr(params[3], &addr_right);
121 pContext->LocalToPhysAddr(params[4], &addr_up);
123 SET_VECTOR(addr_fwd, fwd);
124 SET_VECTOR(addr_right, right);
125 SET_VECTOR(addr_up, up);
130 static cell_t GetVectorAngles(IPluginContext *pContext, const cell_t *params)
134 pContext->LocalToPhysAddr(params[1], &vec_addr);
136 Vector vec(sp_ctof(vec_addr[0]), sp_ctof(vec_addr[1]), sp_ctof(vec_addr[2]));
139 VectorAngles(vec, angle);
142 pContext->LocalToPhysAddr(params[2], &ang_addr);
144 SET_VECTOR(ang_addr, angle);
149 static cell_t GetVectorVectors(IPluginContext *pContext, const cell_t *params)
153 pContext->LocalToPhysAddr(params[1], &vec_addr);
155 Vector vec(sp_ctof(vec_addr[0]), sp_ctof(vec_addr[1]), sp_ctof(vec_addr[2]));
158 VectorVectors(vec, right, up);
160 cell_t *addr_right, *addr_up;
161 pContext->LocalToPhysAddr(params[2], &addr_right);
162 pContext->LocalToPhysAddr(params[3], &addr_up);
164 SET_VECTOR(addr_right, right);
165 SET_VECTOR(addr_up, up);
170 static cell_t NormalizeVector(IPluginContext *pContext, const cell_t *params)
174 pContext->LocalToPhysAddr(params[1], &addr);
176 Vector source(sp_ctof(addr[0]), sp_ctof(addr[1]), sp_ctof(addr[2]));
177 float length = VectorNormalize(source);
179 pContext->LocalToPhysAddr(params[2], &addr);
180 SET_VECTOR(addr, source);
182 return sp_ftoc(length);
185 REGISTER_NATIVES(vectorNatives)
187 {"GetAngleVectors", GetAngleVectors},
188 {"GetVectorAngles", GetVectorAngles},
189 {"GetVectorCrossProduct", GetVectorCrossProduct},
190 {"GetVectorDistance", GetVectorDistance},
191 {"GetVectorDotProduct", GetVectorDotProduct},
192 {"GetVectorLength", GetVectorLength},
193 {"GetVectorVectors", GetVectorVectors},
194 {"NormalizeVector", NormalizeVector},