Consistency: Replace GetPlayerEdict with HLTypeConversion in fun module

This commit is contained in:
Arkshine 2015-10-07 00:26:14 +02:00
parent e52fc14114
commit bf5fdc2b5c
4 changed files with 36 additions and 37 deletions

View File

@ -13,6 +13,7 @@
#include <string.h> #include <string.h>
#include "fun.h" #include "fun.h"
#include <HLTypeConversion.h>
/* /*
JGHG says: JGHG says:
@ -39,6 +40,11 @@
} }
*/ */
char g_bodyhits[33][33]; // where can the guy in the first dimension hit the people in the 2nd dimension? :-)
bool g_silent[33]; // used for set_user_footsteps()
HLTypeConversion TypeConversion;
// ######## Utils: // ######## Utils:
void FUNUTIL_ResetPlayer(int index) void FUNUTIL_ResetPlayer(int index)
{ {
@ -100,7 +106,7 @@ static cell AMX_NATIVE_CALL set_user_godmode(AMX *amx, cell *params) // set_user
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Get player pointer. // Get player pointer.
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
if (params[2] == 1) { if (params[2] == 1) {
// Enable godmode // Enable godmode
@ -123,7 +129,7 @@ static cell AMX_NATIVE_CALL get_user_godmode(AMX *amx, cell *params) // get_user
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Get player pointer. // Get player pointer.
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
int godmode = 0; int godmode = 0;
@ -147,7 +153,7 @@ static cell AMX_NATIVE_CALL give_item(AMX *amx, cell *params) // native give_ite
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Get player pointer. // Get player pointer.
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
// Create item entity pointer // Create item entity pointer
edict_t *pItemEntity; edict_t *pItemEntity;
@ -211,7 +217,7 @@ static cell AMX_NATIVE_CALL spawn(AMX *amx, cell *params) // spawn(id) = 1 param
CHECK_ENTITY(params[1]); CHECK_ENTITY(params[1]);
edict_t *pEnt = GETEDICT(params[1]); edict_t *pEnt = TypeConversion.id_to_edict(params[1]);
MDLL_Spawn(pEnt); MDLL_Spawn(pEnt);
@ -228,7 +234,7 @@ static cell AMX_NATIVE_CALL set_user_health(AMX *amx, cell *params) // set_user_
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Fetch player pointer // Fetch player pointer
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
// Kill if health too low. // Kill if health too low.
if (params[2] > 0) if (params[2] > 0)
@ -249,7 +255,7 @@ static cell AMX_NATIVE_CALL set_user_frags(AMX *amx, cell *params) // set_user_f
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Fetch player pointer // Fetch player pointer
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
pPlayer->v.frags = params[2]; pPlayer->v.frags = params[2];
@ -266,7 +272,7 @@ static cell AMX_NATIVE_CALL set_user_armor(AMX *amx, cell *params) // set_user_a
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Fetch player pointer // Fetch player pointer
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
pPlayer->v.armorvalue = params[2]; pPlayer->v.armorvalue = params[2];
@ -283,7 +289,7 @@ static cell AMX_NATIVE_CALL set_user_origin(AMX *amx, cell *params) // set_user_
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Fetch player pointer // Fetch player pointer
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
cell *newVectorCell = MF_GetAmxAddr(amx, params[2]); cell *newVectorCell = MF_GetAmxAddr(amx, params[2]);
@ -308,7 +314,7 @@ static cell AMX_NATIVE_CALL set_user_rendering(AMX *amx, cell *params) // set_us
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Fetch player pointer // Fetch player pointer
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
pPlayer->v.renderfx = params[2]; pPlayer->v.renderfx = params[2];
Vector newVector = Vector(float(params[3]), float(params[4]), float(params[5])); Vector newVector = Vector(float(params[3]), float(params[4]), float(params[5]));
@ -332,7 +338,7 @@ static cell AMX_NATIVE_CALL set_user_maxspeed(AMX *amx, cell *params) // set_use
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Fetch player pointer // Fetch player pointer
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
SETCLIENTMAXSPEED(pPlayer, fNewSpeed); SETCLIENTMAXSPEED(pPlayer, fNewSpeed);
pPlayer->v.maxspeed = fNewSpeed; pPlayer->v.maxspeed = fNewSpeed;
@ -349,7 +355,7 @@ static cell AMX_NATIVE_CALL get_user_maxspeed(AMX *amx, cell *params) // Float:g
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Fetch player pointer // Fetch player pointer
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
return amx_ftoc(pPlayer->v.maxspeed); return amx_ftoc(pPlayer->v.maxspeed);
} }
@ -363,7 +369,7 @@ static cell AMX_NATIVE_CALL set_user_gravity(AMX *amx, cell *params) // set_user
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Fetch player pointer // Fetch player pointer
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
pPlayer->v.gravity = amx_ctof(params[2]); pPlayer->v.gravity = amx_ctof(params[2]);
@ -379,7 +385,7 @@ static cell AMX_NATIVE_CALL get_user_gravity(AMX *amx, cell *params) // Float:ge
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Fetch player pointer // Fetch player pointer
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
return amx_ftoc(pPlayer->v.gravity); return amx_ftoc(pPlayer->v.gravity);
} }
@ -449,7 +455,7 @@ static cell AMX_NATIVE_CALL set_user_noclip(AMX *amx, cell *params) // set_user_
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Fetch player pointer // Fetch player pointer
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
if (params[2] == 1) if (params[2] == 1)
pPlayer->v.movetype = MOVETYPE_NOCLIP; pPlayer->v.movetype = MOVETYPE_NOCLIP;
@ -468,7 +474,7 @@ static cell AMX_NATIVE_CALL get_user_noclip(AMX *amx, cell *params) // get_user_
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Fetch player pointer // Fetch player pointer
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
return pPlayer->v.movetype == MOVETYPE_NOCLIP; return pPlayer->v.movetype == MOVETYPE_NOCLIP;
} }
@ -485,7 +491,7 @@ static cell AMX_NATIVE_CALL set_user_footsteps(AMX *amx, cell *params) // set_us
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
// Fetch player pointer // Fetch player pointer
edict_t *pPlayer = MF_GetPlayerEdict(params[1]); edict_t *pPlayer = TypeConversion.id_to_edict(params[1]);
if (params[2]) { if (params[2]) {
pPlayer->v.flTimeStepSound = 999; pPlayer->v.flTimeStepSound = 999;
@ -511,7 +517,7 @@ static cell AMX_NATIVE_CALL strip_user_weapons(AMX *amx, cell *params) // index
{ {
CHECK_PLAYER(params[1]); CHECK_PLAYER(params[1]);
edict_t* pPlayer = MF_GetPlayerEdict(params[1]); edict_t* pPlayer = TypeConversion.id_to_edict(params[1]);
string_t item = MAKE_STRING("player_weaponstrip"); string_t item = MAKE_STRING("player_weaponstrip");
edict_t *pent = CREATE_NAMED_ENTITY(item); edict_t *pent = CREATE_NAMED_ENTITY(item);
@ -632,6 +638,8 @@ void OnPluginsLoaded() {
// Reset all hitzones // Reset all hitzones
FUNUTIL_ResetPlayer(i); FUNUTIL_ResetPlayer(i);
} }
TypeConversion.init();
} }
/* /*
void ClientConnectFakeBot(int index) void ClientConnectFakeBot(int index)

View File

@ -29,16 +29,6 @@
#define HITGROUP_RIGHTARM 5 // 32 #define HITGROUP_RIGHTARM 5 // 32
#define HITGROUP_LEFTLEG 6 // 64 #define HITGROUP_LEFTLEG 6 // 64
#define HITGROUP_RIGHTLEG 7 // 128 #define HITGROUP_RIGHTLEG 7 // 128
// Fun-specific defines above
// The stuff below might end up in a class soon
char g_bodyhits[33][33]; // where can the guy in the first dimension hit the people in the 2nd dimension? :-)
bool g_silent[33]; // used for set_user_footsteps()
//int g_ResetHUD;
bool g_ResetHUDbool;
edict_t* g_edict;
//bool g_bot[33]; // is user bot? <--- removed, only needed with akimbot
// Globals above
#define CHECK_ENTITY(x) \ #define CHECK_ENTITY(x) \
if (x < 0 || x > gpGlobals->maxEntities) { \ if (x < 0 || x > gpGlobals->maxEntities) { \
@ -51,7 +41,7 @@ edict_t* g_edict;
return 0; \ return 0; \
} \ } \
} else { \ } else { \
if (x != 0 && FNullEnt(INDEXENT(x))) { \ if (x != 0 && FNullEnt(TypeConversion.id_to_edict(x))) { \
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \
return 0; \ return 0; \
} \ } \
@ -63,11 +53,8 @@ edict_t* g_edict;
MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \ MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \
return 0; \ return 0; \
} else { \ } else { \
if (!MF_IsPlayerIngame(x) || FNullEnt(MF_GetPlayerEdict(x))) { \ if (!MF_IsPlayerIngame(x) || FNullEnt(TypeConversion.id_to_edict(x))) { \
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", x); \ MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", x); \
return 0; \ return 0; \
} \ } \
} }
#define GETEDICT(n) \
((n >= 1 && n <= gpGlobals->maxClients) ? MF_GetPlayerEdict(n) : INDEXENT(n))

View File

@ -145,6 +145,7 @@
<ClCompile Include="..\..\..\public\sdk\amxxmodule.cpp" /> <ClCompile Include="..\..\..\public\sdk\amxxmodule.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\..\public\HLTypeConversion.h" />
<ClInclude Include="..\fun.h" /> <ClInclude Include="..\fun.h" />
<ClInclude Include="..\moduleconfig.h" /> <ClInclude Include="..\moduleconfig.h" />
<ClInclude Include="..\..\..\public\sdk\amxxmodule.h" /> <ClInclude Include="..\..\..\public\sdk\amxxmodule.h" />

View File

@ -37,6 +37,9 @@
<ClInclude Include="..\..\..\public\sdk\amxxmodule.h"> <ClInclude Include="..\..\..\public\sdk\amxxmodule.h">
<Filter>Module SDK\SDK Base</Filter> <Filter>Module SDK\SDK Base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\..\public\HLTypeConversion.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\..\..\plugins\include\fun.inc"> <None Include="..\..\..\plugins\include\fun.inc">