mirror of
https://github.com/rehlds/reapi.git
synced 2025-01-01 09:35:47 +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 index Client index
|
||||||
* @param pszName Item classname
|
* @param pszName Item classname
|
||||||
* @param type Look at the enums with name GiveType
|
* @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
|
* @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.
|
* Give the default items to a player.
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#define RG_CSGameRules_CheckWinConditions RG_CSGameRules_CheckWinCond
|
#define RG_CSGameRules_CheckWinConditions RG_CSGameRules_CheckWinCond
|
||||||
#define RG_CBasePlayer_SetClientUserInfoModel RG_CBasePlayer_SetUserInfoModel
|
#define RG_CBasePlayer_SetClientUserInfoModel RG_CBasePlayer_SetUserInfoModel
|
||||||
#define RG_CBasePlayer_SetClientUserInfoName RG_CBasePlayer_SetUserInfoName
|
#define RG_CBasePlayer_SetClientUserInfoName RG_CBasePlayer_SetUserInfoName
|
||||||
|
#define m_Shield_hEntToIgnoreTouchesFrom m_Shield_EntToIgnoreTouchesFrom
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum UnifiedSignals
|
enum UnifiedSignals
|
||||||
@ -4065,6 +4066,14 @@ enum CCSPlayer_Members
|
|||||||
* Set params: set_member(index, member, value);
|
* Set params: set_member(index, member, value);
|
||||||
*/
|
*/
|
||||||
m_bForceShowMenu,
|
m_bForceShowMenu,
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Description: -
|
||||||
|
* Member type: float
|
||||||
|
* Get params: Float:get_member(index, member);
|
||||||
|
* Set params: set_member(index, member, Float:value);
|
||||||
|
*/
|
||||||
|
m_flRespawnPending,
|
||||||
};
|
};
|
||||||
|
|
||||||
// CBasePlayerItem
|
// CBasePlayerItem
|
||||||
|
@ -51,7 +51,7 @@ class CCSArmoury: public CCSEntity {};
|
|||||||
|
|
||||||
class CCSPlayer: public CCSMonster {
|
class CCSPlayer: public CCSMonster {
|
||||||
public:
|
public:
|
||||||
CCSPlayer() : m_bForceShowMenu(false)
|
CCSPlayer() : m_bForceShowMenu(false), m_flRespawnPending(0)
|
||||||
{
|
{
|
||||||
m_szModel[0] = '\0';
|
m_szModel[0] = '\0';
|
||||||
}
|
}
|
||||||
@ -95,12 +95,14 @@ public:
|
|||||||
virtual void Disappear();
|
virtual void Disappear();
|
||||||
virtual void MakeVIP();
|
virtual void MakeVIP();
|
||||||
virtual bool MakeBomber();
|
virtual bool MakeBomber();
|
||||||
|
virtual void ResetSequenceInfo();
|
||||||
virtual void StartDeathCam();
|
virtual void StartDeathCam();
|
||||||
|
|
||||||
CBasePlayer *BasePlayer() const;
|
CBasePlayer *BasePlayer() const;
|
||||||
public:
|
public:
|
||||||
char m_szModel[32];
|
char m_szModel[32];
|
||||||
bool m_bForceShowMenu;
|
bool m_bForceShowMenu;
|
||||||
|
float m_flRespawnPending;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CAPI_Bot: public CCSPlayer {};
|
class CAPI_Bot: public CCSPlayer {};
|
||||||
|
@ -50,11 +50,17 @@ inline AType getApiType(T *) { return ATYPE_INTEGER; }
|
|||||||
|
|
||||||
inline bool hasStringArgs() { return false; }
|
inline bool hasStringArgs() { return false; }
|
||||||
|
|
||||||
|
extern void __declspec(noreturn) UTIL_SysError(const char *fmt, ...);
|
||||||
|
|
||||||
template <typename T, typename ...f_args>
|
template <typename T, typename ...f_args>
|
||||||
bool hasStringArgs(T, f_args... 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 (sizeof(T) > sizeof(int))
|
||||||
if (getApiType(T()) == ATYPE_STRING) return true;
|
UTIL_SysError("%s: invalid hookchain argument size (%i > %i)", __FUNCTION__, sizeof(T), sizeof(int));
|
||||||
|
|
||||||
|
if (getApiType(T()) == ATYPE_STRING)
|
||||||
|
return true;
|
||||||
|
|
||||||
return hasStringArgs(args...);
|
return hasStringArgs(args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -722,6 +722,7 @@ member_t memberlist_pmtrace[] = {
|
|||||||
member_t memberlist_csplayer[] = {
|
member_t memberlist_csplayer[] = {
|
||||||
CSPL_MEMBERS(m_szModel),
|
CSPL_MEMBERS(m_szModel),
|
||||||
CSPL_MEMBERS(m_bForceShowMenu),
|
CSPL_MEMBERS(m_bForceShowMenu),
|
||||||
|
CSPL_MEMBERS(m_flRespawnPending),
|
||||||
};
|
};
|
||||||
|
|
||||||
member_t memberlist_baseitem[] = {
|
member_t memberlist_baseitem[] = {
|
||||||
|
@ -740,6 +740,7 @@ enum CSPlayer_Members
|
|||||||
{
|
{
|
||||||
m_szModel = BEGIN_MEMBER_REGION(csplayer),
|
m_szModel = BEGIN_MEMBER_REGION(csplayer),
|
||||||
m_bForceShowMenu,
|
m_bForceShowMenu,
|
||||||
|
m_flRespawnPending,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum CBasePlayerItem_Members
|
enum CBasePlayerItem_Members
|
||||||
|
@ -53,8 +53,6 @@ cell AMX_NATIVE_CALL rg_add_account(AMX *amx, cell *params)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum GiveType { GT_APPEND, GT_REPLACE, GT_DROP_AND_REPLACE };
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gives the player an item.
|
* 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);
|
auto pInfo = g_ReGameApi->GetWeaponSlot(itemName);
|
||||||
if (pInfo)
|
if (pInfo)
|
||||||
{
|
{
|
||||||
pPlayer->ForEachItem(pInfo->slot, [pPlayer, pInfo, type](CBasePlayerItem *pItem)
|
pPlayer->ForEachItem(pInfo->slot, [pPlayer, type](CBasePlayerItem *pItem) {
|
||||||
{
|
RemoveOrDropItem(pPlayer, pItem, type);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -120,14 +103,15 @@ cell AMX_NATIVE_CALL rg_give_item(AMX *amx, cell *params)
|
|||||||
* @param index Client index
|
* @param index Client index
|
||||||
* @param pszName Item classname
|
* @param pszName Item classname
|
||||||
* @param type Look at the enums with name GiveType
|
* @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
|
* @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)
|
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);
|
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);
|
auto pInfo = g_ReGameApi->GetWeaponSlot(itemName);
|
||||||
if (pInfo)
|
if (pInfo)
|
||||||
{
|
{
|
||||||
pPlayer->ForEachItem(pInfo->slot, [pPlayer, pInfo, type](CBasePlayerItem *pItem)
|
pPlayer->ForEachItem(pInfo->slot, [pPlayer, type](CBasePlayerItem *pItem) {
|
||||||
{
|
RemoveOrDropItem(pPlayer, pItem, type);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pEntity = GiveNamedItemInternal(amx, pPlayer, itemName);
|
auto pEntity = GiveNamedItemInternal(amx, pPlayer, itemName, params[arg_uid]);
|
||||||
if (pEntity)
|
if (pEntity)
|
||||||
return indexOfPDataAmx(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]);
|
CBasePlayer *pPlayer = UTIL_PlayerByIndex(params[arg_index]);
|
||||||
CHECK_CONNECTED(pPlayer, 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->IsWeapon()) {
|
||||||
if (pItem == pPlayer->m_pActiveItem) {
|
if (pItem == pPlayer->m_pActiveItem) {
|
||||||
((CBasePlayerWeapon *)pItem)->RetireWeapon();
|
((CBasePlayerWeapon *)pItem)->RetireWeapon();
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
#pragma once
|
#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
|
enum WpnInfo
|
||||||
{
|
{
|
||||||
WI_ID,
|
WI_ID,
|
||||||
|
@ -59,7 +59,6 @@
|
|||||||
|
|
||||||
// reapi main
|
// reapi main
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "reapi_utils.h"
|
|
||||||
#include "api_config.h"
|
#include "api_config.h"
|
||||||
#include "hook_manager.h"
|
#include "hook_manager.h"
|
||||||
#include "hook_callback.h"
|
#include "hook_callback.h"
|
||||||
@ -77,3 +76,5 @@
|
|||||||
#include "natives_vtc.h"
|
#include "natives_vtc.h"
|
||||||
#include "natives_reunion.h"
|
#include "natives_reunion.h"
|
||||||
#include "natives_rechecker.h"
|
#include "natives_rechecker.h"
|
||||||
|
|
||||||
|
#include "reapi_utils.h"
|
||||||
|
@ -64,7 +64,7 @@ void CTempStrings::pop(size_t count)
|
|||||||
m_current -= 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));
|
edict_t *pEdict = CREATE_NAMED_ENTITY(ALLOC_STRING(pszItemName));
|
||||||
if (FNullEnt(pEdict))
|
if (FNullEnt(pEdict))
|
||||||
@ -76,6 +76,10 @@ CBaseEntity *GiveNamedItemInternal(AMX *amx, CBasePlayer *pPlayer, const char *p
|
|||||||
pEdict->v.origin = pPlayer->pev->origin;
|
pEdict->v.origin = pPlayer->pev->origin;
|
||||||
pEdict->v.spawnflags |= SF_NORESPAWN;
|
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_Spawn(pEdict);
|
||||||
MDLL_Touch(pEdict, ENT(pPlayer->pev));
|
MDLL_Touch(pEdict, ENT(pPlayer->pev));
|
||||||
|
|
||||||
@ -198,3 +202,22 @@ void GetAttachment(CBaseEntity *pEntity, int iBone, Vector *pVecOrigin, Vector *
|
|||||||
*pVecAngles = vecAngles;
|
*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();
|
void UpdateTeamScores();
|
||||||
ModelName GetModelAuto(TeamName team);
|
ModelName GetModelAuto(TeamName team);
|
||||||
void UTIL_ServerPrint(const char *fmt, ...);
|
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 GetBonePosition(CBaseEntity *pEntity, int iBone, Vector *vecOrigin, Vector *vecAngles);
|
||||||
void GetAttachment(CBaseEntity *pEntity, int iBone, Vector *pVecOrigin, Vector *pVecAngles);
|
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, ...);
|
extern void __declspec(noreturn) UTIL_SysError(const char *fmt, ...);
|
||||||
|
Loading…
Reference in New Issue
Block a user