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 "sourcemod.h"
34 #include "HandleSys.h"
38 static cell_t smn_BfWriteBool(IPluginContext *pCtx, const cell_t *params)
40 Handle_t hndl = static_cast<Handle_t>(params[1]);
46 sec.pIdentity = g_pCoreIdent;
48 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
51 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
54 pBitBuf->WriteOneBit(params[2]);
59 static cell_t smn_BfWriteByte(IPluginContext *pCtx, const cell_t *params)
61 Handle_t hndl = static_cast<Handle_t>(params[1]);
67 sec.pIdentity = g_pCoreIdent;
69 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
72 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
75 pBitBuf->WriteByte(params[2]);
80 static cell_t smn_BfWriteChar(IPluginContext *pCtx, const cell_t *params)
82 Handle_t hndl = static_cast<Handle_t>(params[1]);
88 sec.pIdentity = g_pCoreIdent;
90 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
93 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
96 pBitBuf->WriteChar(params[2]);
101 static cell_t smn_BfWriteShort(IPluginContext *pCtx, const cell_t *params)
103 Handle_t hndl = static_cast<Handle_t>(params[1]);
109 sec.pIdentity = g_pCoreIdent;
111 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
114 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
117 pBitBuf->WriteShort(params[2]);
122 static cell_t smn_BfWriteWord(IPluginContext *pCtx, const cell_t *params)
124 Handle_t hndl = static_cast<Handle_t>(params[1]);
130 sec.pIdentity = g_pCoreIdent;
132 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
135 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
138 pBitBuf->WriteWord(params[2]);
143 static cell_t smn_BfWriteNum(IPluginContext *pCtx, const cell_t *params)
145 Handle_t hndl = static_cast<Handle_t>(params[1]);
151 sec.pIdentity = g_pCoreIdent;
153 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
156 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
159 pBitBuf->WriteLong(static_cast<long>(params[2]));
164 static cell_t smn_BfWriteFloat(IPluginContext *pCtx, const cell_t *params)
166 Handle_t hndl = static_cast<Handle_t>(params[1]);
172 sec.pIdentity = g_pCoreIdent;
174 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
177 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
180 pBitBuf->WriteFloat(sp_ctof(params[2]));
185 static cell_t smn_BfWriteString(IPluginContext *pCtx, const cell_t *params)
187 Handle_t hndl = static_cast<Handle_t>(params[1]);
194 sec.pIdentity = g_pCoreIdent;
196 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
199 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
203 if ((err=pCtx->LocalToString(params[2], &str)) != SP_ERROR_NONE)
205 pCtx->ThrowNativeErrorEx(err, NULL);
209 pBitBuf->WriteString(str);
214 static cell_t smn_BfWriteEntity(IPluginContext *pCtx, const cell_t *params)
216 Handle_t hndl = static_cast<Handle_t>(params[1]);
222 sec.pIdentity = g_pCoreIdent;
224 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
227 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
230 pBitBuf->WriteShort(params[2]);
235 static cell_t smn_BfWriteAngle(IPluginContext *pCtx, const cell_t *params)
237 Handle_t hndl = static_cast<Handle_t>(params[1]);
243 sec.pIdentity = g_pCoreIdent;
245 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
248 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
251 pBitBuf->WriteBitAngle(sp_ctof(params[2]), params[3]);
256 static cell_t smn_BfWriteCoord(IPluginContext *pCtx, const cell_t *params)
258 Handle_t hndl = static_cast<Handle_t>(params[1]);
264 sec.pIdentity = g_pCoreIdent;
266 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
269 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
272 pBitBuf->WriteBitCoord(sp_ctof(params[2]));
277 static cell_t smn_BfWriteVecCoord(IPluginContext *pCtx, const cell_t *params)
279 Handle_t hndl = static_cast<Handle_t>(params[1]);
285 sec.pIdentity = g_pCoreIdent;
287 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
290 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
294 pCtx->LocalToPhysAddr(params[2], &pVec);
295 Vector vec(sp_ctof(pVec[0]), sp_ctof(pVec[1]), sp_ctof(pVec[2]));
296 pBitBuf->WriteBitVec3Coord(vec);
301 static cell_t smn_BfWriteVecNormal(IPluginContext *pCtx, const cell_t *params)
303 Handle_t hndl = static_cast<Handle_t>(params[1]);
309 sec.pIdentity = g_pCoreIdent;
311 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
314 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
318 pCtx->LocalToPhysAddr(params[2], &pVec);
319 Vector vec(sp_ctof(pVec[0]), sp_ctof(pVec[1]), sp_ctof(pVec[2]));
320 pBitBuf->WriteBitVec3Normal(vec);
325 static cell_t smn_BfWriteAngles(IPluginContext *pCtx, const cell_t *params)
327 Handle_t hndl = static_cast<Handle_t>(params[1]);
333 sec.pIdentity = g_pCoreIdent;
335 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
338 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
342 pCtx->LocalToPhysAddr(params[2], &pAng);
343 QAngle ang(sp_ctof(pAng[0]), sp_ctof(pAng[1]), sp_ctof(pAng[2]));
344 pBitBuf->WriteBitAngles(ang);
349 static cell_t smn_BfReadBool(IPluginContext *pCtx, const cell_t *params)
351 Handle_t hndl = static_cast<Handle_t>(params[1]);
357 sec.pIdentity = g_pCoreIdent;
359 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
362 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
365 return pBitBuf->ReadOneBit() ? 1 : 0;
368 static cell_t smn_BfReadByte(IPluginContext *pCtx, const cell_t *params)
370 Handle_t hndl = static_cast<Handle_t>(params[1]);
376 sec.pIdentity = g_pCoreIdent;
378 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
381 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
384 return pBitBuf->ReadByte();
387 static cell_t smn_BfReadChar(IPluginContext *pCtx, const cell_t *params)
389 Handle_t hndl = static_cast<Handle_t>(params[1]);
395 sec.pIdentity = g_pCoreIdent;
397 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
400 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
403 return pBitBuf->ReadChar();
406 static cell_t smn_BfReadShort(IPluginContext *pCtx, const cell_t *params)
408 Handle_t hndl = static_cast<Handle_t>(params[1]);
414 sec.pIdentity = g_pCoreIdent;
416 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
419 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
422 return pBitBuf->ReadShort();
425 static cell_t smn_BfReadWord(IPluginContext *pCtx, const cell_t *params)
427 Handle_t hndl = static_cast<Handle_t>(params[1]);
433 sec.pIdentity = g_pCoreIdent;
435 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
438 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
441 return pBitBuf->ReadWord();
444 static cell_t smn_BfReadNum(IPluginContext *pCtx, const cell_t *params)
446 Handle_t hndl = static_cast<Handle_t>(params[1]);
452 sec.pIdentity = g_pCoreIdent;
454 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
457 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
460 return static_cast<cell_t>(pBitBuf->ReadLong());
463 static cell_t smn_BfReadFloat(IPluginContext *pCtx, const cell_t *params)
465 Handle_t hndl = static_cast<Handle_t>(params[1]);
471 sec.pIdentity = g_pCoreIdent;
473 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
476 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
479 return sp_ftoc(pBitBuf->ReadFloat());
482 static cell_t smn_BfReadString(IPluginContext *pCtx, const cell_t *params)
484 Handle_t hndl = static_cast<Handle_t>(params[1]);
491 sec.pIdentity = g_pCoreIdent;
493 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
496 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
499 pCtx->LocalToPhysAddr(params[2], (cell_t **)&buf);
500 if (!pBitBuf->ReadString(buf, params[3], params[4] ? true : false))
502 return pCtx->ThrowNativeError("Destination string buffer is too short, try increasing its size");
508 static cell_t smn_BfReadEntity(IPluginContext *pCtx, const cell_t *params)
510 Handle_t hndl = static_cast<Handle_t>(params[1]);
516 sec.pIdentity = g_pCoreIdent;
518 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
521 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
524 return pBitBuf->ReadShort();
527 static cell_t smn_BfReadAngle(IPluginContext *pCtx, const cell_t *params)
529 Handle_t hndl = static_cast<Handle_t>(params[1]);
535 sec.pIdentity = g_pCoreIdent;
537 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
540 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
543 return sp_ftoc(pBitBuf->ReadBitAngle(params[2]));
546 static cell_t smn_BfReadCoord(IPluginContext *pCtx, const cell_t *params)
548 Handle_t hndl = static_cast<Handle_t>(params[1]);
554 sec.pIdentity = g_pCoreIdent;
556 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
559 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
562 return sp_ftoc(pBitBuf->ReadBitCoord());
565 static cell_t smn_BfReadVecCoord(IPluginContext *pCtx, const cell_t *params)
567 Handle_t hndl = static_cast<Handle_t>(params[1]);
573 sec.pIdentity = g_pCoreIdent;
575 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
578 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
582 pCtx->LocalToPhysAddr(params[2], &pVec);
585 pBitBuf->ReadBitVec3Coord(vec);
587 pVec[0] = sp_ftoc(vec.x);
588 pVec[1] = sp_ftoc(vec.y);
589 pVec[2] = sp_ftoc(vec.z);
594 static cell_t smn_BfReadVecNormal(IPluginContext *pCtx, const cell_t *params)
596 Handle_t hndl = static_cast<Handle_t>(params[1]);
602 sec.pIdentity = g_pCoreIdent;
604 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
607 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
611 pCtx->LocalToPhysAddr(params[2], &pVec);
614 pBitBuf->ReadBitVec3Normal(vec);
616 pVec[0] = sp_ftoc(vec.x);
617 pVec[1] = sp_ftoc(vec.y);
618 pVec[2] = sp_ftoc(vec.z);
623 static cell_t smn_BfReadAngles(IPluginContext *pCtx, const cell_t *params)
625 Handle_t hndl = static_cast<Handle_t>(params[1]);
631 sec.pIdentity = g_pCoreIdent;
633 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
636 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
640 pCtx->LocalToPhysAddr(params[2], &pAng);
643 pBitBuf->ReadBitAngles(ang);
645 pAng[0] = sp_ftoc(ang.x);
646 pAng[1] = sp_ftoc(ang.y);
647 pAng[2] = sp_ftoc(ang.z);
652 REGISTER_NATIVES(bitbufnatives)
654 {"BfWriteBool", smn_BfWriteBool},
655 {"BfWriteByte", smn_BfWriteByte},
656 {"BfWriteChar", smn_BfWriteChar},
657 {"BfWriteShort", smn_BfWriteShort},
658 {"BfWriteWord", smn_BfWriteWord},
659 {"BfWriteNum", smn_BfWriteNum},
660 {"BfWriteFloat", smn_BfWriteFloat},
661 {"BfWriteString", smn_BfWriteString},
662 {"BfWriteEntity", smn_BfWriteEntity},
663 {"BfWriteAngle", smn_BfWriteAngle},
664 {"BfWriteCoord", smn_BfWriteCoord},
665 {"BfWriteVecCoord", smn_BfWriteVecCoord},
666 {"BfWriteVecNormal", smn_BfWriteVecNormal},
667 {"BfWriteAngles", smn_BfWriteAngles},
668 {"BfReadBool", smn_BfReadBool},
669 {"BfReadByte", smn_BfReadByte},
670 {"BfReadChar", smn_BfReadChar},
671 {"BfReadShort", smn_BfReadShort},
672 {"BfReadWord", smn_BfReadWord},
673 {"BfReadNum", smn_BfReadNum},
674 {"BfReadFloat", smn_BfReadFloat},
675 {"BfReadString", smn_BfReadString},
676 {"BfReadEntity", smn_BfReadEntity},
677 {"BfReadAngle", smn_BfReadAngle},
678 {"BfReadCoord", smn_BfReadCoord},
679 {"BfReadVecCoord", smn_BfReadVecCoord},
680 {"BfReadVecNormal", smn_BfReadVecNormal},
681 {"BfReadAngles", smn_BfReadAngles},