Skip to content

Commit

Permalink
Add ReAPI support as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaroq7 committed Aug 17, 2017
1 parent 9890069 commit 022d9ff
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions amxmodx/scripting/ctw.sma
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
* Requirement(s):
* AMX Mod X 1.8.3
* (optional) ReAPI module
*
* Setup:
* Put .sma file into the amxmodx/scripting folder
Expand All @@ -32,11 +33,18 @@
*
*/

//Enables ReAPI support
//#define REAPI_SUPPORT

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine>
#include <hamsandwich>
#if defined REAPI_SUPPORT
#include <reapi>
#else
#include <engine>
#include <cstrike>
#include <hamsandwich>
#endif
#include <fakemeta>

#define INVALID_WIRE -1
Expand All @@ -50,7 +58,10 @@ new g_hMenu;

new g_eC4;
new g_iWire;

#if !defined REAPI_SUPPORT
new g_iBarTimeMsg;
#endif

new Array:g_arrayWires;
new g_iWires;
Expand All @@ -66,14 +77,20 @@ public plugin_init()

create_cvar("ctw_version", "0.0.4-dev", FCVAR_SERVER, "CTW version");

#if !defined REAPI_SUPPORT
g_iBarTimeMsg = get_user_msgid("BarTime");
#endif

register_event("BarTime", "OnBarTimeEvent", "bef", "1=0", "1=3", "1=5", "1=10");
register_logevent("OnNewRoundStart", 2, "1=Round_Start");
register_logevent("OnBombPlanted", 3, "2=Planted_The_Bomb");
register_logevent("OnBombDefused", 3, "2=Defused_The_Bomb");

#if defined REAPI_SUPPORT
RegisterHookChain(RG_CBasePlayer_Spawn, "CBasePlayerSpawnPost", 1);
#else
RegisterHamPlayer(Ham_Killed, "CBasePlayerKilledPost", 1);
#endif

g_arrayWires = ArrayCreate(32);

Expand Down Expand Up @@ -138,15 +155,23 @@ public MenuWiresHandler(id, menu, key)
if (key == MENU_TIMEOUT || key == MENU_EXIT)
return PLUGIN_HANDLED;

#if defined REAPI_SUPPORT
if (get_member(id, m_iTeam) == TEAM_TERRORIST)
#else
if (cs_get_user_team(id) == CS_TEAM_T)
#endif
{
g_iWire = key;
client_print_color(id, id, "%s %l", g_szPrefix, "CHOSE_WIRE", ArrayGetStringHandle(g_arrayWires, key));
return PLUGIN_HANDLED;
}

//Sometimes g_eC4 is not valid ent, idk why this is happening
#if defined REAPI_SUPPORT
if (!is_entity(g_eC4))
#else
if (!is_valid_ent(g_eC4))
#endif
return PLUGIN_HANDLED;

if (g_iWire == key)
Expand All @@ -160,9 +185,13 @@ public MenuWiresHandler(id, menu, key)
set_ent_data_float(g_eC4, "CGrenade", "m_flC4Blow", get_gametime());
}

#if defined REAPI_SUPPORT
rg_send_bartime(id, 0);
#else
message_begin(MSG_ONE, g_iBarTimeMsg, _, id);
write_short(0);
message_end();
#endif

return PLUGIN_HANDLED;
}
Expand All @@ -172,7 +201,20 @@ public OnBombPlanted()
//g_ePlayerResetMenu bartime event
HideMenu(g_ePlayerResetMenu);

#if defined REAPI_SUPPORT
new iIndex = -1, szModel[32];
while ((iIndex = rg_find_ent_by_class(iIndex, "grenade", true)))
{
get_entvar(iIndex, var_model, szModel, charsmax(szModel));
if (!equal(szModel, "models/w_c4.mdl"))
{
g_eC4 = iIndex;
break;
}
}
#else
g_eC4 = find_ent_by_model(-1, "grenade", "models/w_c4.mdl");
#endif

if (g_iWire == INVALID_WIRE)
g_iWire = random(g_iWires);
Expand Down

0 comments on commit 022d9ff

Please sign in to comment.