Quote:
Originally Posted by KliPPy
|
I did not look at the code, so could you explain how it's different than using a trie and saving data with entity id as key?
Quote:
Originally Posted by Depresie
Hams, i remember somewhere you were explaining us how to retrieve the weapon entity index from within the weaponbox in FM_SetModel forward, but i don't remember where..
?
|
Retrieving in FM_SetModel is the same as retrieving anywhere else.
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define MAX_ITEM_TYPES 6
new const m_rgpPlayerItems_CWeaponBox[MAX_ITEM_TYPES] = {34, 35, ...}
const m_pNext = 42
const XoCWeaponBox = 4
const XoCBasePlayerItem = 4
public plugin_init()
{
register_forward(FM_SetModel, "pfnSetModel", false)
}
public pfnSetModel(const entity, const model[])
{
if(pev_valid(entity))
{
new className[32]
pev(entity, pev_classname, className, charsmax(className))
if(equal(className, "weaponbox"))
{
new weaponEntity
for(new i = 1; i < sizeof m_rgpPlayerItems_CWeaponBox; i++)
{
weaponEntity = get_pdata_cbase(entity, m_rgpPlayerItems_CWeaponBox[i], XoCWeaponBox)
while(pev_valid(weaponEntity))
{
//do your stuff
weaponEntity = get_pdata_cbase(weaponEntity, m_pNext, XoCBasePlayerItem)
}
}
}
}
}
While a weaponbox can contain multiple weapons and ammo types, in CS they usually contain only one. You could have weaponboxes with multiple weapons if a coder/mapper decides to do that, but by default there is only one.
This means that the while() loop is not really needed and the simplified code will be like:
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define MAX_ITEM_TYPES 6
new const m_rgpPlayerItems_CWeaponBox[MAX_ITEM_TYPES] = {34, 35, ...}
const XoCWeaponBox = 4
public plugin_init()
{
register_forward(FM_SetModel, "pfnSetModel", false)
}
public pfnSetModel(const entity, const model[])
{
if(pev_valid(entity))
{
new className[32]
pev(entity, pev_classname, className, charsmax(className))
if(equal(className, "weaponbox"))
{
new weaponEntity
for(new i = 1; i < sizeof m_rgpPlayerItems_CWeaponBox; i++)
{
weaponEntity = get_pdata_cbase(entity, m_rgpPlayerItems_CWeaponBox[i], XoCWeaponBox)
if(pev_valid(weaponEntity))
{
//do your stuff
break
}
}
}
}
}
I would still advise you to use the first code, the difference in performance is almost non-existent.
__________________