Here you have a working code(you weren't far from the truth, just some small mistakes)
PHP Code:
#include < amxmodx >
#include < fakemeta >
#include < engine >
#include < cstrike >
#include < hamsandwich >
#include < orpheu >
#include <orpheu_advanced>
#define XO_CWEAPONBOX 4
const m_iId = 43;
const m_pfnThink = 4
new const WeaponBoxModels[ ][ ] =
{
"", "models/w_p228.mdl", "",
"models/w_scout.mdl", "", "models/w_xm1014.mdl",
"models/w_c4.mdl", "models/w_mac10.mdl", "models/w_aug.mdl", "",
"models/w_elite.mdl", "models/w_fiveseven.mdl", "models/w_ump45.mdl",
"models/w_sg550.mdl", "models/w_galil.mdl", "models/w_famas.mdl",
"models/w_usp.mdl", "models/w_glock18.mdl", "models/w_awp.mdl",
"models/w_mp5.mdl", "models/w_m249.mdl", "models/w_m3.mdl",
"models/w_m4a1.mdl", "models/w_tmp.mdl", "models/w_g3sg1.mdl",
"", "models/w_deagle.mdl", "models/w_sg552.mdl", "models/w_ak47.mdl",
"", "models/w_p90.mdl", "", ""
}
new IntClassNameString
new OrpheuFunction:HandleCreateNamedEntityFunc
new OrpheuFunction:HandlePackWeaponFunc
new CWeaponBoxKill_Address
public plugin_init( )
{
register_clcmd("say /create", "OnCreate")
register_clcmd("say /think", "OnThink")
IntClassNameString = engfunc(EngFunc_AllocString, "weaponbox")
HandleCreateNamedEntityFunc = OrpheuGetFunction("CREATE_NAMED_ENTITY")
HandlePackWeaponFunc = OrpheuGetFunction("PackWeapon", "CWeaponBox")
CWeaponBoxKill_Address = OrpheuGetFunctionAddress(OrpheuGetFunction("Kill", "CWeaponBox"))
}
public OnCreate( id )
{
new Float:WeaponBoxOrigin[3]
new Origin[3]
get_user_origin(id, Origin, 3)
IVecFVec(Origin, WeaponBoxOrigin)
new WeaponBoxEntity = OrpheuCall(HandleCreateNamedEntityFunc, IntClassNameString)
if(!pev_valid(WeaponBoxEntity))
{
return 0
}
engfunc(EngFunc_SetOrigin, WeaponBoxEntity, WeaponBoxOrigin)
ExecuteHam(Ham_Spawn, WeaponBoxEntity)
new WeaponEntity = create_entity("weapon_ak47")
if(!pev_valid(WeaponEntity))
{
remove_entity(WeaponBoxEntity)
}
ExecuteHam(Ham_Spawn, WeaponEntity)
new WeaponID = cs_get_weapon_id(WeaponEntity)
OrpheuCall(HandlePackWeaponFunc, WeaponBoxEntity, WeaponEntity)
if(WeaponBoxModels[WeaponID][ 0 ] != EOS )
{
engfunc( EngFunc_SetModel, WeaponBoxEntity, WeaponBoxModels[WeaponID])
}
set_pdata_int(WeaponBoxEntity, m_pfnThink, CWeaponBoxKill_Address, 0)
return 0
}
Note: you will see an extra step:
PHP Code:
CWeaponBoxKill_Address = OrpheuGetFunctionAddress(OrpheuGetFunction("Kill", "CWeaponBox"))
set_pdata_int(WeaponBoxEntity, m_pfnThink, CWeaponBoxKill_Address, 0)
The proper way to remove a weaponbox is to force it to think(by using call_think for example). This removes both the weaponbox and the weapon that's linked to it. If you use only remove_entity then you will remove the box but the weapon will remain, causing a memory leak.
call_think works because m_pfnThink is set by the game with the address of CWeaponBox::Kill functions.
If you remove the set_pdata_int and use call_think you will see it does nothing. So if you want to be able to properly remove the box you need to set m_pfnThink to the correct value.
Now, what was wrong with your code?
When you create the weapon_ak47 entity you never spawned it meaning this offsets were never set:
https://github.com/s1lentq/ReGameDLL...pn_ak47.cpp#L5
You tried to do something, but it's wrong:
PHP Code:
set_pdata_int( iWeaponEntity, m_iId, cs_get_weapon_id( iWeaponEntity ), XO_CWEAPONBOX );
cs_get_weapon_id is using m_iId. So basically you were doing m_iId = m_iId and the offset had no value at that point. After executing spawn the offset has a valid value.
Now here:
PHP Code:
engfunc( EngFunc_SetModel, iWeaponEntity, WeaponBoxModels[ iWeaponId ] );
ExecuteHam( Ham_Spawn, iWeaponEntity );
set_pev( iWeaponEntity, pev_origin, fOrigin );
You need to do this on the weaponbox entity, not on the weapon entity. The weaponbox is a box and the weapon is inside it. What you see on the ground is the weaponbox not the weapon.
__________________