mirror of
https://github.com/rehlds/reapi.git
synced 2024-12-28 15:45:31 +03:00
Enhanced native rg_give_custom_item
This commit is contained in:
parent
e52b83d873
commit
0af5713b86
@ -232,11 +232,12 @@ native rg_give_item(const index, const pszName[], GiveType:type = GT_APPEND);
|
||||
* @param index Client index
|
||||
* @param pszName Item classname
|
||||
* @param type Look at the enums with name GiveType
|
||||
* @param uid Sets a unique index for the entity
|
||||
*
|
||||
* @return Index of entity if successfull, -1 otherwise
|
||||
*
|
||||
*/
|
||||
native rg_give_custom_item(const index, const pszName[], GiveType:type = GT_APPEND);
|
||||
native rg_give_custom_item(const index, const pszName[], GiveType:type = GT_APPEND, const uid = 0);
|
||||
|
||||
/*
|
||||
* Give the default items to a player.
|
||||
|
@ -25,6 +25,7 @@
|
||||
#define RG_CSGameRules_CheckWinConditions RG_CSGameRules_CheckWinCond
|
||||
#define RG_CBasePlayer_SetClientUserInfoModel RG_CBasePlayer_SetUserInfoModel
|
||||
#define RG_CBasePlayer_SetClientUserInfoName RG_CBasePlayer_SetUserInfoName
|
||||
#define m_Shield_hEntToIgnoreTouchesFrom m_Shield_EntToIgnoreTouchesFrom
|
||||
#endif
|
||||
|
||||
enum UnifiedSignals
|
||||
@ -4065,6 +4066,14 @@ enum CCSPlayer_Members
|
||||
* Set params: set_member(index, member, value);
|
||||
*/
|
||||
m_bForceShowMenu,
|
||||
|
||||
/*
|
||||
* Description: -
|
||||
* Member type: float
|
||||
* Get params: Float:get_member(index, member);
|
||||
* Set params: set_member(index, member, Float:value);
|
||||
*/
|
||||
m_flRespawnPending,
|
||||
};
|
||||
|
||||
// CBasePlayerItem
|
||||
|
@ -51,7 +51,7 @@ class CCSArmoury: public CCSEntity {};
|
||||
|
||||
class CCSPlayer: public CCSMonster {
|
||||
public:
|
||||
CCSPlayer() : m_bForceShowMenu(false)
|
||||
CCSPlayer() : m_bForceShowMenu(false), m_flRespawnPending(0)
|
||||
{
|
||||
m_szModel[0] = '\0';
|
||||
}
|
||||
@ -95,12 +95,14 @@ public:
|
||||
virtual void Disappear();
|
||||
virtual void MakeVIP();
|
||||
virtual bool MakeBomber();
|
||||
virtual void ResetSequenceInfo();
|
||||
virtual void StartDeathCam();
|
||||
|
||||
CBasePlayer *BasePlayer() const;
|
||||
public:
|
||||
char m_szModel[32];
|
||||
bool m_bForceShowMenu;
|
||||
float m_flRespawnPending;
|
||||
};
|
||||
|
||||
class CAPI_Bot: public CCSPlayer {};
|
||||
|
@ -50,11 +50,17 @@ inline AType getApiType(T *) { return ATYPE_INTEGER; }
|
||||
|
||||
inline bool hasStringArgs() { return false; }
|
||||
|
||||
extern void __declspec(noreturn) UTIL_SysError(const char *fmt, ...);
|
||||
|
||||
template <typename T, typename ...f_args>
|
||||
bool hasStringArgs(T, f_args... args)
|
||||
{
|
||||
if (sizeof(T) > sizeof(int)) UTIL_SysError("%s: invalid hookchain argument size (%i > %i)", __FUNCTION__, sizeof(T), sizeof(int));
|
||||
if (getApiType(T()) == ATYPE_STRING) return true;
|
||||
if (sizeof(T) > sizeof(int))
|
||||
UTIL_SysError("%s: invalid hookchain argument size (%i > %i)", __FUNCTION__, sizeof(T), sizeof(int));
|
||||
|
||||
if (getApiType(T()) == ATYPE_STRING)
|
||||
return true;
|
||||
|
||||
return hasStringArgs(args...);
|
||||
}
|
||||
|
||||
|
@ -722,6 +722,7 @@ member_t memberlist_pmtrace[] = {
|
||||
member_t memberlist_csplayer[] = {
|
||||
CSPL_MEMBERS(m_szModel),
|
||||
CSPL_MEMBERS(m_bForceShowMenu),
|
||||
CSPL_MEMBERS(m_flRespawnPending),
|
||||
};
|
||||
|
||||
member_t memberlist_baseitem[] = {
|
||||
|
@ -740,6 +740,7 @@ enum CSPlayer_Members
|
||||
{
|
||||
m_szModel = BEGIN_MEMBER_REGION(csplayer),
|
||||
m_bForceShowMenu,
|
||||
m_flRespawnPending,
|
||||
};
|
||||
|
||||
enum CBasePlayerItem_Members
|
||||
|
@ -53,8 +53,6 @@ cell AMX_NATIVE_CALL rg_add_account(AMX *amx, cell *params)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
enum GiveType { GT_APPEND, GT_REPLACE, GT_DROP_AND_REPLACE };
|
||||
|
||||
/*
|
||||
* Gives the player an item.
|
||||
*
|
||||
@ -83,23 +81,8 @@ cell AMX_NATIVE_CALL rg_give_item(AMX *amx, cell *params)
|
||||
auto pInfo = g_ReGameApi->GetWeaponSlot(itemName);
|
||||
if (pInfo)
|
||||
{
|
||||
pPlayer->ForEachItem(pInfo->slot, [pPlayer, pInfo, type](CBasePlayerItem *pItem)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case GT_DROP_AND_REPLACE:
|
||||
pPlayer->CSPlayer()->DropPlayerItem(STRING(pItem->pev->classname));
|
||||
break;
|
||||
case GT_REPLACE:
|
||||
pPlayer->pev->weapons &= ~(1 << pItem->m_iId);
|
||||
pPlayer->RemovePlayerItem(pItem);
|
||||
pItem->Kill();
|
||||
break;
|
||||
case GT_APPEND:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pPlayer->ForEachItem(pInfo->slot, [pPlayer, type](CBasePlayerItem *pItem) {
|
||||
RemoveOrDropItem(pPlayer, pItem, type);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
@ -120,14 +103,15 @@ cell AMX_NATIVE_CALL rg_give_item(AMX *amx, cell *params)
|
||||
* @param index Client index
|
||||
* @param pszName Item classname
|
||||
* @param type Look at the enums with name GiveType
|
||||
* @param uid Sets a unique index for the entity
|
||||
*
|
||||
* @return Index of entity if successfull, -1 otherwise
|
||||
*
|
||||
* native rg_give_custom_item(const index, const pszName[], GiveType:type = GT_APPEND);
|
||||
* native rg_give_custom_item(const index, const pszName[], GiveType:type = GT_APPEND, const uid = 0);
|
||||
*/
|
||||
cell AMX_NATIVE_CALL rg_give_custom_item(AMX *amx, cell *params)
|
||||
{
|
||||
enum args_e { arg_count, arg_index, arg_item, arg_type };
|
||||
enum args_e { arg_count, arg_index, arg_item, arg_type, arg_uid };
|
||||
|
||||
CHECK_ISPLAYER(arg_index);
|
||||
|
||||
@ -142,29 +126,14 @@ cell AMX_NATIVE_CALL rg_give_custom_item(AMX *amx, cell *params)
|
||||
auto pInfo = g_ReGameApi->GetWeaponSlot(itemName);
|
||||
if (pInfo)
|
||||
{
|
||||
pPlayer->ForEachItem(pInfo->slot, [pPlayer, pInfo, type](CBasePlayerItem *pItem)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case GT_DROP_AND_REPLACE:
|
||||
pPlayer->CSPlayer()->DropPlayerItem(STRING(pItem->pev->classname));
|
||||
break;
|
||||
case GT_REPLACE:
|
||||
pPlayer->pev->weapons &= ~(1 << pItem->m_iId);
|
||||
pPlayer->RemovePlayerItem(pItem);
|
||||
pItem->Kill();
|
||||
break;
|
||||
case GT_APPEND:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pPlayer->ForEachItem(pInfo->slot, [pPlayer, type](CBasePlayerItem *pItem) {
|
||||
RemoveOrDropItem(pPlayer, pItem, type);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
auto pEntity = GiveNamedItemInternal(amx, pPlayer, itemName);
|
||||
auto pEntity = GiveNamedItemInternal(amx, pPlayer, itemName, params[arg_uid]);
|
||||
if (pEntity)
|
||||
return indexOfPDataAmx(pEntity);
|
||||
|
||||
@ -874,8 +843,8 @@ cell AMX_NATIVE_CALL rg_remove_items_by_slot(AMX *amx, cell *params)
|
||||
CBasePlayer *pPlayer = UTIL_PlayerByIndex(params[arg_index]);
|
||||
CHECK_CONNECTED(pPlayer, arg_index);
|
||||
|
||||
pPlayer->ForEachItem(params[arg_slot], [pPlayer](CBasePlayerItem *pItem) {
|
||||
|
||||
pPlayer->ForEachItem(params[arg_slot], [pPlayer](CBasePlayerItem *pItem)
|
||||
{
|
||||
if (pItem->IsWeapon()) {
|
||||
if (pItem == pPlayer->m_pActiveItem) {
|
||||
((CBasePlayerWeapon *)pItem)->RetireWeapon();
|
||||
|
@ -1,5 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
enum GiveType
|
||||
{
|
||||
GT_APPEND, // Just give item
|
||||
GT_REPLACE, // Give the item and remove all other weapons from the slot
|
||||
GT_DROP_AND_REPLACE // Give the item and drop all other weapons from the slot
|
||||
};
|
||||
|
||||
enum WpnInfo
|
||||
{
|
||||
WI_ID,
|
||||
|
@ -59,7 +59,6 @@
|
||||
|
||||
// reapi main
|
||||
#include "main.h"
|
||||
#include "reapi_utils.h"
|
||||
#include "api_config.h"
|
||||
#include "hook_manager.h"
|
||||
#include "hook_callback.h"
|
||||
@ -77,3 +76,5 @@
|
||||
#include "natives_vtc.h"
|
||||
#include "natives_reunion.h"
|
||||
#include "natives_rechecker.h"
|
||||
|
||||
#include "reapi_utils.h"
|
||||
|
@ -64,7 +64,7 @@ void CTempStrings::pop(size_t count)
|
||||
m_current -= count;
|
||||
}
|
||||
|
||||
CBaseEntity *GiveNamedItemInternal(AMX *amx, CBasePlayer *pPlayer, const char *pszItemName)
|
||||
CBaseEntity *GiveNamedItemInternal(AMX *amx, CBasePlayer *pPlayer, const char *pszItemName, const size_t uid)
|
||||
{
|
||||
edict_t *pEdict = CREATE_NAMED_ENTITY(ALLOC_STRING(pszItemName));
|
||||
if (FNullEnt(pEdict))
|
||||
@ -76,6 +76,10 @@ CBaseEntity *GiveNamedItemInternal(AMX *amx, CBasePlayer *pPlayer, const char *p
|
||||
pEdict->v.origin = pPlayer->pev->origin;
|
||||
pEdict->v.spawnflags |= SF_NORESPAWN;
|
||||
|
||||
// In some cases, we must to sets unique id
|
||||
// for the entity before it will triggered a spawn.
|
||||
pEdict->v.impulse = uid;
|
||||
|
||||
MDLL_Spawn(pEdict);
|
||||
MDLL_Touch(pEdict, ENT(pPlayer->pev));
|
||||
|
||||
@ -198,3 +202,22 @@ void GetAttachment(CBaseEntity *pEntity, int iBone, Vector *pVecOrigin, Vector *
|
||||
*pVecAngles = vecAngles;
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveOrDropItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem, GiveType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case GT_DROP_AND_REPLACE:
|
||||
pPlayer->CSPlayer()->DropPlayerItem(STRING(pItem->pev->classname));
|
||||
break;
|
||||
case GT_REPLACE:
|
||||
printf(" -> KILL: (%s)\n", STRING(pItem->pev->classname));
|
||||
pPlayer->pev->weapons &= ~(1 << pItem->m_iId);
|
||||
pPlayer->RemovePlayerItem(pItem);
|
||||
pItem->Kill();
|
||||
break;
|
||||
case GT_APPEND:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -51,9 +51,10 @@ void Broadcast(const char *sentence);
|
||||
void UpdateTeamScores();
|
||||
ModelName GetModelAuto(TeamName team);
|
||||
void UTIL_ServerPrint(const char *fmt, ...);
|
||||
CBaseEntity *GiveNamedItemInternal(AMX *amx, CBasePlayer *pPlayer, const char *pszItemName);
|
||||
CBaseEntity *GiveNamedItemInternal(AMX *amx, CBasePlayer *pPlayer, const char *pszItemName, const size_t uid = 0);
|
||||
|
||||
void GetBonePosition(CBaseEntity *pEntity, int iBone, Vector *vecOrigin, Vector *vecAngles);
|
||||
void GetAttachment(CBaseEntity *pEntity, int iBone, Vector *pVecOrigin, Vector *pVecAngles);
|
||||
void RemoveOrDropItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem, GiveType type);
|
||||
|
||||
extern void __declspec(noreturn) UTIL_SysError(const char *fmt, ...);
|
||||
|
Loading…
Reference in New Issue
Block a user